Skip to content

Commit

Permalink
Start moving docs to docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbyrne committed Feb 11, 2016
1 parent e29b555 commit b924862
Show file tree
Hide file tree
Showing 47 changed files with 1,947 additions and 1,022 deletions.
1 change: 1 addition & 0 deletions doc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`genrst.jl` generates the rst files from Julia docstrings. This should be run *before* committing the changes to the repository.
55 changes: 55 additions & 0 deletions doc/genrst.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using Distributions

if VERSION < v"0.5.0-"
function Markdown.rstinline(io::IO, md::Markdown.Link)
if ismatch(r":(func|obj|ref|exc|class|const|data):`\.*", md.url)
Markdown.rstinline(io, md.url)
else
Markdown.rstinline(io, "`", md.text, " <", md.url, ">`_")
end
end
end

function printrst(io,md)
mdd = md.content[1]
sigs = shift!(mdd.content)

decl = ".. function:: "*replace(sigs.code, "\n","\n ")
body = Markdown.rst(mdd)
println(io, decl)
println(io)
for l in split(body, "\n")
ismatch(r"^\s*$", l) ? println(io) : println(io, " ", l)
end
end

cd(joinpath(dirname(@__FILE__),"source")) do
for (name,T) in [("Univariate Discrete",DiscreteUnivariateDistribution),
("Univariate Continuous",ContinuousUnivariateDistribution),
]

fname = replace(lowercase(name),' ','-')
open("$fname.rst","w") do f
println(f,".. _$fname:")
println(f)
println(f,"$name Distributions")
println(f,"----------------------------------------------------")
println(f)
println(f, ".. DO NOT EDIT: this file is generated from Julia source.")
println(f)

for D in subtypes(T)
if isleaftype(D)
md = Base.doc(D)
if isa(md,Markdown.MD)
isa(md.content[1].content[1],Markdown.Code) || error("Incorrect docstring format: $D")

printrst(f,md)
else
warn("$D is not documented.")
end
end
end
end
end
end
6 changes: 4 additions & 2 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@

# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.todo', 'sphinx.ext.coverage', 'sphinx.ext.pngmath']
extensions = ['sphinx.ext.mathjax',
'sphinx.ext.todo',
'sphinx.ext.coverage']

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
Expand All @@ -34,7 +36,7 @@
source_suffix = '.rst'

# The encoding of source files.
#source_encoding = 'utf-8-sig'
source_encoding = 'utf-8-sig'

# The master toctree document.
master_doc = 'index'
Expand Down
Loading

0 comments on commit b924862

Please sign in to comment.