Add interactive constructor for Documenter

This commit is contained in:
Chris de Graaf 2019-09-27 00:08:02 +07:00
parent 3a9c9634e6
commit a373a25c05
No known key found for this signature in database
GPG Key ID: 150FFDD9B0073C7B
4 changed files with 36 additions and 4 deletions

View File

@ -173,6 +173,16 @@ function prompt(
return convert(Vector{String}, map(strip, split(s, ","; keepempty=false)))
end
function prompt(::Type{<:Dict}, s::AbstractString, default::Dict, required::Bool=false)
default_display = join(map(p -> "$(p.first)=$(p.second)", collect(default)), ", ")
s = prompt(String, "$s (k=v, comma-delimited)", default_display; required=required)
return if isempty(s)
Dict{String, String}()
else
Dict{String, String}(Pair(split(strip(kv), "=")...) for kv in split(s, ","))
end
end
# TODO: These can be made simpler when this is merged:
# https://github.com/JuliaLang/julia/pull/30043
@ -182,7 +192,7 @@ select(s::AbstractString, xs::Vector, initial) = select(string, s, xs, initial)
function select(f::Function, s::AbstractString, xs::Vector, initial::Vector)
m = MultiSelectMenu(map(f, xs); pagesize=length(xs))
foreach(x -> push!(m.selected, findfirst(==(x), xs)), initial)
selection = request(s, m)
selection = request("$s:", m)
return map(i -> xs[i], collect(selection))
end

View File

@ -6,7 +6,7 @@ const DOCUMENTER_DEP = PackageSpec(;
"""
Documenter{T<:Union{TravisCI, GitLabCI, Nothing}}(;
make_jl="$(contractuser(default_file("docs", "make.jl")))",
index_md="$(contractuser(default_file("docs", "index.md")))",
index_md="$(contractuser(default_file("docs", "src", "index.md")))",
assets=String[],
canonical_url=make_canonical(T),
makedocs_kwargs=Dict{Symbol, Any}(),
@ -44,7 +44,7 @@ struct Documenter{T<:Union{TravisCI, GitLabCI, Nothing}} <: Plugin
makedocs_kwargs::Dict{Symbol}=Dict{Symbol, Any}(),
canonical_url::Union{Function, Nothing}=make_canonical(T),
make_jl::AbstractString=default_file("docs", "make.jl"),
index_md::AbstractString=default_file("docs", "index.md"),
index_md::AbstractString=default_file("docs", "src", "index.md"),
) where T <: Union{TravisCI, GitLabCI, Nothing}
return new(assets, makedocs_kwargs, canonical_url, make_jl, index_md)
end
@ -52,6 +52,28 @@ end
Documenter(; kwargs...) = Documenter{Nothing}(; kwargs...)
function interactive(::Type{Documenter})
kwargs = Dict{Symbol, Any}()
default = default_file("docs", "make.jl")
kwargs[:make_jl] = prompt(String, "Documenter: Path to make.jl template", default)
default = default_file("docs", "src", "index.md")
kwargs[:index_md] = prompt(String, "Documenter: Path to make.jl template", default)
kwargs[:assets] = prompt(Vector{String}, "Documenter: Extra asset files", String[])
md_kw = prompt(Dict{String, String}, "Documenter: makedocs keyword arguments", Dict())
parsed = Dict{Symbol, Any}(Symbol(p.first) => eval(Meta.parse(p.second)) for p in md_kw)
kwargs[:makedocs_kwargs] = parsed
available = [Nothing, TravisCI, GitLabCI]
f = T -> string(nameof(T))
T = select(f, "Documenter: Documentation deployment strategy", available, Nothing)
return Documenter{T}(; kwargs...)
end
gitignore(::Documenter) = ["/docs/build/"]
badges(::Documenter) = Badge[]

View File

@ -7,7 +7,7 @@ Creates a module entrypoint.
- `file::AbstractString`: Template file for `src/<module>.jl`.
"""
@with_defaults mutable struct SrcDir <: BasicPlugin
file::String = default_file("src", "module.jl") <- "Path to src/<module>.jl template"
file::String = default_file("src", "module.jl") <- "Path to <module>.jl template"
destination::String = joinpath("src", "<module>.jl")
end