Skip to content

Commit

Permalink
Escape HTML the right way
Browse files Browse the repository at this point in the history
  • Loading branch information
christopher-dG committed Sep 18, 2019
1 parent 8659870 commit dc4f2be
Show file tree
Hide file tree
Showing 16 changed files with 71 additions and 76 deletions.
12 changes: 6 additions & 6 deletions defaults/CITATION.bib
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
@misc{<<PKG>>.jl,
author = {<<AUTHORS>>},
title = {<<PKG>>.jl},
url = {<<URL>>},
@misc{<<&PKG>>.jl,
author = {<<&AUTHORS>>},
title = {<<&PKG>>.jl},
url = {<<&URL>>},
version = {v0.1.0},
year = {<<YEAR>>},
month = {<<MONTH>>}
year = {<<&YEAR>>},
month = {<<&MONTH>>}
}
4 changes: 2 additions & 2 deletions defaults/README.md
Original file line number Diff line number Diff line change
@@ -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}}
Expand Down
6 changes: 3 additions & 3 deletions defaults/appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions defaults/cirrus.yml
Original file line number Diff line number Diff line change
@@ -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 -)"
Expand Down
10 changes: 5 additions & 5 deletions defaults/gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 '
Expand Down
4 changes: 2 additions & 2 deletions defaults/index.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# {{PKG}}
# {{{PKG}}}

```@index
```

```@autodocs
Modules = [{{PKG}}]
Modules = [{{{PKG}}}]
```
18 changes: 9 additions & 9 deletions defaults/make.jl
Original file line number Diff line number Diff line change
@@ -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}}
],
Expand All @@ -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}}
4 changes: 2 additions & 2 deletions defaults/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using {{PKG}}
using {{{PKG}}}
using Test

@testset "{{PKG}}.jl" begin
@testset "{{{PKG}}}.jl" begin
# Write your tests here.
end
12 changes: 6 additions & 6 deletions defaults/travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,31 @@ notifications:
email: false
julia:
{{#VERSIONS}}
- {{.}}
- {{{.}}}
{{/VERSIONS}}
os:
{{#OS}}
- {{.}}
- {{{.}}}
{{/OS}}
jobs:
fast_finish: true
{{#HAS_ALLOW_FAILURES}}
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()));
Expand Down
21 changes: 13 additions & 8 deletions docs/src/user.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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 `<<foo>>`, use `<<&foo>>` to disable escaping.

Assuming the following view:

Expand Down
2 changes: 1 addition & 1 deletion src/PkgTemplates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 2 additions & 12 deletions src/plugin.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

"""
Expand All @@ -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"))
Expand Down
20 changes: 10 additions & 10 deletions src/plugins/ci.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/coverage.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)

"""
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/documenter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/AllPlugins/README.md.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit dc4f2be

Please sign in to comment.