From 75c7875899bdab4b05600f4766e2fbc70631e1ad Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Tue, 12 Dec 2017 15:15:55 +0000 Subject: [PATCH] Misc style changes --- src/generate.jl | 22 +++++++++------------- src/licenses.jl | 2 +- src/plugin.jl | 5 ++--- src/plugins/documenter.jl | 12 ++++++------ src/template.jl | 2 +- test/interactive/interactive.jl | 2 +- test/tests.jl | 8 ++++---- 7 files changed, 24 insertions(+), 29 deletions(-) diff --git a/src/generate.jl b/src/generate.jl index 4c3632c..9f18483 100644 --- a/src/generate.jl +++ b/src/generate.jl @@ -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), ) diff --git a/src/licenses.jl b/src/licenses.jl index 27e86b5..3e26478 100644 --- a/src/licenses.jl +++ b/src/licenses.jl @@ -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) """ diff --git a/src/plugin.jl b/src/plugin.jl index 05b8b05..87a74f3 100644 --- a/src/plugin.jl +++ b/src/plugin.jl @@ -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 """ diff --git a/src/plugins/documenter.jl b/src/plugins/documenter.jl index 714ebe4..76560ce 100644 --- a/src/plugins/documenter.jl +++ b/src/plugins/documenter.jl @@ -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 diff --git a/src/template.jl b/src/template.jl index 7253343..7695061 100644 --- a/src/template.jl +++ b/src/template.jl @@ -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" diff --git a/test/interactive/interactive.jl b/test/interactive/interactive.jl index 41aa5d4..51ec178 100644 --- a/test/interactive/interactive.jl +++ b/test/interactive/interactive.jl @@ -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)) diff --git a/test/tests.jl b/test/tests.jl index 25f03f0..9f7c176 100644 --- a/test/tests.jl +++ b/test/tests.jl @@ -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)