mustache 1.0.5 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Rakefile +1 -1
- data/lib/mustache.rb +21 -1
- data/lib/mustache/context.rb +4 -4
- data/lib/mustache/generator.rb +2 -2
- data/lib/mustache/parser.rb +5 -3
- data/lib/mustache/version.rb +1 -1
- data/man/mustache.1.html +2 -2
- data/man/mustache.5.html +1 -1
- data/man/mustache.5.ron +1 -1
- data/test/mustache_test.rb +13 -1
- data/test/parser_test.rb +64 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e67a05eb517f6f5186b678d0ffe92a167d2e7908c7b738ad2d99d0c835c230a1
|
4
|
+
data.tar.gz: f011440519762ec422c3724be76ed103153d52144ec24b9eb45c133c1c74dc92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c207b7321fb06b82c814dddc0c7857bf5aa3f2a3ab7058f269f15bf0545aa2b684f5624800d5779f05f4c98a7bed69ca26bb7e1f1e3a955c397adeac3d7ba6bf
|
7
|
+
data.tar.gz: 140774643b249d068b45f2d7a00af1b30faa651300ee8b26534e76f6da267dc63c3251bded724bd0c5fbe0506705b26322e6a99bde7375c40492b27ba8ac58f8
|
data/Rakefile
CHANGED
data/lib/mustache.rb
CHANGED
@@ -190,7 +190,22 @@ class Mustache
|
|
190
190
|
end
|
191
191
|
|
192
192
|
# Override this to provide custom escaping.
|
193
|
+
# By default it uses `CGI.escapeHTML`.
|
193
194
|
#
|
195
|
+
# @example Overriding #escape
|
196
|
+
# class PersonView < Mustache
|
197
|
+
# def escape(value)
|
198
|
+
# my_html_escape_method(value.to_s)
|
199
|
+
# end
|
200
|
+
# end
|
201
|
+
#
|
202
|
+
# @param [Object] value Value to escape.
|
203
|
+
# @return [String] Escaped content.
|
204
|
+
def escape(value)
|
205
|
+
self.escapeHTML(value.to_s)
|
206
|
+
end
|
207
|
+
|
208
|
+
# Override this to provide custom escaping.
|
194
209
|
# Example:
|
195
210
|
#
|
196
211
|
# class PersonView < Mustache
|
@@ -199,6 +214,11 @@ class Mustache
|
|
199
214
|
# end
|
200
215
|
# end
|
201
216
|
#
|
217
|
+
# @deprecated Use {#escape} instead.
|
218
|
+
#
|
219
|
+
# Note that {#escape} can receive any kind of object.
|
220
|
+
# If your override logic is expecting a string, you will
|
221
|
+
# have to call to_s on it yourself.
|
202
222
|
# @param [String] str String to escape.
|
203
223
|
#
|
204
224
|
# @return [String] Escaped HTML.
|
@@ -244,7 +264,7 @@ class Mustache
|
|
244
264
|
file_name = underscore(name)
|
245
265
|
file_path = "#{view_path}/#{file_name}.rb"
|
246
266
|
|
247
|
-
return Mustache unless File.
|
267
|
+
return Mustache unless File.exist?(file_path)
|
248
268
|
|
249
269
|
require file_path.chomp('.rb')
|
250
270
|
rescued_const_get(name)
|
data/lib/mustache/context.rb
CHANGED
@@ -51,12 +51,12 @@ class Mustache
|
|
51
51
|
|
52
52
|
# Allows customization of how Mustache escapes things.
|
53
53
|
#
|
54
|
-
# @param [
|
54
|
+
# @param [Object] value Value to escape.
|
55
55
|
#
|
56
|
-
# @return [String] Escaped
|
56
|
+
# @return [String] Escaped string.
|
57
57
|
#
|
58
|
-
def
|
59
|
-
mustache_in_stack.
|
58
|
+
def escape(value)
|
59
|
+
mustache_in_stack.escape(value)
|
60
60
|
end
|
61
61
|
|
62
62
|
# Adds a new object to the context's internal stack.
|
data/lib/mustache/generator.rb
CHANGED
@@ -133,7 +133,7 @@ class Mustache
|
|
133
133
|
when Proc
|
134
134
|
#{proc_handling}
|
135
135
|
when Array, Enumerator, Mustache::Enumerable
|
136
|
-
v.map { |
|
136
|
+
v.map { |_| ctx.push(_); r = #{code}; ctx.pop; r }.join
|
137
137
|
else
|
138
138
|
ctx.push(v); r = #{code}; ctx.pop; r
|
139
139
|
end
|
@@ -182,7 +182,7 @@ class Mustache
|
|
182
182
|
if v.is_a?(Proc)
|
183
183
|
v = #{@option_static_lambdas ? 'v.call' : 'Mustache::Template.new(v.call.to_s).render(ctx.dup)'}
|
184
184
|
end
|
185
|
-
ctx.
|
185
|
+
ctx.escape(v)
|
186
186
|
compiled
|
187
187
|
end
|
188
188
|
|
data/lib/mustache/parser.rb
CHANGED
@@ -323,12 +323,14 @@ EOF
|
|
323
323
|
|
324
324
|
def scan_tag_close content, fetch, padding, pre_match_position
|
325
325
|
section, pos, result = @sections.pop
|
326
|
+
if section.nil?
|
327
|
+
error "Closing unopened #{content.inspect}"
|
328
|
+
end
|
329
|
+
|
326
330
|
raw = @scanner.pre_match[pos[3]...pre_match_position] + padding
|
327
331
|
(@result = result).last << raw << [self.otag, self.ctag]
|
328
332
|
|
329
|
-
if section
|
330
|
-
error "Closing unopened #{content.inspect}"
|
331
|
-
elsif section != content
|
333
|
+
if section != content
|
332
334
|
error "Unclosed section #{section.inspect}", pos
|
333
335
|
end
|
334
336
|
end
|
data/lib/mustache/version.rb
CHANGED
data/man/mustache.1.html
CHANGED
@@ -102,7 +102,7 @@ names: [ {name: chris}, {name: mark}, {name: scott} ]
|
|
102
102
|
should work fine.</p>
|
103
103
|
|
104
104
|
<p>After the frontmatter should come any valid Mustache template. See
|
105
|
-
<a class="man-ref" href="mustache.5.
|
105
|
+
<a class="man-ref" href="mustache.5.ronn.html">mustache<span class="s">(5)</span></a> for an overview of Mustache templates.</p>
|
106
106
|
|
107
107
|
<p>For example:</p>
|
108
108
|
|
@@ -198,7 +198,7 @@ data
|
|
198
198
|
|
199
199
|
<h2 id="SEE-ALSO">SEE ALSO</h2>
|
200
200
|
|
201
|
-
<p><a class="man-ref" href="mustache.5.
|
201
|
+
<p><a class="man-ref" href="mustache.5.ronn.html">mustache<span class="s">(5)</span></a>, <span class="man-ref">gem<span class="s">(1)</span></span>,
|
202
202
|
<a href="http://mustache.github.io/" data-bare-link="true">http://mustache.github.io/</a></p>
|
203
203
|
|
204
204
|
|
data/man/mustache.5.html
CHANGED
@@ -409,7 +409,7 @@ markup."</p>
|
|
409
409
|
|
410
410
|
<h2 id="SEE-ALSO">SEE ALSO</h2>
|
411
411
|
|
412
|
-
<p><a class="man-ref" href="mustache.1.
|
412
|
+
<p><a class="man-ref" href="mustache.1.ronn.html">mustache<span class="s">(1)</span></a>,
|
413
413
|
<a href="http://mustache.github.io/" data-bare-link="true">http://mustache.github.io/</a></p>
|
414
414
|
|
415
415
|
|
data/man/mustache.5.ron
CHANGED
data/test/mustache_test.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
require_relative 'helper'
|
3
|
+
require 'json'
|
3
4
|
|
4
5
|
class MustacheTest < Minitest::Test
|
5
6
|
def test_instance_render
|
@@ -659,7 +660,7 @@ template
|
|
659
660
|
assert_equal('[ 0 1 2 3 4 5 6 7 8 9 10 ]', MethodMissing.render)
|
660
661
|
end
|
661
662
|
|
662
|
-
def
|
663
|
+
def test_custom_html_escaping
|
663
664
|
view = Class.new(Mustache) do
|
664
665
|
def escapeHTML(str)
|
665
666
|
"pong"
|
@@ -670,6 +671,17 @@ template
|
|
670
671
|
assert_equal 'nothing', Mustache.render("{{thing}}", :thing => "nothing")
|
671
672
|
end
|
672
673
|
|
674
|
+
def test_custom_escaping
|
675
|
+
view = Class.new(Mustache) do
|
676
|
+
def escape(str)
|
677
|
+
JSON.dump(str)
|
678
|
+
end
|
679
|
+
end
|
680
|
+
|
681
|
+
assert_equal '{ "key": "a\"b" }', view.render('{ "key": {{thing}} }', :thing => 'a"b')
|
682
|
+
assert_equal 'nothing', Mustache.render("{{thing}}", :thing => "nothing")
|
683
|
+
end
|
684
|
+
|
673
685
|
def test_implicit_iterator
|
674
686
|
view = Mustache.new
|
675
687
|
view.template = "{{#people}}* {{.}}\n{{/people}}"
|
data/test/parser_test.rb
CHANGED
@@ -94,4 +94,68 @@ EOF
|
|
94
94
|
|
95
95
|
assert_equal expected, tokens
|
96
96
|
end
|
97
|
+
|
98
|
+
def test_unclosed_section
|
99
|
+
lexer = Mustache::Parser.new
|
100
|
+
exception = assert_raises Mustache::Parser::SyntaxError do
|
101
|
+
lexer.compile("{{#list}}")
|
102
|
+
end
|
103
|
+
|
104
|
+
expected = <<-EOF
|
105
|
+
Unclosed section "list"
|
106
|
+
Line 1
|
107
|
+
{{#list}}
|
108
|
+
^
|
109
|
+
EOF
|
110
|
+
|
111
|
+
assert_equal expected, exception.message
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_closing_unopened
|
115
|
+
lexer = Mustache::Parser.new
|
116
|
+
exception = assert_raises Mustache::Parser::SyntaxError do
|
117
|
+
lexer.compile("{{/list}}")
|
118
|
+
end
|
119
|
+
|
120
|
+
expected = <<-EOF
|
121
|
+
Closing unopened "list"
|
122
|
+
Line 1
|
123
|
+
{{/list}}
|
124
|
+
^
|
125
|
+
EOF
|
126
|
+
|
127
|
+
assert_equal expected, exception.message
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_unclosed_tag
|
131
|
+
lexer = Mustache::Parser.new
|
132
|
+
exception = assert_raises Mustache::Parser::SyntaxError do
|
133
|
+
lexer.compile("{{list")
|
134
|
+
end
|
135
|
+
|
136
|
+
expected = <<-EOF
|
137
|
+
Unclosed tag
|
138
|
+
Line 1
|
139
|
+
{{list
|
140
|
+
^
|
141
|
+
EOF
|
142
|
+
|
143
|
+
assert_equal expected, exception.message
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_illegal_content
|
147
|
+
lexer = Mustache::Parser.new
|
148
|
+
exception = assert_raises Mustache::Parser::SyntaxError do
|
149
|
+
lexer.compile("{{")
|
150
|
+
end
|
151
|
+
|
152
|
+
expected = <<-EOF
|
153
|
+
Illegal content in tag
|
154
|
+
Line 1
|
155
|
+
{{
|
156
|
+
^
|
157
|
+
EOF
|
158
|
+
|
159
|
+
assert_equal expected, exception.message
|
160
|
+
end
|
97
161
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mustache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Wanstrath
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2018-10-13 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|
@@ -220,7 +220,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
220
220
|
version: '0'
|
221
221
|
requirements: []
|
222
222
|
rubyforge_project:
|
223
|
-
rubygems_version: 2.
|
223
|
+
rubygems_version: 2.7.7
|
224
224
|
signing_key:
|
225
225
|
specification_version: 4
|
226
226
|
summary: Mustache is a framework-agnostic way to render logic-free views.
|