Misc style changes

This commit is contained in:
Chris de Graaf 2017-12-12 15:15:55 +00:00
parent bab42686d8
commit 75c7875899
7 changed files with 24 additions and 29 deletions

View File

@ -88,7 +88,7 @@ function generate(
gen_readme(dir, pkg_name, t),
gen_gitignore(dir, pkg_name, t),
gen_license(dir, pkg_name, t),
vcat([gen_plugin(plugin, t, dir, pkg_name) for plugin in values(t.plugins)]...),
vcat(map(p -> gen_plugin(p, t, dir, pkg_name), values(t.plugins))...),
)
LibGit2.add!(repo, files...)
@ -307,7 +307,7 @@ Returns an array of generated file/directory names.
"""
function gen_gitignore(dir::AbstractString, pkg_name::AbstractString, template::Template)
seen = [".DS_Store"]
patterns = vcat([plugin.gitignore for plugin in values(template.plugins)]...)
patterns = vcat(map(p -> p.gitignore, values(template.plugins))...)
for pattern in patterns
if !in(pattern, seen)
push!(seen, pattern)
@ -390,9 +390,15 @@ end
"""
substitute(template::AbstractString, view::Dict{String, Any}) -> String
substitute(
template::AbstractString,
pkg_template::Template;
view::Dict{String, Any}=Dict{String, Any}(),
) -> String
Replace placeholders in `template` with values in `view` via
[`Mustache`](https://github.com/jverzani/Mustache.jl). `template` is not modified.
If `pkg_template` is supplied, some default replacements are also performed.
For information on how to structure `template`, see "Defining Template Files" section in
[Custom Plugins](@ref).
@ -402,16 +408,6 @@ but will simply be evaluated as false.
"""
substitute(template::AbstractString, view::Dict{String, Any}) = render(template, view)
"""
substitute(
template::AbstractString,
pkg_template::Template;
view::Dict{String, Any}=Dict{String, Any}(),
) -> String
Replace placeholders in `template`, using some default replacements based on the
`pkg_template` and additional ones in `view`. `template` is not modified.
"""
function substitute(
template::AbstractString,
pkg_template::Template;
@ -422,7 +418,7 @@ function substitute(
d = Dict{String, Any}(
"USER" => pkg_template.user,
"VERSION" => "$(v.major).$(v.minor)",
"DOCUMENTER" => any(isa(p, Documenter) for p in values(pkg_template.plugins)),
"DOCUMENTER" => any(map(p -> isa(p, Documenter), values(pkg_template.plugins))),
"CODECOV" => haskey(pkg_template.plugins, CodeCov),
"COVERALLS" => haskey(pkg_template.plugins, Coveralls),
)

View File

@ -16,7 +16,7 @@ const LICENSES = Dict(
Print the names of all available licenses.
"""
available_licenses(io::IO) = println(io, join(["$k: $v" for (k, v) in LICENSES], "\n"))
available_licenses(io::IO) = println(io, join(("$k: $v" for (k, v) in LICENSES), "\n"))
available_licenses() = available_licenses(STDOUT)
"""

View File

@ -71,8 +71,7 @@ abstract type GenericPlugin <: Plugin end
function show(io::IO, p::GenericPlugin)
spc = " "
t = split(string(typeof(p)), ".")[end]
println(io, "$t:")
println(io, "$(Base.datatype_name(typeof(p))):")
cfg = if isnull(p.src)
"None"
@ -245,7 +244,7 @@ badges(plugin::Plugin, user::AbstractString, pkg_name::AbstractString) = String[
function badges(plugin::GenericPlugin, user::AbstractString, pkg_name::AbstractString)
# Give higher priority to replacements defined in the plugin's view.
view = merge(Dict("USER" => user, "PKGNAME" => pkg_name), plugin.view)
return [substitute(format(badge), view) for badge in plugin.badges]
return map(b -> substitute(format(b), view), plugin.badges)
end
"""

View File

@ -62,12 +62,12 @@ function gen_plugin(
end
function show(io::IO, p::Documenter)
t = split(string(typeof(p)), ".")[end]
println(io, "$t:")
spc = " "
println(io, "$(Base.datatype_name(typeof(p))):")
n = length(p.assets)
s = n == 1 ? "" : "s"
print(io, " $n asset file$s")
print(io, "$spc→ $n asset file$s")
if n == 0
println(io)
else
@ -76,12 +76,12 @@ function show(io::IO, p::Documenter)
n = length(p.gitignore)
s = n == 1 ? "" : "s"
print(io, " $n gitignore entrie$s")
print(io, "$spc→ $n gitignore entrie$s")
n > 0 && print(io, ": $(join(map(g -> "\"$g\"", p.gitignore), ", "))")
end
function interactive(plugin_type::Type{<:Documenter})
plugin_name = split(string(plugin_type), ".")[end]
print("$plugin_name: Enter any Documenter asset files (separated by spaces) []: ")
t = Base.datatype_name(plugin_type)
print("$t: Enter any Documenter asset files (separated by spaces) []: ")
return plugin_type(; assets=String.(split(readline())))
end

View File

@ -92,7 +92,7 @@ create a template, you can use [`interactive_template`](@ref) instead.
requirements_dedup = collect(Set(requirements))
diff = length(requirements) - length(requirements_dedup)
names = [tokens[1] for tokens in split.(requirements_dedup)]
names = map(t -> first(t), split.(requirements_dedup))
if length(names) > length(Set(names))
throw(ArgumentError(
"requirements contains duplicate packages with conflicting versions"

View File

@ -61,7 +61,7 @@
end
@testset "Interactive package generation" begin
cfg = join(["$(p.first) $(p.second)" for p in gitconfig], "\n")
cfg = join(("$k $v" for (k, v) in gitconfig), "\n")
write(STDIN.buffer, "$me\n\n\r\n\n\n\n$cfg\n\nd")
generate_interactive(test_pkg)
@test isdir(Pkg.dir(test_pkg))

View File

@ -138,7 +138,7 @@ end
License: MIT ($(gitconfig["user.name"]) $(Dates.year(now())))
Package directory: $pkgdir
Precompilation enabled: Yes
Minimum Julia version: v$VERSION
Minimum Julia version: v$(PkgTemplates.version_floor())
0 package requirements
Git configuration options:
github.user = $(gitconfig["github.user"])
@ -167,7 +167,7 @@ end
License: None
Package directory: $pkgdir
Precompilation enabled: Yes
Minimum Julia version: v$VERSION
Minimum Julia version: v$(PkgTemplates.version_floor())
2 package requirements: Bar, Foo
Git configuration options:
github.user = $(gitconfig["github.user"])
@ -288,7 +288,7 @@ end
@test isfile(Pkg.dir(test_pkg, "test", "runtests.jl"))
repo = LibGit2.GitRepo(Pkg.dir(test_pkg))
remote = LibGit2.get(LibGit2.GitRemote, repo, "origin")
branches = [LibGit2.shortname(branch[1]) for branch in LibGit2.GitBranchIter(repo)]
branches = map(b -> LibGit2.shortname(first(b)), LibGit2.GitBranchIter(repo))
@test LibGit2.getconfig(repo, "user.name", "") == gitconfig["user.name"]
# Note: This test will fail on your system if you've configured Git
# to replace all HTTPS URLs with SSH.
@ -334,7 +334,7 @@ end
@test isfile(Pkg.dir(test_pkg, "docs", "src", "index.md"))
repo = LibGit2.GitRepo(Pkg.dir(test_pkg))
@test LibGit2.getconfig(repo, "user.name", "") == gitconfig["user.name"]
branches = [LibGit2.shortname(branch[1]) for branch in LibGit2.GitBranchIter(repo)]
branches = map(b -> LibGit2.shortname(first(b)), LibGit2.GitBranchIter(repo))
@test in("gh-pages", branches)
@test !LibGit2.isdirty(repo)
rm(Pkg.dir(test_pkg); recursive=true)