From 5eb911c35a2b9c7b5faccad3369357bb3855fe25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathieu=20Besan=C3=A7on?= Date: Tue, 14 May 2019 17:47:23 +0200 Subject: [PATCH] citation --- src/PkgTemplates.jl | 1 + src/generate.jl | 36 +++++++--------------------------- src/plugins/citation.jl | 43 +++++++++++++++++++++++++++++++++++++++++ src/template.jl | 8 -------- 4 files changed, 51 insertions(+), 37 deletions(-) create mode 100644 src/plugins/citation.jl diff --git a/src/PkgTemplates.jl b/src/PkgTemplates.jl index eda0742..3972653 100644 --- a/src/PkgTemplates.jl +++ b/src/PkgTemplates.jl @@ -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] diff --git a/src/generate.jl b/src/generate.jl index a79e100..2c07f51 100644 --- a/src/generate.jl +++ b/src/generate.jl @@ -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 diff --git a/src/plugins/citation.jl b/src/plugins/citation.jl new file mode 100644 index 0000000..64f4957 --- /dev/null +++ b/src/plugins/citation.jl @@ -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 diff --git a/src/template.jl b/src/template.jl index 0068a8a..1dab0e6 100644 --- a/src/template.jl +++ b/src/template.jl @@ -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))