Use autodocs for generated documentation

This commit is contained in:
Chris de Graaf 2018-09-28 16:38:48 -05:00
parent 0fd34f5847
commit 9b38d75942
2 changed files with 14 additions and 18 deletions

View File

@ -32,7 +32,7 @@ function gen_plugin(p::Documenter, t::Template, pkg_name::AbstractString)
"[]" "[]"
end end
text = """ make = """
using Documenter, $pkg_name using Documenter, $pkg_name
makedocs(; makedocs(;
@ -47,16 +47,19 @@ function gen_plugin(p::Documenter, t::Template, pkg_name::AbstractString)
assets=$assets_string, assets=$assets_string,
) )
""" """
docs = """
# $pkg_name.jl
gen_file(joinpath(dirname(docs_dir), "make.jl"), text) ```@index
```
# If the README exists, use it as the default docs. ```@autodocs
readme_path = joinpath(t.dir, pkg_name, "README.md") Modules = [$pkg_name]
if isfile(readme_path) ```
cp(readme_path, joinpath(docs_dir, "index.md")) """
else
gen_file(joinpath(docs_dir, "index.md"), "# $pkg_name") gen_file(joinpath(dirname(docs_dir), "make.jl"), make)
end gen_file(joinpath(docs_dir, "index.md"), docs)
end end
function Base.show(io::IO, p::Documenter) function Base.show(io::IO, p::Documenter)

View File

@ -30,7 +30,7 @@ pkg_dir = joinpath(t.dir, test_pkg)
@test isdir(joinpath(pkg_dir, "docs", "src")) @test isdir(joinpath(pkg_dir, "docs", "src"))
@test isfile(joinpath(pkg_dir, "docs", "src", "index.md")) @test isfile(joinpath(pkg_dir, "docs", "src", "index.md"))
index = readchomp(joinpath(pkg_dir, "docs", "src", "index.md")) index = readchomp(joinpath(pkg_dir, "docs", "src", "index.md"))
@test index == "# $test_pkg" @test occursin("autodocs", index)
rm(joinpath(pkg_dir, "docs"); recursive=true) rm(joinpath(pkg_dir, "docs"); recursive=true)
p = GitHubPages(; assets=[test_file]) p = GitHubPages(; assets=[test_file])
@test gen_plugin(p, t, test_pkg) == ["docs/"] @test gen_plugin(p, t, test_pkg) == ["docs/"]
@ -57,18 +57,11 @@ pkg_dir = joinpath(t.dir, test_pkg)
temp_dir = mktempdir() temp_dir = mktempdir()
t = Template(; user=me, dir=temp_dir, plugins=[GitHubPages()]) t = Template(; user=me, dir=temp_dir, plugins=[GitHubPages()])
generate(test_pkg, t) generate(test_pkg, t)
pkg_dir = joinpath(t.dir, test_pkg)
# Check that the gh-pages branch exists. # Check that the gh-pages branch exists.
repo = LibGit2.GitRepo(pkg_dir) repo = LibGit2.GitRepo(joinpath(t.dir, test_pkg))
branches = map(b -> LibGit2.shortname(first(b)), LibGit2.GitBranchIter(repo)) branches = map(b -> LibGit2.shortname(first(b)), LibGit2.GitBranchIter(repo))
@test in("gh-pages", branches) @test in("gh-pages", branches)
# Check that the generated docs root is just the copied README.
readme = read(joinpath(pkg_dir, "README.md"), String)
index = read(joinpath(pkg_dir, "docs", "src", "index.md"), String)
@test readme == index
rm(temp_dir; recursive=true)
end end
end end