2019-02-05 17:31:51 +00:00
|
|
|
const DEFAULTS_DIR = normpath(joinpath(@__DIR__, "..", "defaults"))
|
|
|
|
|
|
|
|
abstract type BasicPlugin <: Plugin end
|
|
|
|
|
|
|
|
default_file(paths::AbstractString...) = joinpath(DEFAULTS_DIR, paths...)
|
|
|
|
|
2017-08-17 22:06:05 +00:00
|
|
|
"""
|
2019-02-05 17:31:51 +00:00
|
|
|
view(::Plugin, ::Template, pkg::AbstractString) -> Dict{String}
|
2017-08-21 21:19:40 +00:00
|
|
|
|
2019-02-05 17:31:51 +00:00
|
|
|
Return extra string substitutions to be made for this plugin.
|
|
|
|
"""
|
|
|
|
view(::Plugin, ::Template, ::AbstractString) = Dict{String, Any}()
|
2017-08-17 22:06:05 +00:00
|
|
|
|
|
|
|
"""
|
2019-02-05 17:31:51 +00:00
|
|
|
gitignore(::Plugin) -> Vector{String}
|
2017-08-17 06:57:58 +00:00
|
|
|
|
2019-02-05 17:31:51 +00:00
|
|
|
Return patterns that should be added to `.gitignore`.
|
|
|
|
"""
|
|
|
|
gitignore(::Plugin) = String[]
|
2017-12-01 17:33:57 +00:00
|
|
|
|
2019-02-05 17:31:51 +00:00
|
|
|
"""
|
|
|
|
badges(::Plugin) -> Union{Badge, Vector{Badge}}
|
2017-12-01 17:33:57 +00:00
|
|
|
|
2019-02-05 17:31:51 +00:00
|
|
|
Return a list of [`Badge`](@ref)s, or just one, to be added to `README.md`.
|
|
|
|
"""
|
|
|
|
badges(::Plugin) = Badge[]
|
2017-12-01 17:33:57 +00:00
|
|
|
|
2017-08-17 06:57:58 +00:00
|
|
|
"""
|
2019-02-05 17:31:51 +00:00
|
|
|
source(::BasicPlugin) -> Union{String, Nothing}
|
2017-08-22 16:25:00 +00:00
|
|
|
|
2019-02-05 17:31:51 +00:00
|
|
|
Return the path to a plugin's configuration file template, or `nothing` to indicate no file.
|
|
|
|
"""
|
|
|
|
source(::BasicPlugin) = nothing
|
2017-08-17 22:06:05 +00:00
|
|
|
|
2019-02-05 17:31:51 +00:00
|
|
|
"""
|
|
|
|
destination(::BasicPlugin) -> String
|
2017-08-22 16:25:00 +00:00
|
|
|
|
2019-02-05 17:31:51 +00:00
|
|
|
Return the destination, relative to the package root, of a plugin's configuration file.
|
2017-08-17 22:06:05 +00:00
|
|
|
"""
|
2019-02-05 17:31:51 +00:00
|
|
|
function destination end
|
2017-08-17 06:57:58 +00:00
|
|
|
|
2017-08-18 04:06:15 +00:00
|
|
|
"""
|
|
|
|
Badge(hover::AbstractString, image::AbstractString, link::AbstractString) -> Badge
|
|
|
|
|
2019-02-05 17:31:51 +00:00
|
|
|
Container for Markdown badge data.
|
|
|
|
Each argument can contain placeholders.
|
2017-08-18 04:06:15 +00:00
|
|
|
|
2019-02-05 17:31:51 +00:00
|
|
|
## Arguments
|
2017-08-18 04:06:15 +00:00
|
|
|
* `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.
|
|
|
|
"""
|
2018-12-20 19:21:17 +00:00
|
|
|
struct Badge
|
|
|
|
hover::String
|
|
|
|
image::String
|
|
|
|
link::String
|
2017-08-18 04:06:15 +00:00
|
|
|
end
|
|
|
|
|
2019-02-05 17:31:51 +00:00
|
|
|
Base.string(b::Badge) = "[)]($(b.link))"
|
2017-08-18 04:06:15 +00:00
|
|
|
|
2019-02-05 17:31:51 +00:00
|
|
|
# Format a plugin's badges as a list of strings, with all substitutions applied.
|
|
|
|
function badges(p::Plugin, t::Template, pkg_name::AbstractString)
|
|
|
|
bs = badges(p)
|
|
|
|
bs isa Vector || (bs = [bs])
|
|
|
|
bs = map(string, bs)
|
|
|
|
# TODO render
|
|
|
|
end
|
2017-08-18 04:06:15 +00:00
|
|
|
|
2017-08-17 06:57:58 +00:00
|
|
|
"""
|
2019-02-05 17:31:51 +00:00
|
|
|
gen_plugin(p::Plugin, t::Template, pkg::AbstractString) -> Nothing
|
2017-08-17 06:57:58 +00:00
|
|
|
|
|
|
|
Generate any files associated with a plugin.
|
|
|
|
|
2019-02-05 17:31:51 +00:00
|
|
|
## Arguments
|
2018-09-28 20:30:10 +00:00
|
|
|
* `p::Plugin`: Plugin whose files are being generated.
|
|
|
|
* `t::Template`: Template configuration.
|
2019-02-05 17:31:51 +00:00
|
|
|
* `pkg::AbstractString`: Name of the package.
|
|
|
|
"""
|
|
|
|
gen_plugin(::Plugin, ::Template, ::AbstractString) = nothing
|
|
|
|
|
|
|
|
function gen_plugin(p::BasicPlugin, t::Template, pkg::AbstractString)
|
|
|
|
source(p) === nothing && return
|
|
|
|
text = render(source(p), view(p, t, pkg); tags=tags(p))
|
|
|
|
gen_file(joinpath(t.dir, pkg_name, destination(p)), text)
|
2017-08-17 22:06:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
"""
|
2019-02-05 17:31:51 +00:00
|
|
|
gen_file(file::AbstractString, text::AbstractString) -> Int
|
2017-08-17 22:06:05 +00:00
|
|
|
|
2019-02-05 17:31:51 +00:00
|
|
|
Create a new file containing some given text.
|
|
|
|
Trailing whitespace is removed, and the file will end with a newline.
|
|
|
|
"""
|
|
|
|
function gen_file(file::AbstractString, text::AbstractString)
|
|
|
|
mkpath(dirname(file))
|
|
|
|
text = join(map(rstrip, split(text, "\n")), "\n")
|
|
|
|
endswith(text , "\n") || (text *= "\n")
|
|
|
|
write(file, text)
|
|
|
|
end
|
2017-08-17 22:06:05 +00:00
|
|
|
|
2019-02-05 17:31:51 +00:00
|
|
|
render_file(file::AbstractString, view, tags) = render_text(read(file, String), view, tags)
|
2017-08-17 22:06:05 +00:00
|
|
|
|
2019-02-05 17:31:51 +00:00
|
|
|
render_text(text::AbstractString, view, tags) = render(text, view; tags=tags)
|
2017-08-17 22:06:05 +00:00
|
|
|
|
2019-02-05 17:31:51 +00:00
|
|
|
function render_badges(p::BasicPlugin, t::Template, pkg::AbstractString)
|
2017-08-17 06:57:58 +00:00
|
|
|
end
|
2017-08-21 19:53:00 +00:00
|
|
|
|
2019-02-05 17:31:51 +00:00
|
|
|
function render_plugin(p::BasicPlugin, t::Template, pkg::AbstractString)
|
|
|
|
render_file(source(p), view(p, t, pkg), tags(p))
|
2017-08-21 19:53:00 +00:00
|
|
|
end
|
2019-02-05 17:31:51 +00:00
|
|
|
|
|
|
|
include(joinpath("plugins", "essentials.jl"))
|
|
|
|
include(joinpath("plugins", "coverage.jl"))
|
|
|
|
include(joinpath("plugins", "ci.jl"))
|
|
|
|
include(joinpath("plugins", "citation.jl"))
|
|
|
|
include(joinpath("plugins", "documenter.jl"))
|
|
|
|
|
|
|
|
const BADGE_ORDER = [
|
|
|
|
Documenter{GitLabCI},
|
|
|
|
Documenter{TravisCI},
|
|
|
|
TravisCI,
|
|
|
|
AppVeyor,
|
|
|
|
GitLabCI,
|
|
|
|
Codecov,
|
|
|
|
Coveralls,
|
|
|
|
]
|