mustache 0.99.3 → 0.99.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mustache/generator.rb +9 -3
- data/lib/mustache/parser.rb +1 -1
- data/lib/mustache/sinatra.rb +0 -5
- data/lib/mustache/version.rb +1 -1
- data/test/parser_test.rb +10 -5
- metadata +6 -6
data/lib/mustache/generator.rb
CHANGED
@@ -90,7 +90,7 @@ class Mustache
|
|
90
90
|
|
91
91
|
# Callback fired when the compiler finds a section token. We're
|
92
92
|
# passed the section name and the array of tokens.
|
93
|
-
def on_section(name, content, raw)
|
93
|
+
def on_section(name, content, raw, delims)
|
94
94
|
# Convert the tokenized content of this section into a Ruby
|
95
95
|
# string we can use.
|
96
96
|
code = compile(content)
|
@@ -102,7 +102,13 @@ class Mustache
|
|
102
102
|
if v == true
|
103
103
|
#{code}
|
104
104
|
elsif v.is_a?(Proc)
|
105
|
-
Mustache::Template.new(v.call(#{raw.inspect}).to_s)
|
105
|
+
t = Mustache::Template.new(v.call(#{raw.inspect}).to_s)
|
106
|
+
def t.tokens(src=@source)
|
107
|
+
p = Parser.new
|
108
|
+
p.otag, p.ctag = #{delims.inspect}
|
109
|
+
p.compile(src)
|
110
|
+
end
|
111
|
+
t.render(ctx.dup)
|
106
112
|
else
|
107
113
|
# Shortcut when passed non-array
|
108
114
|
v = [v] unless v.is_a?(Array) || defined?(Enumerator) && v.is_a?(Enumerator)
|
@@ -115,7 +121,7 @@ class Mustache
|
|
115
121
|
|
116
122
|
# Fired when we find an inverted section. Just like `on_section`,
|
117
123
|
# we're passed the inverted section name and the array of tokens.
|
118
|
-
def on_inverted_section(name, content, raw)
|
124
|
+
def on_inverted_section(name, content, raw, _)
|
119
125
|
# Convert the tokenized content of this section into a Ruby
|
120
126
|
# string we can use.
|
121
127
|
code = compile(content)
|
data/lib/mustache/parser.rb
CHANGED
@@ -157,7 +157,7 @@ EOF
|
|
157
157
|
when '/'
|
158
158
|
section, pos, result = @sections.pop
|
159
159
|
raw = @scanner.pre_match[pos[3]...pre_match_position] + padding
|
160
|
-
(@result = result).last << raw
|
160
|
+
(@result = result).last << raw << [self.otag, self.ctag]
|
161
161
|
|
162
162
|
if section.nil?
|
163
163
|
error "Closing unopened #{content.inspect}"
|
data/lib/mustache/sinatra.rb
CHANGED
@@ -88,11 +88,6 @@ class Mustache
|
|
88
88
|
# Copy instance variables set in Sinatra to the view
|
89
89
|
instance_variables.each do |name|
|
90
90
|
instance.instance_variable_set(name, instance_variable_get(name))
|
91
|
-
|
92
|
-
# Automagic attr_readers for ivars you set in Sinatra routes.
|
93
|
-
if !instance.respond_to?(name)
|
94
|
-
(class << instance; self end).send(:attr_reader, name.to_s.sub('@',''))
|
95
|
-
end
|
96
91
|
end
|
97
92
|
|
98
93
|
# Render with locals.
|
data/lib/mustache/version.rb
CHANGED
data/test/parser_test.rb
CHANGED
@@ -35,7 +35,8 @@ EOF
|
|
35
35
|
[:static, " <li><strong>"],
|
36
36
|
[:mustache, :etag, [:mustache, :fetch, ["name"]]],
|
37
37
|
[:static, "</strong></li>\n"]],
|
38
|
-
%Q' <li><strong>{{name}}</strong></li>\n'
|
38
|
+
%Q' <li><strong>{{name}}</strong></li>\n',
|
39
|
+
%w[{{ }}]],
|
39
40
|
[:mustache,
|
40
41
|
:section,
|
41
42
|
[:mustache, :fetch, ["link"]],
|
@@ -45,14 +46,17 @@ EOF
|
|
45
46
|
[:static, "\">"],
|
46
47
|
[:mustache, :etag, [:mustache, :fetch, ["name"]]],
|
47
48
|
[:static, "</a></li>\n"]],
|
48
|
-
%Q' <li><a href="{{url}}">{{name}}</a></li>\n'
|
49
|
-
|
49
|
+
%Q' <li><a href="{{url}}">{{name}}</a></li>\n',
|
50
|
+
%w[{{ }}]]],
|
51
|
+
%Q'{{#first}}\n <li><strong>{{name}}</strong></li>\n{{/first}}\n{{#link}}\n <li><a href="{{url}}">{{name}}</a></li>\n{{/link}}\n',
|
52
|
+
%w[{{ }}]],
|
50
53
|
[:static, "\n"],
|
51
54
|
[:mustache,
|
52
55
|
:section,
|
53
56
|
[:mustache, :fetch, ["empty"]],
|
54
57
|
[:multi, [:static, "<p>The list is empty.</p>\n"]],
|
55
|
-
%Q'<p>The list is empty.</p>\n'
|
58
|
+
%Q'<p>The list is empty.</p>\n',
|
59
|
+
%w[{{ }}]]]
|
56
60
|
|
57
61
|
assert_equal expected, tokens
|
58
62
|
end
|
@@ -66,7 +70,8 @@ EOF
|
|
66
70
|
:section,
|
67
71
|
[:mustache, :fetch, ["list"]],
|
68
72
|
[:multi, [:static, "\t"]],
|
69
|
-
"\t"
|
73
|
+
"\t",
|
74
|
+
%w[{{ }}]]]
|
70
75
|
|
71
76
|
assert_equal expected, tokens
|
72
77
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mustache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 411
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 99
|
9
|
-
-
|
10
|
-
version: 0.99.
|
9
|
+
- 4
|
10
|
+
version: 0.99.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Chris Wanstrath
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2011-
|
20
|
+
date: 2011-05-26 00:00:00 -07:00
|
21
21
|
default_executable:
|
22
22
|
dependencies: []
|
23
23
|
|
@@ -141,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
141
|
requirements: []
|
142
142
|
|
143
143
|
rubyforge_project:
|
144
|
-
rubygems_version: 1.
|
144
|
+
rubygems_version: 1.5.2
|
145
145
|
signing_key:
|
146
146
|
specification_version: 3
|
147
147
|
summary: Mustache is a framework-agnostic way to render logic-free views.
|