commit
38944a8a17
@ -24,7 +24,8 @@ export
|
||||
TravisCI,
|
||||
GitLabCI,
|
||||
Codecov,
|
||||
Coveralls
|
||||
Coveralls,
|
||||
Citation
|
||||
|
||||
"""
|
||||
A plugin to be added to a [`Template`](@ref), which adds some functionality or integration.
|
||||
@ -44,6 +45,7 @@ include(joinpath("plugins", "travisci.jl"))
|
||||
include(joinpath("plugins", "gitlabci.jl"))
|
||||
include(joinpath("plugins", "githubpages.jl"))
|
||||
include(joinpath("plugins", "gitlabpages.jl"))
|
||||
include(joinpath("plugins", "citation.jl"))
|
||||
|
||||
const DEFAULTS_DIR = normpath(joinpath(@__DIR__, "..", "defaults"))
|
||||
const BADGE_ORDER = [GitHubPages, GitLabPages, TravisCI, AppVeyor, GitLabCI, Codecov, Coveralls]
|
||||
|
@ -198,6 +198,10 @@ function gen_readme(pkg_dir::AbstractString, t::Template)
|
||||
"\n",
|
||||
)
|
||||
end
|
||||
if haskey(t.plugins, Citation) && t.plugins[Citation].readme_section
|
||||
text *= "\n## Citing\n\nSee `CITATION.bib` for the relevant reference(s).\n"
|
||||
end
|
||||
|
||||
|
||||
gen_file(joinpath(pkg_dir, "README.md"), text)
|
||||
return ["README.md"]
|
||||
|
45
src/plugins/citation.jl
Normal file
45
src/plugins/citation.jl
Normal file
@ -0,0 +1,45 @@
|
||||
"""
|
||||
Citation(; readme_section::Bool=false)
|
||||
|
||||
Add `Citation` to a template's plugins to add a `CITATION.bib` file to
|
||||
generated repositories, and an appropriate section in the README.
|
||||
|
||||
# Keyword Arguments:
|
||||
* `readme_section::Bool=false`: whether to add a section in the readme pointing to `CITATION.bib`.
|
||||
"""
|
||||
struct Citation <: GenericPlugin
|
||||
gitignore::Vector{AbstractString}
|
||||
src::Union{String, Nothing}
|
||||
dest::AbstractString
|
||||
badges::Vector{Badge}
|
||||
view::Dict{String, Any}
|
||||
readme_section::Bool
|
||||
function Citation(; readme_section::Bool=false)
|
||||
new(
|
||||
[],
|
||||
nothing,
|
||||
"CITATION.bib",
|
||||
[],
|
||||
Dict{String, Any}(),
|
||||
readme_section,
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
interactive(::Type{Citation}) = interactive(Citation; readme_section=false)
|
||||
|
||||
function gen_plugin(p::Citation, t::Template, pkg_name::AbstractString)
|
||||
pkg_dir = joinpath(t.dir, pkg_name)
|
||||
text = """
|
||||
@misc{$pkg_name.jl,
|
||||
\tauthor = {$(t.authors)},
|
||||
\ttitle = {{$(pkg_name).jl}},
|
||||
\turl = {https://$(t.host)/$(t.user)/$(pkg_name).jl},
|
||||
\tversion = {v0.1.0},
|
||||
\tyear = {$(year(today()))},
|
||||
\tmonth = {$(month(today()))}
|
||||
}
|
||||
"""
|
||||
gen_file(joinpath(pkg_dir, "CITATION.bib"), text)
|
||||
return ["CITATION.bib"]
|
||||
end
|
48
test/plugins/citation.jl
Normal file
48
test/plugins/citation.jl
Normal file
@ -0,0 +1,48 @@
|
||||
t = Template(; user=me)
|
||||
pkg_dir = joinpath(t.dir, test_pkg)
|
||||
|
||||
@testset "CITATION" begin
|
||||
@testset "Plugin creation" begin
|
||||
p = Citation()
|
||||
@test isempty(p.gitignore)
|
||||
@test p.dest == "CITATION.bib"
|
||||
@test isempty(p.badges)
|
||||
@test isempty(p.view)
|
||||
@test !p.readme_section
|
||||
p = Citation(; readme_section=true)
|
||||
@test p.readme_section
|
||||
end
|
||||
|
||||
@testset "File generation" begin
|
||||
p = Citation()
|
||||
@test gen_plugin(p, t, test_pkg) == ["CITATION.bib"]
|
||||
@test isfile(joinpath(pkg_dir, "CITATION.bib"))
|
||||
citation = read(joinpath(pkg_dir, "CITATION.bib"), String)
|
||||
|
||||
@test occursin("@misc", citation)
|
||||
@test occursin("$(t.authors)", citation)
|
||||
@test occursin("v0.1.0", citation)
|
||||
end
|
||||
|
||||
@testset "Readme untouched" begin
|
||||
p = Citation(; readme_section=false)
|
||||
t.plugins[Citation] = p
|
||||
isdir(pkg_dir) && rm(pkg_dir; recursive=true)
|
||||
generate(test_pkg, t, git=false)
|
||||
readme = read(joinpath(pkg_dir, "README.md"), String)
|
||||
@test !occursin("## Citing", readme)
|
||||
@test !occursin("CITATION.bib", readme)
|
||||
end
|
||||
|
||||
@testset "Readme modification" begin
|
||||
p = Citation(; readme_section=true)
|
||||
t.plugins[Citation] = p
|
||||
isdir(pkg_dir) && rm(pkg_dir; recursive=true)
|
||||
generate(test_pkg, t, git=false)
|
||||
readme = read(joinpath(pkg_dir, "README.md"), String)
|
||||
@test occursin("## Citing", readme)
|
||||
@test occursin("CITATION.bib", readme)
|
||||
end
|
||||
end
|
||||
|
||||
rm(pkg_dir; recursive=true)
|
@ -442,6 +442,7 @@ end
|
||||
include(joinpath("plugins", "coveralls.jl"))
|
||||
include(joinpath("plugins", "githubpages.jl"))
|
||||
include(joinpath("plugins", "gitlabpages.jl"))
|
||||
include(joinpath("plugins", "citation.jl"))
|
||||
end
|
||||
|
||||
@testset "Documenter add kwargs" begin
|
||||
|
Loading…
Reference in New Issue
Block a user