Escape HTML the right way

This commit is contained in:
Chris de Graaf 2019-09-18 22:27:16 +07:00
parent f6272e110f
commit 358c213b87
No known key found for this signature in database
GPG Key ID: 150FFDD9B0073C7B
16 changed files with 71 additions and 76 deletions

View File

@ -1,8 +1,8 @@
@misc{<<PKG>>.jl, @misc{<<&PKG>>.jl,
author = {<<AUTHORS>>}, author = {<<&AUTHORS>>},
title = {<<PKG>>.jl}, title = {<<&PKG>>.jl},
url = {<<URL>>}, url = {<<&URL>>},
version = {v0.1.0}, version = {v0.1.0},
year = {<<YEAR>>}, year = {<<&YEAR>>},
month = {<<MONTH>>} month = {<<&MONTH>>}
} }

View File

@ -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}} {{^HAS_INLINE_BADGES}}
{{#BADGES}} {{#BADGES}}
{{.}} {{{.}}}
{{/BADGES}} {{/BADGES}}
{{/HAS_INLINE_BADGES}} {{/HAS_INLINE_BADGES}}
{{#HAS_CITATION}} {{#HAS_CITATION}}

View File

@ -2,17 +2,17 @@
environment: environment:
matrix: matrix:
{{#VERSIONS}} {{#VERSIONS}}
- julia_version: {{.}} - julia_version: {{{.}}}
{{/VERSIONS}} {{/VERSIONS}}
platform: platform:
{{#PLATFORMS}} {{#PLATFORMS}}
- {{.}} - {{{.}}}
{{/PLATFORMS}} {{/PLATFORMS}}
{{#HAS_ALLOW_FAILURES}} {{#HAS_ALLOW_FAILURES}}
matrix: matrix:
allow_failures: allow_failures:
{{#ALLOW_FAILURES}} {{#ALLOW_FAILURES}}
- julia_version: {{.}} - julia_version: {{{.}}}
{{/ALLOW_FAILURES}} {{/ALLOW_FAILURES}}
{{/HAS_ALLOW_FAILURES}} {{/HAS_ALLOW_FAILURES}}
branches: branches:

View File

@ -1,10 +1,10 @@
freebsd_instance: freebsd_instance:
image: {{IMAGE}} image: {{{IMAGE}}}
task: task:
name: FreeBSD name: FreeBSD
env: env:
{{#VERSIONS}} {{#VERSIONS}}
JULIA_VERSION: {{.}} JULIA_VERSION: {{{.}}}
{{/VERSIONS}} {{/VERSIONS}}
install_script: install_script:
- sh -c "$(fetch https://raw.githubusercontent.com/ararslan/CirrusCI.jl/master/bin/install.sh -o -)" - sh -c "$(fetch https://raw.githubusercontent.com/ararslan/CirrusCI.jl/master/bin/install.sh -o -)"

View File

@ -18,16 +18,16 @@
@printf "Test coverage %.2f%%\n" 100c / t;' @printf "Test coverage %.2f%%\n" 100c / t;'
{{/HAS_COVERAGE}} {{/HAS_COVERAGE}}
{{#VERSIONS}} {{#VERSIONS}}
Julia {{.}}: Julia {{{.}}}:
image: julia:{{.}} image: julia:{{{.}}}
<<: *script <<: *script
{{#HAS_COVERAGE}} {{#HAS_COVERAGE}}
<<: *coverage <<: *coverage
{{/HAS_COVERAGE}} {{/HAS_COVERAGE}}
{{/VERSIONS}} {{/VERSIONS}}
{{#HAS_DOCUMENTER}} {{#HAS_DOCUMENTER}}
pages: pages:
image: julia:{{VERSION}} image: julia:{{{VERSION}}}
stage: deploy stage: deploy
script: script:
- julia --project=docs -e ' - julia --project=docs -e '

View File

@ -1,8 +1,8 @@
# {{PKG}} # {{{PKG}}}
```@index ```@index
``` ```
```@autodocs ```@autodocs
Modules = [{{PKG}}] Modules = [{{{PKG}}}]
``` ```

View File

@ -1,18 +1,18 @@
using {{PKG}} using {{{PKG}}}
using Documenter using Documenter
makedocs(; makedocs(;
modules=[{{PKG}}], modules=[{{{PKG}}}],
authors="{{AUTHORS}}", authors="{{{AUTHORS}}}",
repo="https://{{REPO}}/blob/{commit}{path}#L{line}", repo="https://{{{REPO}}}/blob/{commit}{path}#L{line}",
sitename="{{PKG}}.jl", sitename="{{{PKG}}}.jl",
format=Documenter.HTML(; format=Documenter.HTML(;
{{#CANONICAL}} {{#CANONICAL}}
canonical="{{CANONICAL}}", canonical="{{{CANONICAL}}}",
{{/CANONICAL}} {{/CANONICAL}}
assets={{^HAS_ASSETS}}String{{/HAS_ASSETS}}[{{^HAS_ASSETS}}],{{/HAS_ASSETS}} assets={{^HAS_ASSETS}}String{{/HAS_ASSETS}}[{{^HAS_ASSETS}}],{{/HAS_ASSETS}}
{{#ASSETS}} {{#ASSETS}}
"{{.}}", "{{{.}}}",
{{/ASSETS}} {{/ASSETS}}
{{#HAS_ASSETS}} {{#HAS_ASSETS}}
], ],
@ -22,12 +22,12 @@ makedocs(;
"Home" => "index.md", "Home" => "index.md",
], ],
{{#MAKEDOCS_KWARGS}} {{#MAKEDOCS_KWARGS}}
{{first}}={{second}}, {{{first}}}={{{second}}},
{{/MAKEDOCS_KWARGS}} {{/MAKEDOCS_KWARGS}}
) )
{{#HAS_DEPLOY}} {{#HAS_DEPLOY}}
deploydocs(; deploydocs(;
repo="{{REPO}}", repo="{{{REPO}}}",
) )
{{/HAS_DEPLOY}} {{/HAS_DEPLOY}}

View File

@ -1,6 +1,6 @@
using {{PKG}} using {{{PKG}}}
using Test using Test
@testset "{{PKG}}.jl" begin @testset "{{{PKG}}}.jl" begin
# Write your tests here. # Write your tests here.
end end

View File

@ -4,11 +4,11 @@ notifications:
email: false email: false
julia: julia:
{{#VERSIONS}} {{#VERSIONS}}
- {{.}} - {{{.}}}
{{/VERSIONS}} {{/VERSIONS}}
os: os:
{{#OS}} {{#OS}}
- {{.}} - {{{.}}}
{{/OS}} {{/OS}}
jobs: jobs:
fast_finish: true fast_finish: true
@ -16,19 +16,19 @@ jobs:
allow_failures: allow_failures:
{{/HAS_ALLOW_FAILURES}} {{/HAS_ALLOW_FAILURES}}
{{#ALLOW_FAILURES}} {{#ALLOW_FAILURES}}
- julia: {{.}} - julia: {{{.}}}
{{/ALLOW_FAILURES}} {{/ALLOW_FAILURES}}
{{#HAS_JOBS}} {{#HAS_JOBS}}
include: include:
{{/HAS_JOBS}} {{/HAS_JOBS}}
{{#X86}} {{#X86}}
- julia: {{JULIA}} - julia: {{{JULIA}}}
os: {{OS}} os: {{{OS}}}
arch: x86 arch: x86
{{/X86}} {{/X86}}
{{#HAS_DOCUMENTER}} {{#HAS_DOCUMENTER}}
- stage: Documentation - stage: Documentation
julia: {{VERSION}} julia: {{{VERSION}}}
script: julia --project=docs -e ' script: julia --project=docs -e '
using Pkg; using Pkg;
Pkg.develop(PackageSpec(; path=pwd())); Pkg.develop(PackageSpec(; path=pwd()));

View File

@ -75,10 +75,10 @@ If that's the case, a basic understanding of [Mustache](https://mustache.github.
Here's an example template file: Here's an example template file:
``` ```
Hello, {{name}}. Hello, {{{name}}}.
{{#weather}} {{#weather}}
It's {{weather}} outside. It's {{{weather}}} outside.
{{/weather}} {{/weather}}
{{^weather}} {{^weather}}
I don't know what the weather outside is. 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: I have the following things:
{{/has_things}} {{/has_things}}
{{#things}} {{#things}}
- Here's a thing: {{.}} - Here's a thing: {{{.}}}
{{/things}} {{/things}}
{{#people}} {{#people}}
- {{name}} is {{mood}} - {{{name}}} is {{{mood}}}
{{/people}} {{/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. In the second section, `weather`'s value may or may not exist.
If it does exist, then "It's $weather outside" is printed. 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. 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. 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. 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 `<<foo>>`, use `<<&foo>>` to disable escaping.
Assuming the following view: Assuming the following view:

View File

@ -9,7 +9,7 @@ using LibGit2: LibGit2, GitRemote
using Pkg: Pkg, TOML, PackageSpec using Pkg: Pkg, TOML, PackageSpec
using REPL.TerminalMenus: MultiSelectMenu, RadioMenu, request using REPL.TerminalMenus: MultiSelectMenu, RadioMenu, request
using Mustache: entityMap, render using Mustache: render
using Parameters: @with_kw_noshow using Parameters: @with_kw_noshow
export export

View File

@ -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. `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) 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 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. `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) function render_text(text::AbstractString, view::Dict{<:AbstractString}, tags=nothing)
saved = copy(entityMap) return tags === nothing ? render(text, view) : render(text, view; tags=tags)
empty!(entityMap)
return try
if tags === nothing
render(text, view)
else
render(text, view; tags=tags)
end
finally
append!(entityMap, saved)
end
end end
include(joinpath("plugins", "defaults.jl")) include(joinpath("plugins", "defaults.jl"))

View File

@ -59,8 +59,8 @@ destination(::TravisCI) = ".travis.yml"
badges(::TravisCI) = Badge( badges(::TravisCI) = Badge(
"Build Status", "Build Status",
"https://travis-ci.com/{{USER}}/{{PKG}}.jl.svg?branch=master", "https://travis-ci.com/{{{USER}}}/{{{PKG}}}.jl.svg?branch=master",
"https://travis-ci.com/{{USER}}/{{PKG}}.jl", "https://travis-ci.com/{{{USER}}}/{{{PKG}}}.jl",
) )
function view(p::TravisCI, t::Template, pkg::AbstractString) function view(p::TravisCI, t::Template, pkg::AbstractString)
@ -125,8 +125,8 @@ destination(::AppVeyor) = ".appveyor.yml"
badges(::AppVeyor) = Badge( badges(::AppVeyor) = Badge(
"Build Status", "Build Status",
"https://ci.appveyor.com/api/projects/status/github/{{USER}}/{{PKG}}.jl?svg=true", "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/project/{{{USER}}}/{{{PKG}}}-jl",
) )
function view(p::AppVeyor, t::Template, pkg::AbstractString) function view(p::AppVeyor, t::Template, pkg::AbstractString)
@ -178,8 +178,8 @@ destination(::CirrusCI) = ".cirrus.yml"
badges(::CirrusCI) = Badge( badges(::CirrusCI) = Badge(
"Build Status", "Build Status",
"https://api.cirrus-ci.com/github/{{USER}}/{{PACKAGE}}.jl.svg", "https://api.cirrus-ci.com/github/{{{USER}}}/{{{PKG}}}.jl.svg",
"https://cirrus-ci.com/github/{{USER}}/{{PKG}}.jl", "https://cirrus-ci.com/github/{{{USER}}}/{{{PKG}}}.jl",
) )
function view(p::CirrusCI, t::Template, pkg::AbstractString) function view(p::CirrusCI, t::Template, pkg::AbstractString)
@ -230,13 +230,13 @@ destination(::GitLabCI) = ".gitlab-ci.yml"
function badges(p::GitLabCI) function badges(p::GitLabCI)
ci = Badge( ci = Badge(
"Build Status", "Build Status",
"https://gitlab.com/{{USER}}/{{PKG}}.jl/badges/master/build.svg", "https://gitlab.com/{{{USER}}}/{{{PKG}}}.jl/badges/master/build.svg",
"https://gitlab.com/{{USER}}/{{PKG}}.jl/pipelines", "https://gitlab.com/{{{USER}}}/{{{PKG}}}.jl/pipelines",
) )
cov = Badge( cov = Badge(
"Coverage", "Coverage",
"https://gitlab.com/{{USER}}/{{PKG}}.jl/badges/master/coverage.svg", "https://gitlab.com/{{{USER}}}/{{{PKG}}}.jl/badges/master/coverage.svg",
"https://gitlab.com/{{USER}}/{{PKG}}.jl/commits/master", "https://gitlab.com/{{{USER}}}/{{{PKG}}}.jl/commits/master",
) )
return p.coverage ? [ci, cov] : [ci] return p.coverage ? [ci, cov] : [ci]
end end

View File

@ -17,8 +17,8 @@ destination(::Codecov) = ".codecov.yml"
badges(::Codecov) = Badge( badges(::Codecov) = Badge(
"Coverage", "Coverage",
"https://codecov.io/gh/{{USER}}/{{PKG}}.jl/branch/master/graph/badge.svg", "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",
) )
""" """
@ -38,8 +38,8 @@ destination(::Coveralls) = ".coveralls.yml"
badges(::Coveralls) = Badge( badges(::Coveralls) = Badge(
"Coverage", "Coverage",
"https://coveralls.io/repos/github/{{USER}}/{{PKG}}.jl/badge.svg?branch=master", "https://coveralls.io/repos/github/{{{USER}}}/{{{PKG}}}.jl/badge.svg?branch=master",
"https://coveralls.io/github/{{USER}}/{{PKG}}.jl?branch=master", "https://coveralls.io/github/{{{USER}}}/{{{PKG}}}.jl?branch=master",
) )
gitignore(::Union{Codecov, Coveralls}) = COVERAGE_GITIGNORE gitignore(::Union{Codecov, Coveralls}) = COVERAGE_GITIGNORE

View File

@ -55,18 +55,18 @@ badges(::Documenter{TravisCI}) = [
Badge( Badge(
"Stable", "Stable",
"https://img.shields.io/badge/docs-stable-blue.svg", "https://img.shields.io/badge/docs-stable-blue.svg",
"https://{{USER}}.github.io/{{PKG}}.jl/stable", "https://{{{USER}}}.github.io/{{{PKG}}}.jl/stable",
), ),
Badge( Badge(
"Dev", "Dev",
"https://img.shields.io/badge/docs-dev-blue.svg", "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( badges(::Documenter{GitLabCI}) = Badge(
"Dev", "Dev",
"https://img.shields.io/badge/docs-dev-blue.svg", "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( view(p::Documenter, t::Template, pkg::AbstractString) = Dict(

View File

@ -4,6 +4,6 @@
[![Coverage](https://gitlab.com/tester/AllPlugins.jl/badges/master/coverage.svg)](https://gitlab.com/tester/AllPlugins.jl/commits/master) [![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://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://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://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) [![Coverage](https://coveralls.io/repos/github//.jl/badge.svg?branch=master)](https://coveralls.io/github//.jl?branch=master)