Add show methods
This commit is contained in:
parent
65f5eff29b
commit
481d8430e6
@ -65,3 +65,19 @@ Documenter
|
|||||||
```@docs
|
```@docs
|
||||||
Citation
|
Citation
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Saving Templates
|
||||||
|
|
||||||
|
One of the main reasons for PkgTemplates' existence is for new packages to be consistent.
|
||||||
|
This means using the same template more than once, so we want a way to save a template to be used later.
|
||||||
|
|
||||||
|
Here's my recommendation for loading a template whenever it's needed:
|
||||||
|
|
||||||
|
```julia
|
||||||
|
function template()
|
||||||
|
@eval using PkgTemplates
|
||||||
|
Template(; #= ... =#)
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
Add this to your `startup.jl`, and you can create your template from anywhere, without incurring any startup cost.
|
||||||
|
@ -10,7 +10,7 @@ using Pkg: Pkg, TOML, PackageSpec
|
|||||||
using REPL.TerminalMenus: MultiSelectMenu, RadioMenu, request
|
using REPL.TerminalMenus: MultiSelectMenu, RadioMenu, request
|
||||||
|
|
||||||
using Mustache: entityMap, render
|
using Mustache: entityMap, render
|
||||||
using Parameters: @with_kw
|
using Parameters: @with_kw_noshow
|
||||||
|
|
||||||
export
|
export
|
||||||
Template,
|
Template,
|
||||||
@ -35,5 +35,6 @@ abstract type Plugin end
|
|||||||
include("template.jl")
|
include("template.jl")
|
||||||
include("generate.jl")
|
include("generate.jl")
|
||||||
include("plugin.jl")
|
include("plugin.jl")
|
||||||
|
include("interactive.jl")
|
||||||
|
|
||||||
end
|
end
|
||||||
|
32
src/interactive.jl
Normal file
32
src/interactive.jl
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
# const PLUGIN_TYPES = let
|
||||||
|
# leaves(T::Type) = isconcretetype(T) ? [T] : vcat(map(leaves, subtypes(T))...)
|
||||||
|
# leaves(Plugin)
|
||||||
|
# end
|
||||||
|
|
||||||
|
function Base.show(io::IO, p::T) where T <: Plugin
|
||||||
|
indent = get(io, :indent, 0)
|
||||||
|
print(io, repeat(' ', indent), T, ":")
|
||||||
|
foreach(fieldnames(T)) do n
|
||||||
|
println(io)
|
||||||
|
print(io, repeat(' ', indent + 2), n, ": ", show_field(getfield(p, n)))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
show_field(x) = repr(x)
|
||||||
|
show_field(x::AbstractString) = repr(contractuser(x))
|
||||||
|
|
||||||
|
function Base.show(io::IO, t::Template)
|
||||||
|
println(io, "Template:")
|
||||||
|
foreach(fieldnames(Template)) do n
|
||||||
|
n === :plugins || println(io, repeat(' ', 2), n, ": ", show_field(getfield(t, n)))
|
||||||
|
end
|
||||||
|
if isempty(t.plugins)
|
||||||
|
print(io, " plugins: None")
|
||||||
|
else
|
||||||
|
print(io, repeat(' ', 2), "plugins:")
|
||||||
|
foreach(values(t.plugins)) do p
|
||||||
|
println(io)
|
||||||
|
show(IOContext(io, :indent => 4), p)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -40,7 +40,7 @@ Integrates your packages with [Travis CI](https://travis-ci.com).
|
|||||||
- `coverage::Bool`: Whether or not to publish code coverage (another code coverage plugin such as [`Codecov`](@ref) must also be included).
|
- `coverage::Bool`: Whether or not to publish code coverage (another code coverage plugin such as [`Codecov`](@ref) must also be included).
|
||||||
$EXTRA_VERSIONS_DOC
|
$EXTRA_VERSIONS_DOC
|
||||||
"""
|
"""
|
||||||
@with_kw struct TravisCI <: BasicPlugin
|
@with_kw_noshow struct TravisCI <: BasicPlugin
|
||||||
file::String = default_file("travis.yml")
|
file::String = default_file("travis.yml")
|
||||||
linux::Bool = true
|
linux::Bool = true
|
||||||
osx::Bool = true
|
osx::Bool = true
|
||||||
@ -109,7 +109,7 @@ Integrates your packages with [AppVeyor](https://appveyor.com) via [AppVeyor.jl]
|
|||||||
- `coverage::Bool`: Whether or not to publish code coverage ([`Codecov`](@ref) must also be included).
|
- `coverage::Bool`: Whether or not to publish code coverage ([`Codecov`](@ref) must also be included).
|
||||||
$EXTRA_VERSIONS_DOC
|
$EXTRA_VERSIONS_DOC
|
||||||
"""
|
"""
|
||||||
@with_kw struct AppVeyor <: BasicPlugin
|
@with_kw_noshow struct AppVeyor <: BasicPlugin
|
||||||
file::String = default_file("appveyor.yml")
|
file::String = default_file("appveyor.yml")
|
||||||
x86::Bool = false
|
x86::Bool = false
|
||||||
coverage::Bool = true
|
coverage::Bool = true
|
||||||
@ -162,7 +162,7 @@ $EXTRA_VERSIONS_DOC
|
|||||||
!!! note
|
!!! note
|
||||||
Code coverage submission from Cirrus CI is not yet supported by [Coverage.jl](https://github.com/JuliaCI/Coverage.jl).
|
Code coverage submission from Cirrus CI is not yet supported by [Coverage.jl](https://github.com/JuliaCI/Coverage.jl).
|
||||||
"""
|
"""
|
||||||
@with_kw struct CirrusCI <: BasicPlugin
|
@with_kw_noshow struct CirrusCI <: BasicPlugin
|
||||||
file::String = default_file("cirrus.yml")
|
file::String = default_file("cirrus.yml")
|
||||||
image::String = "freebsd-12-0-release-amd64"
|
image::String = "freebsd-12-0-release-amd64"
|
||||||
coverage::Bool = true
|
coverage::Bool = true
|
||||||
@ -211,7 +211,7 @@ See [`Documenter`](@ref) for more information.
|
|||||||
!!! note
|
!!! note
|
||||||
Nightly Julia is not supported.
|
Nightly Julia is not supported.
|
||||||
"""
|
"""
|
||||||
@with_kw struct GitLabCI <: BasicPlugin
|
@with_kw_noshow struct GitLabCI <: BasicPlugin
|
||||||
file::String = default_file("gitlab-ci.yml")
|
file::String = default_file("gitlab-ci.yml")
|
||||||
coverage::Bool = true
|
coverage::Bool = true
|
||||||
# Nightly has no Docker image.
|
# Nightly has no Docker image.
|
||||||
|
@ -10,7 +10,7 @@ Creates a `CITATION.bib` file for citing package repositories.
|
|||||||
- `file::AbstractString`: Template file for `CITATION.bib`.
|
- `file::AbstractString`: Template file for `CITATION.bib`.
|
||||||
- `readme::Bool`: Whether or not to include a section about citing in the README.
|
- `readme::Bool`: Whether or not to include a section about citing in the README.
|
||||||
"""
|
"""
|
||||||
@with_kw struct Citation <: BasicPlugin
|
@with_kw_noshow struct Citation <: BasicPlugin
|
||||||
file::String = default_file("CITATION.bib")
|
file::String = default_file("CITATION.bib")
|
||||||
readme::Bool = false
|
readme::Bool = false
|
||||||
end
|
end
|
||||||
|
@ -8,7 +8,7 @@ Sets up code coverage submission from CI to [Codecov](https://codecov.io).
|
|||||||
## Keyword Arguments
|
## Keyword Arguments
|
||||||
- `file::Union{AbstractString, Nothing}`: Template file for `.codecov.yml`, or `nothing` to create no file.
|
- `file::Union{AbstractString, Nothing}`: Template file for `.codecov.yml`, or `nothing` to create no file.
|
||||||
"""
|
"""
|
||||||
@with_kw struct Codecov <: BasicPlugin
|
@with_kw_noshow struct Codecov <: BasicPlugin
|
||||||
file::Union{String, Nothing} = nothing
|
file::Union{String, Nothing} = nothing
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ Sets up code coverage submission from CI to [Coveralls](https://coveralls.io).
|
|||||||
## Keyword Arguments
|
## Keyword Arguments
|
||||||
- `file::Union{AbstractString, Nothing}`: Template file for `.coveralls.yml`, or `nothing` to create no file.
|
- `file::Union{AbstractString, Nothing}`: Template file for `.coveralls.yml`, or `nothing` to create no file.
|
||||||
"""
|
"""
|
||||||
@with_kw struct Coveralls <: BasicPlugin
|
@with_kw_noshow struct Coveralls <: BasicPlugin
|
||||||
file::Union{String, Nothing} = nothing
|
file::Union{String, Nothing} = nothing
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ By default, it includes badges for other included plugins
|
|||||||
For example, values of `"README"` or `"README.rst"` might be desired.
|
For example, values of `"README"` or `"README.rst"` might be desired.
|
||||||
- `inline_badges::Bool`: Whether or not to put the badges on the same line as the package name.
|
- `inline_badges::Bool`: Whether or not to put the badges on the same line as the package name.
|
||||||
"""
|
"""
|
||||||
@with_kw struct Readme <: BasicPlugin
|
@with_kw_noshow struct Readme <: BasicPlugin
|
||||||
file::String = default_file("README.md")
|
file::String = default_file("README.md")
|
||||||
destination::String = "README.md"
|
destination::String = "README.md"
|
||||||
inline_badges::Bool = false
|
inline_badges::Bool = false
|
||||||
@ -114,7 +114,7 @@ Creates a `.gitignore` file.
|
|||||||
- `ds_store::Bool`: Whether or not to ignore MacOS's `.DS_Store` files.
|
- `ds_store::Bool`: Whether or not to ignore MacOS's `.DS_Store` files.
|
||||||
- `dev::Bool`: Whether or not to ignore the directory of locally-developed packages.
|
- `dev::Bool`: Whether or not to ignore the directory of locally-developed packages.
|
||||||
"""
|
"""
|
||||||
@with_kw struct Gitignore <: Plugin
|
@with_kw_noshow struct Gitignore <: Plugin
|
||||||
ds_store::Bool = true
|
ds_store::Bool = true
|
||||||
dev::Bool = true
|
dev::Bool = true
|
||||||
end
|
end
|
||||||
@ -142,7 +142,7 @@ Sets up testing for packages.
|
|||||||
## Keyword Arguments
|
## Keyword Arguments
|
||||||
- `file::AbstractString`: Template file for the `runtests.jl`.
|
- `file::AbstractString`: Template file for the `runtests.jl`.
|
||||||
"""
|
"""
|
||||||
@with_kw struct Tests <: BasicPlugin
|
@with_kw_noshow struct Tests <: BasicPlugin
|
||||||
file::String = default_file("runtests.jl")
|
file::String = default_file("runtests.jl")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ struct Documenter{T<:Union{TravisCI, GitLabCI, Nothing}} <: Plugin
|
|||||||
make_jl::String
|
make_jl::String
|
||||||
index_md::String
|
index_md::String
|
||||||
|
|
||||||
# Can't use @with_kw due to some weird precompilation issues.
|
# Can't use @with_kw_noshow due to some weird precompilation issues.
|
||||||
function Documenter{T}(;
|
function Documenter{T}(;
|
||||||
assets::Vector{<:AbstractString}=String[],
|
assets::Vector{<:AbstractString}=String[],
|
||||||
makedocs_kwargs::Dict{Symbol}=Dict{Symbol, Any}(),
|
makedocs_kwargs::Dict{Symbol}=Dict{Symbol, Any}(),
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using Base.Filesystem: path_separator
|
using Base.Filesystem: contractuser, path_separator
|
||||||
|
|
||||||
using LibGit2: LibGit2, GitCommit, GitRemote, GitRepo
|
using LibGit2: LibGit2, GitCommit, GitRemote, GitRepo
|
||||||
using Pkg: Pkg
|
using Pkg: Pkg
|
||||||
@ -43,6 +43,7 @@ mktempdir() do dir
|
|||||||
include("template.jl")
|
include("template.jl")
|
||||||
include("plugin.jl")
|
include("plugin.jl")
|
||||||
include("git.jl")
|
include("git.jl")
|
||||||
|
include("show.jl")
|
||||||
|
|
||||||
# Quite a bit of output depends on the Julia version,
|
# Quite a bit of output depends on the Julia version,
|
||||||
# and the test fixtures are made with Julia 1.2.
|
# and the test fixtures are made with Julia 1.2.
|
||||||
|
42
test/show.jl
Normal file
42
test/show.jl
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
const DEFAULTS_DIR = contractuser(PT.DEFAULTS_DIR)
|
||||||
|
const LICENSE_DIR = contractuser(PT.LICENSE_DIR)
|
||||||
|
|
||||||
|
@testset "Show methods" begin
|
||||||
|
@testset "Plugins" begin
|
||||||
|
expected = """
|
||||||
|
Readme:
|
||||||
|
file: "$DEFAULTS_DIR/README.md"
|
||||||
|
destination: "README.md"
|
||||||
|
inline_badges: false
|
||||||
|
"""
|
||||||
|
@test sprint(show, Readme()) == rstrip(expected)
|
||||||
|
end
|
||||||
|
|
||||||
|
@testset "Template" begin
|
||||||
|
expected = """
|
||||||
|
Template:
|
||||||
|
authors: ["$USER"]
|
||||||
|
develop: true
|
||||||
|
dir: "$(Pkg.devdir())"
|
||||||
|
git: true
|
||||||
|
host: "github.com"
|
||||||
|
julia_version: v"1.0.0"
|
||||||
|
manifest: false
|
||||||
|
ssh: false
|
||||||
|
user: "$USER"
|
||||||
|
plugins:
|
||||||
|
Readme:
|
||||||
|
file: "$DEFAULTS_DIR/README.md"
|
||||||
|
destination: "README.md"
|
||||||
|
inline_badges: false
|
||||||
|
Tests:
|
||||||
|
file: "$DEFAULTS_DIR/runtests.jl"
|
||||||
|
Gitignore:
|
||||||
|
ds_store: true
|
||||||
|
dev: true
|
||||||
|
License:
|
||||||
|
path: "$LICENSE_DIR/MIT"
|
||||||
|
destination: "LICENSE"
|
||||||
|
"""
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user