Only use custom show methods for plaintext display
Thanks Lyndon: https://github.com/invenia/PkgTemplates.jl/issues/80#issuecomment-527351832
This commit is contained in:
parent
481d8430e6
commit
2d7c851fca
@ -3,7 +3,7 @@
|
|||||||
# leaves(Plugin)
|
# leaves(Plugin)
|
||||||
# end
|
# end
|
||||||
|
|
||||||
function Base.show(io::IO, p::T) where T <: Plugin
|
function Base.show(io::IO, ::MIME"text/plain", p::T) where T <: Plugin
|
||||||
indent = get(io, :indent, 0)
|
indent = get(io, :indent, 0)
|
||||||
print(io, repeat(' ', indent), T, ":")
|
print(io, repeat(' ', indent), T, ":")
|
||||||
foreach(fieldnames(T)) do n
|
foreach(fieldnames(T)) do n
|
||||||
@ -15,7 +15,7 @@ end
|
|||||||
show_field(x) = repr(x)
|
show_field(x) = repr(x)
|
||||||
show_field(x::AbstractString) = repr(contractuser(x))
|
show_field(x::AbstractString) = repr(contractuser(x))
|
||||||
|
|
||||||
function Base.show(io::IO, t::Template)
|
function Base.show(io::IO, m::MIME"text/plain", t::Template)
|
||||||
println(io, "Template:")
|
println(io, "Template:")
|
||||||
foreach(fieldnames(Template)) do n
|
foreach(fieldnames(Template)) do n
|
||||||
n === :plugins || println(io, repeat(' ', 2), n, ": ", show_field(getfield(t, n)))
|
n === :plugins || println(io, repeat(' ', 2), n, ": ", show_field(getfield(t, n)))
|
||||||
@ -24,9 +24,9 @@ function Base.show(io::IO, t::Template)
|
|||||||
print(io, " plugins: None")
|
print(io, " plugins: None")
|
||||||
else
|
else
|
||||||
print(io, repeat(' ', 2), "plugins:")
|
print(io, repeat(' ', 2), "plugins:")
|
||||||
foreach(values(t.plugins)) do p
|
foreach(sort(collect(values(t.plugins)); by=string)) do p
|
||||||
println(io)
|
println(io)
|
||||||
show(IOContext(io, :indent => 4), p)
|
show(IOContext(io, :indent => 4), m, p)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
24
test/show.jl
24
test/show.jl
@ -9,7 +9,7 @@ const LICENSE_DIR = contractuser(PT.LICENSE_DIR)
|
|||||||
destination: "README.md"
|
destination: "README.md"
|
||||||
inline_badges: false
|
inline_badges: false
|
||||||
"""
|
"""
|
||||||
@test sprint(show, Readme()) == rstrip(expected)
|
@test sprint(show, MIME("text/plain"), Readme()) == rstrip(expected)
|
||||||
end
|
end
|
||||||
|
|
||||||
@testset "Template" begin
|
@testset "Template" begin
|
||||||
@ -17,7 +17,7 @@ const LICENSE_DIR = contractuser(PT.LICENSE_DIR)
|
|||||||
Template:
|
Template:
|
||||||
authors: ["$USER"]
|
authors: ["$USER"]
|
||||||
develop: true
|
develop: true
|
||||||
dir: "$(Pkg.devdir())"
|
dir: "$(contractuser(Pkg.devdir()))"
|
||||||
git: true
|
git: true
|
||||||
host: "github.com"
|
host: "github.com"
|
||||||
julia_version: v"1.0.0"
|
julia_version: v"1.0.0"
|
||||||
@ -25,18 +25,26 @@ const LICENSE_DIR = contractuser(PT.LICENSE_DIR)
|
|||||||
ssh: false
|
ssh: false
|
||||||
user: "$USER"
|
user: "$USER"
|
||||||
plugins:
|
plugins:
|
||||||
Readme:
|
|
||||||
file: "$DEFAULTS_DIR/README.md"
|
|
||||||
destination: "README.md"
|
|
||||||
inline_badges: false
|
|
||||||
Tests:
|
|
||||||
file: "$DEFAULTS_DIR/runtests.jl"
|
|
||||||
Gitignore:
|
Gitignore:
|
||||||
ds_store: true
|
ds_store: true
|
||||||
dev: true
|
dev: true
|
||||||
License:
|
License:
|
||||||
path: "$LICENSE_DIR/MIT"
|
path: "$LICENSE_DIR/MIT"
|
||||||
destination: "LICENSE"
|
destination: "LICENSE"
|
||||||
|
Readme:
|
||||||
|
file: "$DEFAULTS_DIR/README.md"
|
||||||
|
destination: "README.md"
|
||||||
|
inline_badges: false
|
||||||
|
Tests:
|
||||||
|
file: "$DEFAULTS_DIR/runtests.jl"
|
||||||
"""
|
"""
|
||||||
|
@test sprint(show, MIME("text/plain"), tpl(; authors=USER)) == rstrip(expected)
|
||||||
|
end
|
||||||
|
|
||||||
|
@testset "show as serialization" begin
|
||||||
|
# Equality is not implemented for Template, so check the string form.
|
||||||
|
t1 = tpl()
|
||||||
|
t2 = eval(Meta.parse(sprint(show, t1)))
|
||||||
|
@test sprint(show, t1) == sprint(show, t2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user