Add a pretty show method

This commit is contained in:
Chris de Graaf 2017-12-01 17:33:57 +00:00
parent d075ff678e
commit 74ab858800
3 changed files with 97 additions and 0 deletions

View File

@ -1,3 +1,5 @@
import Base.show
""" """
Generic plugins are plugins that add any number of patterns to the generated package's Generic plugins are plugins that add any number of patterns to the generated package's
`.gitignore`, and have at most one associated file to generate. `.gitignore`, and have at most one associated file to generate.
@ -67,6 +69,23 @@ config template file doesn't follow the generic naming convention, we added anot
""" """
abstract type GenericPlugin <: Plugin end abstract type GenericPlugin <: Plugin end
function show(io::IO, p::GenericPlugin)
t = split(string(typeof(p)), ".")[end]
println(io, "$t:")
cfg = if isnull(p.src)
"None"
else
dirname(get(p.src)) == DEFAULTS_DIR ? "Default" : get(p.src)
end
println(io, " → Config file: $cfg")
n = length(p.gitignore)
s = n == 1 ? "" : "s"
print(io, "$n gitignore entrie$s")
n > 0 && print(io, ": $(join(map(g -> "\"$g\"", p.gitignore), ", "))")
end
""" """
Custom plugins are plugins whose behaviour does not follow the [`GenericPlugin`](@ref) Custom plugins are plugins whose behaviour does not follow the [`GenericPlugin`](@ref)
pattern. They can implement [`gen_plugin`](@ref), [`badges`](@ref), and pattern. They can implement [`gen_plugin`](@ref), [`badges`](@ref), and

View File

@ -1,3 +1,5 @@
import Base.show
""" """
Add a `Documenter` subtype to a template's plugins to add support for documentation Add a `Documenter` subtype to a template's plugins to add support for documentation
generation via [Documenter.jl](https://github.com/JuliaDocs/Documenter.jl). generation via [Documenter.jl](https://github.com/JuliaDocs/Documenter.jl).
@ -59,6 +61,25 @@ function gen_plugin(
end end
end end
function show(io::IO, p::Documenter)
t = split(string(typeof(p)), ".")[end]
println(io, "$t:")
n = length(p.assets)
s = n == 1 ? "" : "s"
print(io, "$n asset file$s")
if n == 0
println(io)
else
println(io, ": $(join(map(a -> replace(a, homedir(), "~"), p.assets), ", "))")
end
n = length(p.gitignore)
s = n == 1 ? "" : "s"
print(io, "$n gitignore entrie$s")
n > 0 && print(io, ": $(join(map(g -> "\"$g\"", p.gitignore), ", "))")
end
function interactive(plugin_type::Type{<:Documenter}) function interactive(plugin_type::Type{<:Documenter})
plugin_name = split(string(plugin_type), ".")[end] plugin_name = split(string(plugin_type), ".")[end]
print("$plugin_name: Enter any Documenter asset files (separated by spaces) []: ") print("$plugin_name: Enter any Documenter asset files (separated by spaces) []: ")

View File

@ -1,3 +1,5 @@
import Base.show
""" """
Template(; kwargs...) -> Template Template(; kwargs...) -> Template
@ -111,6 +113,61 @@ create a template, you can use [`interactive_template`](@ref) instead.
end end
end end
function show(io::IO, t::Template)
maybe_none(s::AbstractString) = isempty(string(s)) ? "None" : string(s)
spc = " "
println(io, "Template:")
println(io, "$spc→ User: $(maybe_none(t.user))")
println(io, "$spc→ Host: $(maybe_none(t.host))")
println(io, "$spc→ License: $(maybe_none(t.license))")
# We don't care about authors or license years if there is no license.
if !isempty(t.license)
# TODO: Authors could be split into multiple lines if there are more than one.
# Maybe the authors field of Template should be an array (or Dict, see #4).
println(io, "$spc→ Authors: $(maybe_none(t.authors))")
println(io, "$spc→ License years: $(maybe_none(t.years))")
end
println(io, "$spc→ Package directory: $(replace(maybe_none(t.dir), homedir(), "~"))")
println(io, "$spc→ Precompilation enabled: $(t.precompile ? "yes" : "no")")
println(io, "$spc→ Minimum Julia version: v$(t.julia_version)")
print(io, "$spc→ Package dependencies: ")
if isempty(t.requirements)
println(io, "None")
else
println(io)
for req in sort(t.requirements)
println(io, "$(spc^2)$req")
end
end
print(io, "$spc→ Git configuration options: ")
if isempty(t.gitconfig)
println(io, "None")
else
println(io)
for k in sort(collect(keys(t.gitconfig)); by=string)
println(io, "$(spc^2)$k = $(t.gitconfig[k])")
end
end
print(io, "$spc→ Plugins: ")
if isempty(t.plugins)
print(io, "None")
else
for plugin in sort(collect(values(t.plugins)); by=string)
println(io)
buf = IOBuffer()
show(buf, plugin)
print(io, "$(spc^2)")
print(io, join(split(String(take!(buf)), "\n"), "\n$(spc^2)"))
end
end
end
""" """
interactive_template(; fast::Bool=false) -> Template interactive_template(; fast::Bool=false) -> Template