2017-08-11 22:18:09 +00:00
|
|
|
"""
|
|
|
|
Add a Documenter subtype to a template's plugins to add support for
|
|
|
|
[Documenter.jl](https://github.com/JuliaDocs/Documenter.jl).
|
|
|
|
"""
|
2017-08-17 06:57:58 +00:00
|
|
|
abstract type Documenter <: CustomPlugin end
|
2017-08-11 22:18:09 +00:00
|
|
|
|
|
|
|
"""
|
|
|
|
gen_plugin(plugin::Documenter, template::Template, pkg_name::AbstractString) -> Void
|
|
|
|
|
|
|
|
Generate the "docs" directory with files common to all Documenter subtypes.
|
|
|
|
|
|
|
|
# Arguments
|
|
|
|
* `plugin::Documenter`: Plugin whose files are being generated.
|
|
|
|
* `template::Template`: Template configuration and plugins.
|
|
|
|
* `pkg_name::AbstractString`: Name of the package.
|
|
|
|
"""
|
|
|
|
function gen_plugin(plugin::Documenter, template::Template, pkg_name::AbstractString)
|
2017-08-14 22:58:11 +00:00
|
|
|
if Pkg.installed("Documenter") == nothing
|
|
|
|
info("Adding Documenter.jl")
|
|
|
|
Pkg.add("Documenter")
|
|
|
|
end
|
2017-08-15 23:46:36 +00:00
|
|
|
path = joinpath(template.temp_dir, pkg_name)
|
2017-08-11 22:18:09 +00:00
|
|
|
docs_dir = joinpath(path, "docs", "src")
|
|
|
|
mkpath(docs_dir)
|
2017-08-14 18:12:57 +00:00
|
|
|
if !isempty(plugin.assets)
|
2017-08-11 22:18:09 +00:00
|
|
|
mkpath(joinpath(docs_dir, "assets"))
|
2017-08-14 18:12:57 +00:00
|
|
|
for file in plugin.assets
|
2017-08-11 22:18:09 +00:00
|
|
|
cp(file, joinpath(docs_dir, "assets", basename(file)))
|
|
|
|
end
|
|
|
|
# We want something that looks like the following:
|
|
|
|
# [
|
|
|
|
# assets/file1,
|
|
|
|
# assets/file2,
|
|
|
|
# ]
|
|
|
|
const TAB = repeat(" ", 4)
|
2017-08-15 14:19:37 +00:00
|
|
|
assets_string = "[\n"
|
|
|
|
for asset in plugin.assets
|
|
|
|
assets_string *= """$(TAB^2)"assets/$(basename(asset))",\n"""
|
2017-08-11 22:18:09 +00:00
|
|
|
end
|
2017-08-15 14:19:37 +00:00
|
|
|
assets_string *= "$TAB]"
|
2017-08-14 22:49:44 +00:00
|
|
|
|
|
|
|
else
|
2017-08-15 16:10:05 +00:00
|
|
|
assets_string = "[]"
|
2017-08-11 22:18:09 +00:00
|
|
|
end
|
|
|
|
text = """
|
|
|
|
using Documenter, $pkg_name
|
|
|
|
|
|
|
|
makedocs(
|
|
|
|
modules=[$pkg_name],
|
|
|
|
format=:html,
|
|
|
|
pages=[
|
|
|
|
"Home" => "index.md",
|
|
|
|
],
|
2017-08-15 16:10:05 +00:00
|
|
|
repo="https://github.com/$(template.user)/$pkg_name.jl/blob/{commit}{path}#L{line}",
|
2017-08-11 22:18:09 +00:00
|
|
|
sitename="$pkg_name.jl",
|
|
|
|
authors="$(template.authors)",
|
2017-08-15 14:19:37 +00:00
|
|
|
assets=$assets_string,
|
2017-08-11 22:18:09 +00:00
|
|
|
)
|
|
|
|
"""
|
|
|
|
|
|
|
|
gen_file(joinpath(dirname(docs_dir), "make.jl"), text)
|
2017-08-14 22:49:44 +00:00
|
|
|
open(joinpath(docs_dir, "index.md"), "w") do fp
|
|
|
|
write(fp, "# $pkg_name")
|
|
|
|
end
|
2017-08-15 23:46:36 +00:00
|
|
|
readme_path = joinpath(template.temp_dir, pkg_name, "README.md")
|
2017-08-11 22:18:09 +00:00
|
|
|
if isfile(readme_path)
|
|
|
|
cp(readme_path, joinpath(docs_dir, "index.md"), remove_destination=true)
|
|
|
|
end
|
|
|
|
end
|