From 9addf49fe6ef1574ac26174e77aa8218f7555ddf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathieu=20Besan=C3=A7on?= Date: Tue, 14 May 2019 16:36:40 +0200 Subject: [PATCH] finish citation --- src/generate.jl | 30 ++++++++++++++++++++++++++++++ src/template.jl | 10 +++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/generate.jl b/src/generate.jl index d78ffa8..c29d46b 100644 --- a/src/generate.jl +++ b/src/generate.jl @@ -63,6 +63,7 @@ function generate( gen_require(pkg_dir, t), gen_readme(pkg_dir, t), gen_license(pkg_dir, t), + gen_citation(pkg_dir, t), vcat(map(p -> gen_plugin(p, t, pkg), values(t.plugins))...), ) @@ -271,6 +272,35 @@ 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_license(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/template.jl b/src/template.jl index 24d4435..0068a8a 100644 --- a/src/template.jl +++ b/src/template.jl @@ -86,7 +86,7 @@ struct Template @warn "Plugin list contained duplicates, only the last of each type was kept" end - new(user, host, license, authors, dir, julia_version, ssh, manifest, plugin_dict) + new(user, host, license, authors, dir, julia_version, ssh, manifest, citation, plugin_dict) end end @@ -109,6 +109,7 @@ 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) @@ -214,6 +215,13 @@ 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))