diff --git a/defaults/CITATION.bib b/defaults/CITATION.bib index b49e5ea9..6579e314 100644 --- a/defaults/CITATION.bib +++ b/defaults/CITATION.bib @@ -1,8 +1,8 @@ -@misc{<>.jl, - author = {<>}, - title = {<>.jl}, - url = {<>}, +@misc{<<&PKG>>.jl, + author = {<<&AUTHORS>>}, + title = {<<&PKG>>.jl}, + url = {<<&URL>>}, version = {v0.1.0}, - year = {<>}, - month = {<>} + year = {<<&YEAR>>}, + month = {<<&MONTH>>} } diff --git a/defaults/README.md b/defaults/README.md index 230e5a50..980a7bb2 100644 --- a/defaults/README.md +++ b/defaults/README.md @@ -1,8 +1,8 @@ -# {{PKG}}{{#HAS_INLINE_BADGES}} {{#BADGES}}{{.}} {{/BADGES}}{{/HAS_INLINE_BADGES}} +# {{{PKG}}}{{#HAS_INLINE_BADGES}} {{#BADGES}}{{{.}}} {{/BADGES}}{{/HAS_INLINE_BADGES}} {{^HAS_INLINE_BADGES}} {{#BADGES}} -{{.}} +{{{.}}} {{/BADGES}} {{/HAS_INLINE_BADGES}} {{#HAS_CITATION}} diff --git a/defaults/appveyor.yml b/defaults/appveyor.yml index 2d4682bb..4535a46e 100644 --- a/defaults/appveyor.yml +++ b/defaults/appveyor.yml @@ -2,17 +2,17 @@ environment: matrix: {{#VERSIONS}} - - julia_version: {{.}} + - julia_version: {{{.}}} {{/VERSIONS}} platform: {{#PLATFORMS}} - - {{.}} + - {{{.}}} {{/PLATFORMS}} {{#HAS_ALLOW_FAILURES}} matrix: allow_failures: {{#ALLOW_FAILURES}} - - julia_version: {{.}} + - julia_version: {{{.}}} {{/ALLOW_FAILURES}} {{/HAS_ALLOW_FAILURES}} branches: diff --git a/defaults/cirrus.yml b/defaults/cirrus.yml index 1e182e2e..8c296cc9 100644 --- a/defaults/cirrus.yml +++ b/defaults/cirrus.yml @@ -1,10 +1,10 @@ freebsd_instance: - image: {{IMAGE}} + image: {{{IMAGE}}} task: name: FreeBSD env: {{#VERSIONS}} - JULIA_VERSION: {{.}} + JULIA_VERSION: {{{.}}} {{/VERSIONS}} install_script: - sh -c "$(fetch https://raw.githubusercontent.com/ararslan/CirrusCI.jl/master/bin/install.sh -o -)" diff --git a/defaults/gitlab-ci.yml b/defaults/gitlab-ci.yml index d9f965d5..774b2180 100644 --- a/defaults/gitlab-ci.yml +++ b/defaults/gitlab-ci.yml @@ -18,16 +18,16 @@ @printf "Test coverage %.2f%%\n" 100c / t;' {{/HAS_COVERAGE}} {{#VERSIONS}} -Julia {{.}}: - image: julia:{{.}} +Julia {{{.}}}: + image: julia:{{{.}}} <<: *script - {{#HAS_COVERAGE}} +{{#HAS_COVERAGE}} <<: *coverage - {{/HAS_COVERAGE}} +{{/HAS_COVERAGE}} {{/VERSIONS}} {{#HAS_DOCUMENTER}} pages: - image: julia:{{VERSION}} + image: julia:{{{VERSION}}} stage: deploy script: - julia --project=docs -e ' diff --git a/defaults/index.md b/defaults/index.md index e5e882f3..949e9c9c 100644 --- a/defaults/index.md +++ b/defaults/index.md @@ -1,8 +1,8 @@ -# {{PKG}} +# {{{PKG}}} ```@index ``` ```@autodocs -Modules = [{{PKG}}] +Modules = [{{{PKG}}}] ``` diff --git a/defaults/make.jl b/defaults/make.jl index 26dd48f8..366e5a8f 100644 --- a/defaults/make.jl +++ b/defaults/make.jl @@ -1,18 +1,18 @@ -using {{PKG}} +using {{{PKG}}} using Documenter makedocs(; - modules=[{{PKG}}], - authors="{{AUTHORS}}", - repo="https://{{REPO}}/blob/{commit}{path}#L{line}", - sitename="{{PKG}}.jl", + modules=[{{{PKG}}}], + authors="{{{AUTHORS}}}", + repo="https://{{{REPO}}}/blob/{commit}{path}#L{line}", + sitename="{{{PKG}}}.jl", format=Documenter.HTML(; {{#CANONICAL}} - canonical="{{CANONICAL}}", + canonical="{{{CANONICAL}}}", {{/CANONICAL}} assets={{^HAS_ASSETS}}String{{/HAS_ASSETS}}[{{^HAS_ASSETS}}],{{/HAS_ASSETS}} {{#ASSETS}} - "{{.}}", + "{{{.}}}", {{/ASSETS}} {{#HAS_ASSETS}} ], @@ -22,12 +22,12 @@ makedocs(; "Home" => "index.md", ], {{#MAKEDOCS_KWARGS}} - {{first}}={{second}}, + {{{first}}}={{{second}}}, {{/MAKEDOCS_KWARGS}} ) {{#HAS_DEPLOY}} deploydocs(; - repo="{{REPO}}", + repo="{{{REPO}}}", ) {{/HAS_DEPLOY}} diff --git a/defaults/runtests.jl b/defaults/runtests.jl index 072ffb37..7cc1ecbe 100644 --- a/defaults/runtests.jl +++ b/defaults/runtests.jl @@ -1,6 +1,6 @@ -using {{PKG}} +using {{{PKG}}} using Test -@testset "{{PKG}}.jl" begin +@testset "{{{PKG}}}.jl" begin # Write your tests here. end diff --git a/defaults/travis.yml b/defaults/travis.yml index 1100682d..accf0d2a 100644 --- a/defaults/travis.yml +++ b/defaults/travis.yml @@ -4,11 +4,11 @@ notifications: email: false julia: {{#VERSIONS}} - - {{.}} + - {{{.}}} {{/VERSIONS}} os: {{#OS}} - - {{.}} + - {{{.}}} {{/OS}} jobs: fast_finish: true @@ -16,19 +16,19 @@ jobs: allow_failures: {{/HAS_ALLOW_FAILURES}} {{#ALLOW_FAILURES}} - - julia: {{.}} + - julia: {{{.}}} {{/ALLOW_FAILURES}} {{#HAS_JOBS}} include: {{/HAS_JOBS}} {{#X86}} - - julia: {{JULIA}} - os: {{OS}} + - julia: {{{JULIA}}} + os: {{{OS}}} arch: x86 {{/X86}} {{#HAS_DOCUMENTER}} - stage: Documentation - julia: {{VERSION}} + julia: {{{VERSION}}} script: julia --project=docs -e ' using Pkg; Pkg.develop(PackageSpec(; path=pwd())); diff --git a/docs/src/user.md b/docs/src/user.md index c811086e..4c86cd06 100644 --- a/docs/src/user.md +++ b/docs/src/user.md @@ -75,10 +75,10 @@ If that's the case, a basic understanding of [Mustache](https://mustache.github. Here's an example template file: ``` -Hello, {{name}}. +Hello, {{{name}}}. {{#weather}} -It's {{weather}} outside. +It's {{{weather}}} outside. {{/weather}} {{^weather}} I don't know what the weather outside is. @@ -88,15 +88,15 @@ I don't know what the weather outside is. I have the following things: {{/has_things}} {{#things}} -- Here's a thing: {{.}} +- Here's a thing: {{{.}}} {{/things}} {{#people}} -- {{name}} is {{mood}} +- {{{name}}} is {{{mood}}} {{/people}} ``` -In the first section, `name` is a key, and its value replaces `{{name}}`. +In the first section, `name` is a key, and its value replaces `{{{name}}}`. In the second section, `weather`'s value may or may not exist. If it does exist, then "It's $weather outside" is printed. @@ -105,11 +105,16 @@ Mustache uses a notion of "truthiness" similar to Python or JavaScript, where va In the third section, `has_things`' value is printed if it's truthy. Then, if the `things` list is truthy (i.e. not empty), its values are each printed on their own line. -The reason that we have two separate keys is that `{{#things}}` iterates over the whole `things` list, even when there are no `{{.}}` placeholders, which would duplicate "I have the following things:" `n` times. +The reason that we have two separate keys is that `{{#things}}` iterates over the whole `things` list, even when there are no `{{{.}}}` placeholders, which would duplicate "I have the following things:" `n` times. -The fourth section iterates over the `people` list, but instead of using the `{{.}}` placeholder, we have `name` and `mood`, which are keys or fields of the list elements. +The fourth section iterates over the `people` list, but instead of using the `{{{.}}}` placeholder, we have `name` and `mood`, which are keys or fields of the list elements. Most types are supported here, including `Dict`s and structs. -`NamedTuple`s require you to use `{{:name}}` instead of the normal `{{name}}`, though. +`NamedTuple`s require you to use `{{{:name}}}` instead of the normal `{{{name}}}`, though. + +You might notice that some curlies are in groups of two (`{{key}}`), and some are in groups of three (`{{{key}}}`). +Whenever we want to subtitute in a value, using the triple curlies disables HTML escaping, which we rarely want for the types of files we're creating. +If you do want escaping, just use the double curlies. +And if you're using different delimiters, for example `<>`, use `<<&foo>>` to disable escaping. Assuming the following view: diff --git a/src/PkgTemplates.jl b/src/PkgTemplates.jl index d8a0312d..15173c88 100644 --- a/src/PkgTemplates.jl +++ b/src/PkgTemplates.jl @@ -9,7 +9,7 @@ using LibGit2: LibGit2, GitRemote using Pkg: Pkg, TOML, PackageSpec using REPL.TerminalMenus: MultiSelectMenu, RadioMenu, request -using Mustache: entityMap, render +using Mustache: render using Parameters: @with_kw_noshow export diff --git a/src/plugin.jl b/src/plugin.jl index 7d48e503..e76f4f04 100644 --- a/src/plugin.jl +++ b/src/plugin.jl @@ -167,7 +167,7 @@ Render a template file with the data in `view`. `tags` should be a tuple of two strings, which are the opening and closing delimiters, or `nothing` to use the default delimiters. """ function render_file(file::AbstractString, view::Dict{<:AbstractString}, tags) - render_text(read(file, String), view, tags) + return render_text(read(file, String), view, tags) end """ @@ -177,17 +177,7 @@ Render some text with the data in `view`. `tags` should be a tuple of two strings, which are the opening and closing delimiters, or `nothing` to use the default delimiters. """ function render_text(text::AbstractString, view::Dict{<:AbstractString}, tags=nothing) - saved = copy(entityMap) - empty!(entityMap) - return try - if tags === nothing - render(text, view) - else - render(text, view; tags=tags) - end - finally - append!(entityMap, saved) - end + return tags === nothing ? render(text, view) : render(text, view; tags=tags) end include(joinpath("plugins", "defaults.jl")) diff --git a/src/plugins/ci.jl b/src/plugins/ci.jl index 9628a1a2..be82caea 100644 --- a/src/plugins/ci.jl +++ b/src/plugins/ci.jl @@ -59,8 +59,8 @@ destination(::TravisCI) = ".travis.yml" badges(::TravisCI) = Badge( "Build Status", - "https://travis-ci.com/{{USER}}/{{PKG}}.jl.svg?branch=master", - "https://travis-ci.com/{{USER}}/{{PKG}}.jl", + "https://travis-ci.com/{{{USER}}}/{{{PKG}}}.jl.svg?branch=master", + "https://travis-ci.com/{{{USER}}}/{{{PKG}}}.jl", ) function view(p::TravisCI, t::Template, pkg::AbstractString) @@ -125,8 +125,8 @@ destination(::AppVeyor) = ".appveyor.yml" badges(::AppVeyor) = Badge( "Build Status", - "https://ci.appveyor.com/api/projects/status/github/{{USER}}/{{PKG}}.jl?svg=true", - "https://ci.appveyor.com/project/{{USER}}/{{PKG}}-jl", + "https://ci.appveyor.com/api/projects/status/github/{{{USER}}}/{{{PKG}}}.jl?svg=true", + "https://ci.appveyor.com/project/{{{USER}}}/{{{PKG}}}-jl", ) function view(p::AppVeyor, t::Template, pkg::AbstractString) @@ -178,8 +178,8 @@ destination(::CirrusCI) = ".cirrus.yml" badges(::CirrusCI) = Badge( "Build Status", - "https://api.cirrus-ci.com/github/{{USER}}/{{PACKAGE}}.jl.svg", - "https://cirrus-ci.com/github/{{USER}}/{{PKG}}.jl", + "https://api.cirrus-ci.com/github/{{{USER}}}/{{{PKG}}}.jl.svg", + "https://cirrus-ci.com/github/{{{USER}}}/{{{PKG}}}.jl", ) function view(p::CirrusCI, t::Template, pkg::AbstractString) @@ -230,13 +230,13 @@ destination(::GitLabCI) = ".gitlab-ci.yml" function badges(p::GitLabCI) ci = Badge( "Build Status", - "https://gitlab.com/{{USER}}/{{PKG}}.jl/badges/master/build.svg", - "https://gitlab.com/{{USER}}/{{PKG}}.jl/pipelines", + "https://gitlab.com/{{{USER}}}/{{{PKG}}}.jl/badges/master/build.svg", + "https://gitlab.com/{{{USER}}}/{{{PKG}}}.jl/pipelines", ) cov = Badge( "Coverage", - "https://gitlab.com/{{USER}}/{{PKG}}.jl/badges/master/coverage.svg", - "https://gitlab.com/{{USER}}/{{PKG}}.jl/commits/master", + "https://gitlab.com/{{{USER}}}/{{{PKG}}}.jl/badges/master/coverage.svg", + "https://gitlab.com/{{{USER}}}/{{{PKG}}}.jl/commits/master", ) return p.coverage ? [ci, cov] : [ci] end diff --git a/src/plugins/coverage.jl b/src/plugins/coverage.jl index 04002947..359c312d 100644 --- a/src/plugins/coverage.jl +++ b/src/plugins/coverage.jl @@ -17,8 +17,8 @@ destination(::Codecov) = ".codecov.yml" badges(::Codecov) = Badge( "Coverage", - "https://codecov.io/gh/{{USER}}/{{PKG}}.jl/branch/master/graph/badge.svg", - "https://codecov.io/gh/{{USER}}/{{PKG}}.jl", + "https://codecov.io/gh/{{{USER}}}/{{{PKG}}}.jl/branch/master/graph/badge.svg", + "https://codecov.io/gh/{{{USER}}}/{{{PKG}}}.jl", ) """ @@ -38,8 +38,8 @@ destination(::Coveralls) = ".coveralls.yml" badges(::Coveralls) = Badge( "Coverage", - "https://coveralls.io/repos/github/{{USER}}/{{PKG}}.jl/badge.svg?branch=master", - "https://coveralls.io/github/{{USER}}/{{PKG}}.jl?branch=master", + "https://coveralls.io/repos/github/{{{USER}}}/{{{PKG}}}.jl/badge.svg?branch=master", + "https://coveralls.io/github/{{{USER}}}/{{{PKG}}}.jl?branch=master", ) gitignore(::Union{Codecov, Coveralls}) = COVERAGE_GITIGNORE diff --git a/src/plugins/documenter.jl b/src/plugins/documenter.jl index 3ff2ac18..dc66a5b5 100644 --- a/src/plugins/documenter.jl +++ b/src/plugins/documenter.jl @@ -55,18 +55,18 @@ badges(::Documenter{TravisCI}) = [ Badge( "Stable", "https://img.shields.io/badge/docs-stable-blue.svg", - "https://{{USER}}.github.io/{{PKG}}.jl/stable", + "https://{{{USER}}}.github.io/{{{PKG}}}.jl/stable", ), Badge( "Dev", "https://img.shields.io/badge/docs-dev-blue.svg", - "https://{{USER}}.github.io/{{PKG}}.jl/dev", + "https://{{{USER}}}.github.io/{{{PKG}}}.jl/dev", ), ] badges(::Documenter{GitLabCI}) = Badge( "Dev", "https://img.shields.io/badge/docs-dev-blue.svg", - "https://{{USER}}.gitlab.io/{{PKG}}.jl/dev", + "https://{{{USER}}}.gitlab.io/{{{PKG}}}.jl/dev", ) view(p::Documenter, t::Template, pkg::AbstractString) = Dict( diff --git a/test/fixtures/AllPlugins/README.md.txt b/test/fixtures/AllPlugins/README.md.txt index 44735f9f..adbba2f3 100644 --- a/test/fixtures/AllPlugins/README.md.txt +++ b/test/fixtures/AllPlugins/README.md.txt @@ -4,6 +4,6 @@ [![Coverage](https://gitlab.com/tester/AllPlugins.jl/badges/master/coverage.svg)](https://gitlab.com/tester/AllPlugins.jl/commits/master) [![Build Status](https://travis-ci.com/tester/AllPlugins.jl.svg?branch=master)](https://travis-ci.com/tester/AllPlugins.jl) [![Build Status](https://ci.appveyor.com/api/projects/status/github/tester/AllPlugins.jl?svg=true)](https://ci.appveyor.com/project/tester/AllPlugins-jl) -[![Build Status](https://api.cirrus-ci.com/github/tester/.jl.svg)](https://cirrus-ci.com/github/tester/AllPlugins.jl) +[![Build Status](https://api.cirrus-ci.com/github/tester/AllPlugins.jl.svg)](https://cirrus-ci.com/github/tester/AllPlugins.jl) [![Coverage](https://codecov.io/gh//.jl/branch/master/graph/badge.svg)](https://codecov.io/gh//.jl) [![Coverage](https://coveralls.io/repos/github//.jl/badge.svg?branch=master)](https://coveralls.io/github//.jl?branch=master)