citation
This commit is contained in:
parent
d6c66e6ebb
commit
5eb911c35a
@ -44,6 +44,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]
|
||||
|
@ -216,8 +216,15 @@ function gen_readme(pkg_dir::AbstractString, t::Template)
|
||||
badges(t.plugins[plugin_type], t.user, pkg),
|
||||
"\n",
|
||||
)
|
||||
if plugin_type <: Citation
|
||||
c = t.plugins[plugin_type]
|
||||
if c.readme_section
|
||||
text *= "## Citing\n\nSee `CITATION.bib` for the relevant reference(s)\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
gen_file(joinpath(pkg_dir, "README.md"), text)
|
||||
return ["README.md"]
|
||||
end
|
||||
@ -272,35 +279,6 @@ function gen_license(pkg_dir::AbstractString, t::Template)
|
||||
return ["LICENSE"]
|
||||
end
|
||||
|
||||
"""
|
||||
gen_citation(pkg_dir::AbstractString, t::Template) -> Vector{String}
|
||||
|
||||
Create a CITATION.bib in `pkg_dir`.
|
||||
|
||||
# Arguments
|
||||
* `pkg_dir::AbstractString`: The directory in which the files will be generated.
|
||||
* `t::Template`: The template whose CITATION.bib file we are generating.
|
||||
|
||||
Returns an array of generated file/directory names.
|
||||
"""
|
||||
function gen_citation(pkg_dir::AbstractString, t::Template)
|
||||
if !t.citation
|
||||
return String[]
|
||||
end
|
||||
pkg = basename(pkg_dir)
|
||||
text = "@misc{$pkg,\n"
|
||||
text *= "\tauthor = {{$(t.author)}},\n"
|
||||
text *= "\ttitle = {{$(pkg).jl}},\n"
|
||||
text *= "\turl = {https://$(t.host)/$(t.user)/$(pkg).jl},\n"
|
||||
text *= "\tversion = {v0.0.1},\n"
|
||||
text *= "\tyear = {$(year(today()))},\n"
|
||||
text *= "\tmonth = {$(month(today()))},\n"
|
||||
text *= "}"
|
||||
|
||||
gen_file(joinpath(pkg_dir, "CITATION.bib"), text)
|
||||
return ["CITATION.bib"]
|
||||
end
|
||||
|
||||
"""
|
||||
gen_file(file::AbstractString, text::AbstractString) -> Int
|
||||
|
||||
|
43
src/plugins/citation.jl
Normal file
43
src/plugins/citation.jl
Normal file
@ -0,0 +1,43 @@
|
||||
"""
|
||||
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,\n"
|
||||
text *= "\tauthor = {{$(t.author)}},\n"
|
||||
text *= "\ttitle = {{$(pkg_name).jl}},\n"
|
||||
text *= "\turl = {https://$(t.host)/$(t.user)/$(pkg_name).jl},\n"
|
||||
text *= "\tversion = {v0.0.1},\n"
|
||||
text *= "\tyear = {$(year(today()))},\n"
|
||||
text *= "\tmonth = {$(month(today()))},\n"
|
||||
text *= "}"
|
||||
gen_file(joinpath(pkg_dir, "CITATION.bib"), text)
|
||||
return ["CITATION.bib"]
|
||||
end
|
@ -109,7 +109,6 @@ function Base.show(io::IO, t::Template)
|
||||
println(io, spc, "→ Minimum Julia version: v", version_floor(t.julia_version))
|
||||
println(io, spc, "→ SSH remote: ", t.ssh ? "Yes" : "No")
|
||||
println(io, spc, "→ Commit Manifest.toml: ", t.manifest ? "Yes" : "No")
|
||||
println(io, spc, "→ Add CITATION.bib: ", t.citation ? "Yes" : "No")
|
||||
|
||||
print(io, spc, "→ Plugins:")
|
||||
if isempty(t.plugins)
|
||||
@ -215,13 +214,6 @@ function interactive_template(; git::Bool=true, fast::Bool=false)
|
||||
uppercase(readline()) in ["Y", "YES", "T", "TRUE"]
|
||||
end
|
||||
|
||||
kwargs[:citation] = if fast
|
||||
false
|
||||
else
|
||||
print("Add CITATION.bib? [no]: ")
|
||||
uppercase(readline()) in ["Y", "YES", "T", "TRUE"]
|
||||
end
|
||||
|
||||
println("Plugins:")
|
||||
# Only include plugin types which have an `interactive` method.
|
||||
plugin_types = filter(t -> hasmethod(interactive, (Type{t},)), fetch(plugin_types))
|
||||
|
Loading…
Reference in New Issue
Block a user