diff --git a/src/plugin.jl b/src/plugin.jl index 9645290..91d7c98 100644 --- a/src/plugin.jl +++ b/src/plugin.jl @@ -10,10 +10,9 @@ Generic plugins are plugins that add any number of patterns to the generated pac to an empty string, there should be a default file in `defaults` that will be copied. * `dest::AbstractString`: Path to the generated file, relative to the root of the generated package repository. -* `badges::Vector{Vector{AbstractString}}`: Array of arrays containing information to - create a Markdown-formatted badge from the plugin. Each entry is of the form - `[hover_text, image_url, link_url]`. Entries will be run through [`substitute`](@ref), - so they may contain placeholder values. +* `badges::Vector{Badge}`: Array of [`Badge`](@ref)s containing information used to + create Markdown-formatted badges from the plugin. Entries will be run through + [`substitute`](@ref), so they may contain placeholder values. * `view::Dict{String, Any}`: Additional substitutions to make in both the plugin's badges and its associated file. See [`substitute`](@ref) for details. @@ -23,7 +22,7 @@ Generic plugins are plugins that add any number of patterns to the generated pac gitignore::Vector{AbstractString} src::Nullable{AbstractString} dest::AbstractString - badges::Vector{Vector{AbstractString}} + badges::Vector{Badge} view::Dict{String, Any} function MyPlugin(; config_file::Union{AbstractString, Void}="") @@ -41,11 +40,11 @@ Generic plugins are plugins that add any number of patterns to the generated pac config_file, ".mypugin.yml", [ - [ + Badge( "My Plugin", "https://myplugin.com/badge-{{YEAR}}.png", "https://myplugin.com/{{USER}}/{{PKGNAME}}.jl", - ], + ), ], Dict{String, Any}("YEAR" => Dates.year(Dates.now())), ) @@ -100,11 +99,11 @@ choose. ) if plugin.lucky return [ - badge( + format(Badge( "You got lucky!", "https://myplugin.com/badge.png", "https://myplugin.com/\$user/\$pkg_name.jl", - ), + )), ] else return String[] @@ -115,10 +114,36 @@ end This plugin doesn't do much, but it demonstrates how [`gen_plugin`](@ref) and [`badges`](@ref) can be implemented using [`substitute`](@ref), [`gen_file`](@ref), -and [`badge`](@ref). +[`Badge`](@ref), and [`format`](@ref). """ abstract type CustomPlugin <: Plugin end +""" + Badge(hover::AbstractString, image::AbstractString, link::AbstractString) -> Badge + +A `Badge` contains the data necessary to generate a Markdown badge. + +# Arguments +* `hover::AbstractString`: Text to appear when the mouse is hovered over the badge. +* `image::AbstractString`: URL to the image to display. +* `link::AbstractString`: URL to go to upon clicking the badge. +""" +@auto_hash_equals struct Badge + hover::AbstractString + image::AbstractString + link::AbstractString + function Badge(hover::AbstractString, image::AbstractString, link::AbstractString) + new(hover, image, link) + end +end + +""" + format(b::Badge) + +Return `badge`'s data formatted as a Markdown string. +""" +format(b::Badge) = "[![$(b.hover)]($(b.image))]($(b.link))" + """ gen_plugin(plugin::Plugin, template::Template, pkg_name::AbstractString) -> Vector{String} @@ -165,19 +190,5 @@ 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 [badge([substitute(part, view) for part in b]...) for b in plugin.badges] -end - -""" - badge(hover::AbstractString, image::AbstractString, image::AbstractString) -> String - -Format a single Markdown badge. - -# Arguments -* `hover::AbstractString`: Text to appear when the mouse is hovered over the badge. -* `image::AbstractString`: URL to the image to display. -* `link::AbstractString`: URL to go to upon clicking the badge. -""" -function badge(hover::AbstractString, image::AbstractString, link::AbstractString) - return "[![$hover]($image)]($link)" + return [substitute(format(badge), view) for badge in plugin.badges] end diff --git a/src/plugins/appveyor.jl b/src/plugins/appveyor.jl index acc9acb..f38104a 100644 --- a/src/plugins/appveyor.jl +++ b/src/plugins/appveyor.jl @@ -12,7 +12,7 @@ generated repositories, and an appropriate badge to the README. gitignore::Vector{AbstractString} src::Nullable{AbstractString} dest::AbstractString - badges::Vector{Vector{AbstractString}} + badges::Vector{Badge} view::Dict{String, Any} function AppVeyor(; config_file::Union{AbstractString, Void}="") @@ -28,11 +28,11 @@ generated repositories, and an appropriate badge to the README. config_file, ".appveyor.yml", [ - [ + Badge( "Build Status", "https://ci.appveyor.com/api/projects/status/github/{{USER}}/{{PKGNAME}}.jl?svg=true", "https://ci.appveyor.com/project/{{USER}}/{{PKGNAME}}-jl", - ], + ) ], Dict{String, Any}(), ) diff --git a/src/plugins/codecov.jl b/src/plugins/codecov.jl index d09f791..3e56331 100644 --- a/src/plugins/codecov.jl +++ b/src/plugins/codecov.jl @@ -13,7 +13,7 @@ generated repositories, and an appropriate badge to the README. Also updates the gitignore::Vector{AbstractString} src::Nullable{AbstractString} dest::AbstractString - badges::Vector{Vector{AbstractString}} + badges::Vector{Badge} view::Dict{String, Any} function CodeCov(; config_file::Union{AbstractString, Void}="") @@ -29,11 +29,11 @@ generated repositories, and an appropriate badge to the README. Also updates the config_file, ".codecov.yml", [ - [ + Badge( "CodeCov", "https://codecov.io/gh/{{USER}}/{{PKGNAME}}.jl/branch/master/graph/badge.svg", "https://codecov.io/gh/{{USER}}/{{PKGNAME}}.jl", - ], + ), ], Dict{String, Any}(), ) diff --git a/src/plugins/coveralls.jl b/src/plugins/coveralls.jl index f8e5566..e506d4f 100644 --- a/src/plugins/coveralls.jl +++ b/src/plugins/coveralls.jl @@ -13,7 +13,7 @@ file to generated repositories, and an appropriate badge to the README. Also upd gitignore::Vector{AbstractString} src::Nullable{AbstractString} dest::AbstractString - badges::Vector{Vector{AbstractString}} + badges::Vector{Badge} view::Dict{String, Any} function Coveralls(; config_file::Union{AbstractString, Void}=nothing) @@ -25,11 +25,11 @@ file to generated repositories, and an appropriate badge to the README. Also upd config_file, ".coveralls.yml", [ - [ + Badge( "Coveralls", "https://coveralls.io/repos/github/{{USER}}/{{PKGNAME}}.jl/badge.svg?branch=master", "https://coveralls.io/github/{{USER}}/{{PKGNAME}}.jl?branch=master", - ], + ), ], Dict{String, Any}(), ) diff --git a/src/plugins/githubpages.jl b/src/plugins/githubpages.jl index a23e143..2c85695 100644 --- a/src/plugins/githubpages.jl +++ b/src/plugins/githubpages.jl @@ -25,8 +25,16 @@ end function badges(_::GitHubPages, user::AbstractString, pkg_name::AbstractString) return [ - badge("Stable", "https://img.shields.io/badge/docs-stable-blue.svg", "https://$user.github.io/$pkg_name.jl/stable") - badge("Latest", "https://img.shields.io/badge/docs-latest-blue.svg", "https://$user.github.io/$pkg_name.jl/latest") + format(Badge( + "Stable", + "https://img.shields.io/badge/docs-stable-blue.svg", + "https://$user.github.io/$pkg_name.jl/stable" + )), + format(Badge( + "Latest", + "https://img.shields.io/badge/docs-latest-blue.svg", + "https://$user.github.io/$pkg_name.jl/latest" + )), ] end diff --git a/src/plugins/travisci.jl b/src/plugins/travisci.jl index af29259..d7185ec 100644 --- a/src/plugins/travisci.jl +++ b/src/plugins/travisci.jl @@ -12,7 +12,7 @@ generated repositories, and an appropriate badge to the README. gitignore::Vector{AbstractString} src::Nullable{AbstractString} dest::AbstractString - badges::Vector{Vector{AbstractString}} + badges::Vector{Badge} view::Dict{String, Any} function TravisCI(; config_file::Union{AbstractString, Void}="") @@ -28,11 +28,11 @@ generated repositories, and an appropriate badge to the README. config_file, ".travis.yml", [ - [ + Badge( "Build Status", "https://travis-ci.org/{{USER}}/{{PKGNAME}}.jl.svg?branch=master", "https://travis-ci.org/{{USER}}/{{PKGNAME}}.jl", - ], + ), ], Dict{String, Any}(), )