2019-09-18 14:25:48 +00:00
|
|
|
const DOCUMENTER_DEP = PackageSpec(;
|
|
|
|
name="Documenter",
|
|
|
|
uuid="e30172f5-a6a5-5a46-863b-614d45cd2de4",
|
|
|
|
)
|
2018-11-05 21:39:14 +00:00
|
|
|
|
2017-08-11 22:18:09 +00:00
|
|
|
"""
|
2019-02-05 17:31:51 +00:00
|
|
|
Documenter{T<:Union{TravisCI, GitLabCI, Nothing}}(;
|
2019-09-19 05:51:04 +00:00
|
|
|
make_jl="$(contractuser(default_file("docs", "make.jl")))",
|
|
|
|
index_md="$(contractuser(default_file("docs", "index.md")))",
|
2019-09-01 14:03:19 +00:00
|
|
|
assets=String[],
|
2019-09-19 05:51:04 +00:00
|
|
|
canonical_url=make_canonical(T),
|
2019-09-01 14:03:19 +00:00
|
|
|
makedocs_kwargs=Dict{Symbol, Any}(),
|
2019-09-18 14:22:04 +00:00
|
|
|
)
|
2019-02-05 17:31:51 +00:00
|
|
|
|
2019-09-01 14:03:19 +00:00
|
|
|
Sets up documentation generation via [Documenter.jl](https://github.com/JuliaDocs/Documenter.jl).
|
2019-02-05 17:31:51 +00:00
|
|
|
Documentation deployment depends on `T`, where `T` is some supported CI plugin, or `Nothing` to only support local documentation builds.
|
|
|
|
|
2019-09-25 14:56:00 +00:00
|
|
|
## Supported Type Parameters
|
|
|
|
- `TravisCI`: Deploys documentation to [GitHub Pages](https://pages.github.com) with the help of [`TravisCI`](@ref).
|
|
|
|
- `GitLabCI`: Deploys documentation to [GitLab Pages](https://pages.gitlab.com) with the help of [`GitLabCI`](@ref).
|
|
|
|
- `Nothing` (default): Does not set up documentation deployment.
|
|
|
|
|
2019-02-05 17:31:51 +00:00
|
|
|
## Keyword Arguments
|
2019-09-01 14:03:19 +00:00
|
|
|
- `make_jl::AbstractString`: Template file for `make.jl`.
|
|
|
|
- `index_md::AbstractString`: Template file for `index.md`.
|
|
|
|
- `assets::Vector{<:AbstractString}`: Extra assets for the generated site.
|
|
|
|
- `canonical_url::Union{Function, Nothing}`: A function to generate the documentation site's canonical URL.
|
|
|
|
The default value will compute GitHub Pages and GitLab Pages URLs for [`TravisCI`](@ref) and [`GitLabCI`](@ref), respectively.
|
|
|
|
- `makedocs_kwargs::Dict{Symbol}`: Extra keyword arguments to be inserted into `makedocs`.
|
2019-02-05 17:31:51 +00:00
|
|
|
|
|
|
|
!!! note
|
2019-09-25 14:56:00 +00:00
|
|
|
If deploying documentation with Travis CI, don't forget to complete [the required configuration](https://juliadocs.github.io/Documenter.jl/stable/man/hosting/#SSH-Deploy-Keys-1).
|
2018-11-05 21:39:14 +00:00
|
|
|
"""
|
2019-02-05 17:31:51 +00:00
|
|
|
struct Documenter{T<:Union{TravisCI, GitLabCI, Nothing}} <: Plugin
|
|
|
|
assets::Vector{String}
|
|
|
|
makedocs_kwargs::Dict{Symbol}
|
|
|
|
canonical_url::Union{Function, Nothing}
|
2019-08-27 14:59:25 +00:00
|
|
|
make_jl::String
|
|
|
|
index_md::String
|
2019-02-05 17:31:51 +00:00
|
|
|
|
2019-09-02 14:20:33 +00:00
|
|
|
# Can't use @with_kw_noshow due to some weird precompilation issues.
|
2019-08-31 14:09:22 +00:00
|
|
|
function Documenter{T}(;
|
2019-02-05 17:31:51 +00:00
|
|
|
assets::Vector{<:AbstractString}=String[],
|
|
|
|
makedocs_kwargs::Dict{Symbol}=Dict{Symbol, Any}(),
|
2019-08-31 14:09:22 +00:00
|
|
|
canonical_url::Union{Function, Nothing}=make_canonical(T),
|
2019-09-19 05:51:04 +00:00
|
|
|
make_jl::AbstractString=default_file("docs", "make.jl"),
|
|
|
|
index_md::AbstractString=default_file("docs", "index.md"),
|
2019-02-05 17:31:51 +00:00
|
|
|
) where T <: Union{TravisCI, GitLabCI, Nothing}
|
2019-08-31 14:09:22 +00:00
|
|
|
return new(assets, makedocs_kwargs, canonical_url, make_jl, index_md)
|
2019-02-05 17:31:51 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Documenter(; kwargs...) = Documenter{Nothing}(; kwargs...)
|
|
|
|
|
2019-09-26 03:42:03 +00:00
|
|
|
gitignore(::Documenter) = ["/docs/build/"]
|
2019-02-05 17:31:51 +00:00
|
|
|
|
|
|
|
badges(::Documenter) = Badge[]
|
|
|
|
badges(::Documenter{TravisCI}) = [
|
|
|
|
Badge(
|
|
|
|
"Stable",
|
|
|
|
"https://img.shields.io/badge/docs-stable-blue.svg",
|
2019-09-18 15:27:16 +00:00
|
|
|
"https://{{{USER}}}.github.io/{{{PKG}}}.jl/stable",
|
2019-02-05 17:31:51 +00:00
|
|
|
),
|
|
|
|
Badge(
|
|
|
|
"Dev",
|
|
|
|
"https://img.shields.io/badge/docs-dev-blue.svg",
|
2019-09-18 15:27:16 +00:00
|
|
|
"https://{{{USER}}}.github.io/{{{PKG}}}.jl/dev",
|
2019-02-05 17:31:51 +00:00
|
|
|
),
|
|
|
|
]
|
|
|
|
badges(::Documenter{GitLabCI}) = Badge(
|
|
|
|
"Dev",
|
|
|
|
"https://img.shields.io/badge/docs-dev-blue.svg",
|
2019-09-18 15:27:16 +00:00
|
|
|
"https://{{{USER}}}.gitlab.io/{{{PKG}}}.jl/dev",
|
2019-02-05 17:31:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
view(p::Documenter, t::Template, pkg::AbstractString) = Dict(
|
|
|
|
"ASSETS" => p.assets,
|
2019-08-27 11:17:15 +00:00
|
|
|
"AUTHORS" => join(t.authors, ", "),
|
2019-02-05 17:31:51 +00:00
|
|
|
"CANONICAL" => p.canonical_url === nothing ? nothing : p.canonical_url(t, pkg),
|
|
|
|
"HAS_ASSETS" => !isempty(p.assets),
|
2019-08-31 14:09:22 +00:00
|
|
|
"MAKEDOCS_KWARGS" => map(((k, v),) -> k => repr(v), collect(p.makedocs_kwargs)),
|
2019-02-05 17:31:51 +00:00
|
|
|
"PKG" => pkg,
|
2019-08-31 10:49:20 +00:00
|
|
|
"REPO" => "$(t.host)/$(t.user)/$pkg.jl",
|
2019-08-29 16:04:11 +00:00
|
|
|
"USER" => t.user,
|
2019-02-05 17:31:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
function view(p::Documenter{TravisCI}, t::Template, pkg::AbstractString)
|
|
|
|
base = invoke(view, Tuple{Documenter, Template, AbstractString}, p, t, pkg)
|
|
|
|
return merge(base, Dict("HAS_DEPLOY" => true))
|
|
|
|
end
|
2017-08-11 22:18:09 +00:00
|
|
|
|
2019-09-25 16:26:03 +00:00
|
|
|
foreach((TravisCI, GitLabCI)) do T
|
|
|
|
@eval function validate(::Documenter{$T}, t::Template)
|
|
|
|
if !hasplugin(t, $T)
|
|
|
|
name = nameof($T)
|
|
|
|
s = "Documenter: The $name plugin must be included for docs deployment to be set up"
|
|
|
|
throw(ArgumentError(s))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-19 17:21:06 +00:00
|
|
|
function hook(p::Documenter, t::Template, pkg_dir::AbstractString)
|
2019-08-31 11:45:41 +00:00
|
|
|
pkg = basename(pkg_dir)
|
2019-08-29 16:04:11 +00:00
|
|
|
docs_dir = joinpath(pkg_dir, "docs")
|
|
|
|
|
|
|
|
# Generate files.
|
|
|
|
make = render_file(p.make_jl, combined_view(p, t, pkg), tags(p))
|
|
|
|
index = render_file(p.index_md, combined_view(p, t, pkg), tags(p))
|
2019-09-19 17:21:06 +00:00
|
|
|
gen_file(joinpath(docs_dir, "make.jl"), make)
|
2019-08-29 16:04:11 +00:00
|
|
|
gen_file(joinpath(docs_dir, "src", "index.md"), index)
|
|
|
|
|
|
|
|
# Copy over any assets.
|
|
|
|
assets_dir = joinpath(docs_dir, "src", "assets")
|
|
|
|
isempty(p.assets) || mkpath(assets_dir)
|
|
|
|
foreach(a -> cp(a, joinpath(assets_dir, basename(a))), p.assets)
|
2018-09-28 20:30:10 +00:00
|
|
|
|
2018-12-14 20:55:13 +00:00
|
|
|
# Create the documentation project.
|
2019-09-18 14:25:48 +00:00
|
|
|
with_project(() -> Pkg.add(DOCUMENTER_DEP), docs_dir)
|
2019-02-05 17:31:51 +00:00
|
|
|
end
|
2018-09-28 20:30:10 +00:00
|
|
|
|
2019-02-05 17:31:51 +00:00
|
|
|
github_pages_url(t::Template, pkg::AbstractString) = "https://$(t.user).github.io/$pkg.jl"
|
2019-08-31 14:09:22 +00:00
|
|
|
gitlab_pages_url(t::Template, pkg::AbstractString) = "https://$(t.user).gitlab.io/$pkg.jl"
|
|
|
|
|
|
|
|
make_canonical(::Type{TravisCI}) = github_pages_url
|
|
|
|
make_canonical(::Type{GitLabCI}) = gitlab_pages_url
|
|
|
|
make_canonical(::Type{Nothing}) = nothing
|
2019-09-25 02:45:08 +00:00
|
|
|
|
|
|
|
needs_username(::Documenter) = true
|