mustache 0.99.6 → 0.99.7
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/mustache +2 -16
- data/lib/mustache.rb +7 -6
- data/lib/mustache/context.rb +6 -13
- data/lib/mustache/generator.rb +8 -12
- data/lib/mustache/parser.rb +6 -6
- data/lib/mustache/template.rb +2 -1
- data/lib/mustache/version.rb +1 -1
- data/lib/rack/bug/panels/mustache_panel.rb +1 -1
- data/man/mustache.1 +1 -1
- data/man/mustache.1.html +1 -1
- data/man/mustache.5 +3 -3
- data/man/mustache.5.html +3 -3
- data/man/mustache.5.ron +2 -2
- data/test/spec_test.rb +1 -5
- metadata +46 -26
- checksums.yaml +0 -7
- data/lib/mustache/blah.rb +0 -116
data/bin/mustache
CHANGED
@@ -64,14 +64,6 @@ class Mustache
|
|
64
64
|
opts.parse!(args)
|
65
65
|
end
|
66
66
|
|
67
|
-
def self.yaml_is_array?(yaml)
|
68
|
-
yaml.is_a? Array and yaml.length == 1 and yaml[0].is_a? Array
|
69
|
-
end
|
70
|
-
|
71
|
-
def self.yaml_is_object?(yaml)
|
72
|
-
yaml.is_a? Array and yaml.length == 1 and yaml[0].is_a? Hash
|
73
|
-
end
|
74
|
-
|
75
67
|
# Does the dirty work of reading files from the command line then
|
76
68
|
# processing them. The meat of this script, if you will.
|
77
69
|
def self.process_files(input_files)
|
@@ -79,7 +71,7 @@ class Mustache
|
|
79
71
|
|
80
72
|
yaml = nil
|
81
73
|
begin
|
82
|
-
yaml =
|
74
|
+
yaml = YAML.load_stream(doc)
|
83
75
|
rescue
|
84
76
|
puts "Unable to parse yaml!"
|
85
77
|
end
|
@@ -89,13 +81,7 @@ class Mustache
|
|
89
81
|
else
|
90
82
|
template = input_files.skip.file.read
|
91
83
|
|
92
|
-
|
93
|
-
puts Mustache.render(template, yaml[0].reduce({}) {|hash, currentHash| hash.merge(currentHash)})
|
94
|
-
elsif self.yaml_is_object?(yaml)
|
95
|
-
puts Mustache.render(template, yaml[0])
|
96
|
-
else
|
97
|
-
puts Mustache.render(template, yaml)
|
98
|
-
end
|
84
|
+
puts Mustache.render template, yaml.compact.reduce(&:merge)
|
99
85
|
end
|
100
86
|
end
|
101
87
|
end
|
data/lib/mustache.rb
CHANGED
@@ -107,14 +107,15 @@ class Mustache
|
|
107
107
|
#
|
108
108
|
# Returns a rendered String version of a template
|
109
109
|
def render(data = template, ctx = {})
|
110
|
-
|
110
|
+
tpl = case data
|
111
|
+
when Hash
|
111
112
|
ctx = data
|
112
|
-
|
113
|
-
|
113
|
+
templateify(template)
|
114
|
+
when Symbol
|
114
115
|
self.template_name = data
|
115
|
-
|
116
|
+
templateify(template)
|
116
117
|
else
|
117
|
-
|
118
|
+
templateify(data)
|
118
119
|
end
|
119
120
|
|
120
121
|
return tpl.render(context) if ctx == {}
|
@@ -231,7 +232,7 @@ class Mustache
|
|
231
232
|
# Returns the constant if found
|
232
233
|
# Returns nil if nothing is found
|
233
234
|
def self.const_get!(name)
|
234
|
-
name.split('::').
|
235
|
+
name.split('::').reduce(Object) do |klass, cname|
|
235
236
|
klass.const_get(cname)
|
236
237
|
end
|
237
238
|
rescue NameError
|
data/lib/mustache/context.rb
CHANGED
@@ -119,27 +119,20 @@ class Mustache
|
|
119
119
|
#
|
120
120
|
# Returns the value of key in obj if it is found and default otherwise.
|
121
121
|
def find(obj, key, default = nil)
|
122
|
-
|
123
|
-
|
124
|
-
if !hash
|
122
|
+
if !obj.respond_to?(:to_hash)
|
125
123
|
# If a class, we need to find tags (methods) per Parser::ALLOWED_CONTENT.
|
126
|
-
if key.to_s.include?('-')
|
127
|
-
key = key.to_s.gsub('-', '_')
|
128
|
-
end
|
124
|
+
key = key.to_s.tr('-', '_') if key.to_s.include?('-')
|
129
125
|
|
130
126
|
if obj.respond_to?(key)
|
131
127
|
meth = obj.method(key) rescue proc { obj.send(key) }
|
132
|
-
|
133
|
-
|
134
|
-
else
|
135
|
-
meth[]
|
136
|
-
end
|
128
|
+
|
129
|
+
meth.arity == 1 ? meth.to_proc : meth[]
|
137
130
|
else
|
138
131
|
default
|
139
132
|
end
|
140
|
-
elsif
|
133
|
+
elsif obj.has_key?(key)
|
141
134
|
obj[key]
|
142
|
-
elsif
|
135
|
+
elsif obj.has_key?(key.to_s)
|
143
136
|
obj[key.to_s]
|
144
137
|
else
|
145
138
|
obj[key] || default
|
data/lib/mustache/generator.rb
CHANGED
@@ -171,20 +171,16 @@ class Mustache
|
|
171
171
|
end
|
172
172
|
|
173
173
|
def on_fetch(names)
|
174
|
+
return "ctx[:to_s]" if names.empty?
|
175
|
+
|
174
176
|
names = names.map { |n| n.to_sym }
|
175
177
|
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
<<-compiled
|
183
|
-
#{rest.inspect}.inject(ctx[#{initial.inspect}]) { |value, key|
|
184
|
-
value && ctx.find(value, key)
|
185
|
-
}
|
186
|
-
compiled
|
187
|
-
end
|
178
|
+
initial, *rest = names
|
179
|
+
<<-compiled
|
180
|
+
#{rest.inspect}.reduce(ctx[#{initial.inspect}]) { |value, key|
|
181
|
+
value && ctx.find(value, key)
|
182
|
+
}
|
183
|
+
compiled
|
188
184
|
end
|
189
185
|
|
190
186
|
# An interpolation-friendly version of a string, for use within a
|
data/lib/mustache/parser.rb
CHANGED
@@ -45,7 +45,7 @@ EOF
|
|
45
45
|
end
|
46
46
|
|
47
47
|
# The sigil types which are valid after an opening `{{`
|
48
|
-
VALID_TYPES = [ '#', '^', '/', '=', '!', '<', '>', '&', '{' ]
|
48
|
+
VALID_TYPES = [ '#', '^', '/', '=', '!', '<', '>', '&', '{' ].map &:freeze
|
49
49
|
|
50
50
|
def self.valid_types
|
51
51
|
@valid_types ||= Regexp.new(VALID_TYPES.map { |t| Regexp.escape(t) }.join('|') )
|
@@ -75,14 +75,14 @@ EOF
|
|
75
75
|
# After these types of tags, all whitespace until the end of the line will
|
76
76
|
# be skipped if they are the first (and only) non-whitespace content on
|
77
77
|
# the line.
|
78
|
-
SKIP_WHITESPACE = [ '#', '^', '/', '<', '>', '=', '!' ]
|
78
|
+
SKIP_WHITESPACE = [ '#', '^', '/', '<', '>', '=', '!' ].map &:freeze
|
79
79
|
|
80
80
|
# The content allowed in a tag name.
|
81
81
|
ALLOWED_CONTENT = /(\w|[?!\/.-])*/
|
82
82
|
|
83
83
|
# These types of tags allow any content,
|
84
84
|
# the rest only allow ALLOWED_CONTENT.
|
85
|
-
ANY_CONTENT = [ '!', '=' ]
|
85
|
+
ANY_CONTENT = [ '!', '=' ].map &:freeze
|
86
86
|
|
87
87
|
attr_reader :scanner, :result
|
88
88
|
attr_writer :otag, :ctag
|
@@ -157,11 +157,11 @@ EOF
|
|
157
157
|
|
158
158
|
# ANY_CONTENT tags allow any character inside of them, while
|
159
159
|
# other tags (such as variables) are more strict.
|
160
|
-
if ANY_CONTENT.include?(type)
|
160
|
+
content = if ANY_CONTENT.include?(type)
|
161
161
|
r = /\s*#{regexp(type)}?#{regexp(current_ctag)}/
|
162
|
-
|
162
|
+
scan_until_exclusive(r)
|
163
163
|
else
|
164
|
-
|
164
|
+
@scanner.scan(ALLOWED_CONTENT)
|
165
165
|
end
|
166
166
|
|
167
167
|
# We found {{ but we can't figure out what's going on inside.
|
data/lib/mustache/template.rb
CHANGED
@@ -59,6 +59,7 @@ class Mustache
|
|
59
59
|
def self.recursor(toks, section, &block)
|
60
60
|
toks.map do |token|
|
61
61
|
next unless token.is_a? Array
|
62
|
+
|
62
63
|
if token[0] == :mustache
|
63
64
|
new_token, new_section, result, stop = yield(token, section)
|
64
65
|
[ result ] + ( stop ? [] : recursor(new_token, new_section, &block))
|
@@ -74,7 +75,7 @@ class Mustache
|
|
74
75
|
Template.recursor(tokens, []) do |token, section|
|
75
76
|
if [:etag, :utag].include?(token[1])
|
76
77
|
[ new_token=nil, new_section=nil, result=((section + [token[2][2][0]]).join('.')), stop=true ]
|
77
|
-
elsif [:section, :inverted_section].include?(token[1])
|
78
|
+
elsif [:section, :inverted_section].include?(token[1])
|
78
79
|
[ new_token=token[4], new_section=(section + [token[2][2][0]]), result=nil, stop=false ]
|
79
80
|
else
|
80
81
|
[ new_token=token, new_section=section, result=nil, stop=false ]
|
data/lib/mustache/version.rb
CHANGED
data/man/mustache.1
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
.\" generated with Ronn/v0.7.3
|
2
2
|
.\" http://github.com/rtomayko/ronn/tree/0.7.3
|
3
3
|
.
|
4
|
-
.TH "MUSTACHE" "1" "
|
4
|
+
.TH "MUSTACHE" "1" "October 2014" "DEFUNKT" "Mustache Manual"
|
5
5
|
.
|
6
6
|
.SH "NAME"
|
7
7
|
\fBmustache\fR \- Mustache processor
|
data/man/mustache.1.html
CHANGED
data/man/mustache.5
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
.\" generated with Ronn/v0.7.3
|
2
2
|
.\" http://github.com/rtomayko/ronn/tree/0.7.3
|
3
3
|
.
|
4
|
-
.TH "MUSTACHE" "5" "
|
4
|
+
.TH "MUSTACHE" "5" "October 2014" "DEFUNKT" "Mustache Manual"
|
5
5
|
.
|
6
6
|
.SH "NAME"
|
7
7
|
\fBmustache\fR \- Logic\-less templates\.
|
@@ -126,7 +126,7 @@ Output:
|
|
126
126
|
.IP "" 0
|
127
127
|
.
|
128
128
|
.SS "Sections"
|
129
|
-
Sections render blocks of text
|
129
|
+
Sections render blocks of text zero or more times, depending on the value of the key in the current context\.
|
130
130
|
.
|
131
131
|
.P
|
132
132
|
A section begins with a pound and ends with a slash\. That is, \fB{{#person}}\fR begins a "person" section while \fB{{/person}}\fR ends it\.
|
@@ -349,7 +349,7 @@ Hi Jon!
|
|
349
349
|
An inverted section begins with a caret (hat) and ends with a slash\. That is \fB{{^person}}\fR begins a "person" inverted section while \fB{{/person}}\fR ends it\.
|
350
350
|
.
|
351
351
|
.P
|
352
|
-
While sections can be used to render text
|
352
|
+
While sections can be used to render text zero or more times based on the value of the key, inverted sections may render text once based on the inverse value of the key\. That is, they will be rendered if the key doesn\'t exist, is false, or is an empty list\.
|
353
353
|
.
|
354
354
|
.P
|
355
355
|
Template:
|
data/man/mustache.5.html
CHANGED
@@ -161,7 +161,7 @@ supports raising an exception in this situation, for instance.</p>
|
|
161
161
|
|
162
162
|
<h3 id="Sections">Sections</h3>
|
163
163
|
|
164
|
-
<p>Sections render blocks of text
|
164
|
+
<p>Sections render blocks of text zero or more times, depending on the
|
165
165
|
value of the key in the current context.</p>
|
166
166
|
|
167
167
|
<p>A section begins with a pound and ends with a slash. That is,
|
@@ -291,7 +291,7 @@ context for a single rendering of the block.</p>
|
|
291
291
|
slash. That is <code>{{^person}}</code> begins a "person" inverted section while
|
292
292
|
<code>{{/person}}</code> ends it.</p>
|
293
293
|
|
294
|
-
<p>While sections can be used to render text
|
294
|
+
<p>While sections can be used to render text zero or more times based on the
|
295
295
|
value of the key, inverted sections may render text once based
|
296
296
|
on the inverse value of the key. That is, they will be rendered
|
297
297
|
if the key doesn't exist, is false, or is an empty list.</p>
|
@@ -415,7 +415,7 @@ markup."</p>
|
|
415
415
|
|
416
416
|
<ol class='man-decor man-foot man foot'>
|
417
417
|
<li class='tl'>DEFUNKT</li>
|
418
|
-
<li class='tc'>
|
418
|
+
<li class='tc'>October 2014</li>
|
419
419
|
<li class='tr'>mustache(5)</li>
|
420
420
|
</ol>
|
421
421
|
|
data/man/mustache.5.ron
CHANGED
@@ -88,7 +88,7 @@ Output:
|
|
88
88
|
|
89
89
|
### Sections
|
90
90
|
|
91
|
-
Sections render blocks of text
|
91
|
+
Sections render blocks of text zero or more times, depending on the
|
92
92
|
value of the key in the current context.
|
93
93
|
|
94
94
|
A section begins with a pound and ends with a slash. That is,
|
@@ -207,7 +207,7 @@ An inverted section begins with a caret (hat) and ends with a
|
|
207
207
|
slash. That is `{{^person}}` begins a "person" inverted section while
|
208
208
|
`{{/person}}` ends it.
|
209
209
|
|
210
|
-
While sections can be used to render text
|
210
|
+
While sections can be used to render text zero or more times based on the
|
211
211
|
value of the key, inverted sections may render text once based
|
212
212
|
on the inverse value of the key. That is, they will be rendered
|
213
213
|
if the key doesn't exist, is false, or is an empty list.
|
data/test/spec_test.rb
CHANGED
@@ -4,11 +4,7 @@ require 'yaml'
|
|
4
4
|
require 'test/unit'
|
5
5
|
|
6
6
|
# Calls appropriate method on YAML. See: https://gist.github.com/tenderlove/958999ab4240b93bd3cd
|
7
|
-
|
8
|
-
YAML.add_domain_type(nil, 'code') { |_, val| eval(val['ruby']) }
|
9
|
-
else
|
10
|
-
YAML.add_builtin_type('code') { |_, val| eval(val['ruby']) }
|
11
|
-
end
|
7
|
+
YAML.add_domain_type(nil, 'code') { |_, val| eval(val['ruby']) }
|
12
8
|
|
13
9
|
# A simple base class for Mustache specs.
|
14
10
|
# Creates a partials directory, then points a (dynamic) subclass of Mustache at
|
metadata
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mustache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.99.
|
4
|
+
version: 0.99.7
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Chris Wanstrath
|
@@ -10,102 +11,118 @@ authors:
|
|
10
11
|
autorequire:
|
11
12
|
bindir: bin
|
12
13
|
cert_chain: []
|
13
|
-
date: 2014-
|
14
|
+
date: 2014-10-22 00:00:00.000000000 Z
|
14
15
|
dependencies:
|
15
16
|
- !ruby/object:Gem::Dependency
|
16
17
|
name: bundler
|
17
18
|
requirement: !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
18
20
|
requirements:
|
19
|
-
- -
|
21
|
+
- - ~>
|
20
22
|
- !ruby/object:Gem::Version
|
21
23
|
version: '1.6'
|
22
24
|
type: :development
|
23
25
|
prerelease: false
|
24
26
|
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
none: false
|
25
28
|
requirements:
|
26
|
-
- -
|
29
|
+
- - ~>
|
27
30
|
- !ruby/object:Gem::Version
|
28
31
|
version: '1.6'
|
29
32
|
- !ruby/object:Gem::Dependency
|
30
33
|
name: rake
|
31
34
|
requirement: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
32
36
|
requirements:
|
33
|
-
- -
|
37
|
+
- - ~>
|
34
38
|
- !ruby/object:Gem::Version
|
35
39
|
version: '10.3'
|
36
40
|
type: :development
|
37
41
|
prerelease: false
|
38
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
39
44
|
requirements:
|
40
|
-
- -
|
45
|
+
- - ~>
|
41
46
|
- !ruby/object:Gem::Version
|
42
47
|
version: '10.3'
|
43
48
|
- !ruby/object:Gem::Dependency
|
44
49
|
name: rdoc
|
45
50
|
requirement: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
46
52
|
requirements:
|
47
|
-
- -
|
53
|
+
- - ~>
|
48
54
|
- !ruby/object:Gem::Version
|
49
55
|
version: '4.1'
|
50
56
|
type: :development
|
51
57
|
prerelease: false
|
52
58
|
version_requirements: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
53
60
|
requirements:
|
54
|
-
- -
|
61
|
+
- - ~>
|
55
62
|
- !ruby/object:Gem::Version
|
56
63
|
version: '4.1'
|
57
64
|
- !ruby/object:Gem::Dependency
|
58
65
|
name: ronn
|
59
66
|
requirement: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
60
68
|
requirements:
|
61
|
-
- -
|
69
|
+
- - ~>
|
62
70
|
- !ruby/object:Gem::Version
|
63
71
|
version: '0.7'
|
64
72
|
type: :development
|
65
73
|
prerelease: false
|
66
74
|
version_requirements: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
67
76
|
requirements:
|
68
|
-
- -
|
77
|
+
- - ~>
|
69
78
|
- !ruby/object:Gem::Version
|
70
79
|
version: '0.7'
|
71
80
|
- !ruby/object:Gem::Dependency
|
72
81
|
name: turn
|
73
82
|
requirement: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
74
84
|
requirements:
|
75
|
-
- -
|
85
|
+
- - ~>
|
76
86
|
- !ruby/object:Gem::Version
|
77
87
|
version: '0.9'
|
78
88
|
type: :development
|
79
89
|
prerelease: false
|
80
90
|
version_requirements: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
81
92
|
requirements:
|
82
|
-
- -
|
93
|
+
- - ~>
|
83
94
|
- !ruby/object:Gem::Version
|
84
95
|
version: '0.9'
|
85
|
-
description:
|
86
|
-
|
96
|
+
description: ! 'Inspired by ctemplate, Mustache is a framework-agnostic way to render
|
97
|
+
|
87
98
|
logic-free views.
|
88
99
|
|
100
|
+
|
89
101
|
As ctemplates says, "It emphasizes separating logic from presentation:
|
102
|
+
|
90
103
|
it is impossible to embed application logic in this template
|
104
|
+
|
91
105
|
language.
|
92
106
|
|
107
|
+
|
93
108
|
Think of Mustache as a replacement for your views. Instead of views
|
109
|
+
|
94
110
|
consisting of ERB or HAML with random helpers and arbitrary logic,
|
111
|
+
|
95
112
|
your views are broken into two parts: a Ruby class and an HTML
|
113
|
+
|
96
114
|
template.
|
115
|
+
|
116
|
+
'
|
97
117
|
email: chris@ozmm.org
|
98
118
|
executables:
|
99
119
|
- mustache
|
100
120
|
extensions: []
|
101
121
|
extra_rdoc_files: []
|
102
122
|
files:
|
103
|
-
- LICENSE
|
104
123
|
- README.md
|
105
124
|
- Rakefile
|
106
|
-
-
|
107
|
-
- lib/mustache.rb
|
108
|
-
- lib/mustache/blah.rb
|
125
|
+
- LICENSE
|
109
126
|
- lib/mustache/context.rb
|
110
127
|
- lib/mustache/enumerable.rb
|
111
128
|
- lib/mustache/generator.rb
|
@@ -114,9 +131,11 @@ files:
|
|
114
131
|
- lib/mustache/sinatra.rb
|
115
132
|
- lib/mustache/template.rb
|
116
133
|
- lib/mustache/version.rb
|
117
|
-
- lib/
|
134
|
+
- lib/mustache.rb
|
118
135
|
- lib/rack/bug/panels/mustache_panel/mustache_extension.rb
|
119
136
|
- lib/rack/bug/panels/mustache_panel/view.mustache
|
137
|
+
- lib/rack/bug/panels/mustache_panel.rb
|
138
|
+
- bin/mustache
|
120
139
|
- man/mustache.1
|
121
140
|
- man/mustache.1.html
|
122
141
|
- man/mustache.1.ron
|
@@ -174,28 +193,29 @@ files:
|
|
174
193
|
- test/partial_test.rb
|
175
194
|
- test/spec_test.rb
|
176
195
|
- test/template_test.rb
|
177
|
-
homepage: http://github.com/
|
196
|
+
homepage: http://github.com/mustache/mustache
|
178
197
|
licenses:
|
179
198
|
- MIT
|
180
|
-
metadata: {}
|
181
199
|
post_install_message:
|
182
200
|
rdoc_options: []
|
183
201
|
require_paths:
|
184
202
|
- lib
|
185
203
|
required_ruby_version: !ruby/object:Gem::Requirement
|
204
|
+
none: false
|
186
205
|
requirements:
|
187
|
-
- -
|
206
|
+
- - ! '>='
|
188
207
|
- !ruby/object:Gem::Version
|
189
|
-
version:
|
208
|
+
version: 1.9.3
|
190
209
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
210
|
+
none: false
|
191
211
|
requirements:
|
192
|
-
- -
|
212
|
+
- - ! '>='
|
193
213
|
- !ruby/object:Gem::Version
|
194
214
|
version: '0'
|
195
215
|
requirements: []
|
196
216
|
rubyforge_project:
|
197
|
-
rubygems_version:
|
217
|
+
rubygems_version: 1.8.23.2
|
198
218
|
signing_key:
|
199
|
-
specification_version:
|
219
|
+
specification_version: 3
|
200
220
|
summary: Mustache is a framework-agnostic way to render logic-free views.
|
201
221
|
test_files: []
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: e3c1091a71418634c3e493d6b3aae1e5a8f0d0f0
|
4
|
-
data.tar.gz: 87936c1b015243222b2c95c29693106a9ea646a1
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: a422377f6020f923eac84ca194e46b78d05ad611428faa4dede440c090c61e2a30d5d15618286ae72b8ebf486e9aae4b351fee521f5bdc4e13ecc99d1a1677e4
|
7
|
-
data.tar.gz: 30d05bc44030071c322a18ff64235c7bd8da19b03c1cbb4bc68dd3deba33c21d82af75dc435aa2c9845705ea8c7989130aa7626aced0ffb119d6bc18344fa420
|
data/lib/mustache/blah.rb
DELETED
@@ -1,116 +0,0 @@
|
|
1
|
-
require 'mustache'
|
2
|
-
|
3
|
-
class Mustache::Template
|
4
|
-
def token_names
|
5
|
-
def recursor(toks, section)
|
6
|
-
toks.map do |token|
|
7
|
-
next unless token.is_a? Array
|
8
|
-
if token[0] == :mustache && [:etag,:utag].include? token[1]
|
9
|
-
(section + [token[2][2][0]]).join '.'
|
10
|
-
elsif token[0] == :mustache && [:section,:inverted_section].include? token[1]
|
11
|
-
recursor(token[4], section + [token[2][2][0]])
|
12
|
-
else
|
13
|
-
recursor(token, section)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
recursor(tokens, []).flatten.reject(&:nil?).uniq
|
18
|
-
end
|
19
|
-
|
20
|
-
def section_names
|
21
|
-
def recursor(toks, section)
|
22
|
-
sections = []
|
23
|
-
toks.each do |token|
|
24
|
-
next unless token.is_a? Array
|
25
|
-
if token[0] == :mustache && [:section,:inverted_section].include? token[1]
|
26
|
-
new_section = section + [token[2][2][0]]
|
27
|
-
sections += [ new_section.join('.') ] + recursor(token[4], new_section)
|
28
|
-
else
|
29
|
-
sections += recursor(token, section)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
sections
|
33
|
-
end
|
34
|
-
recursor(tokens,[]).reject(&:nil?).uniq
|
35
|
-
end
|
36
|
-
|
37
|
-
def partial_names
|
38
|
-
def recursor(toks)
|
39
|
-
partials = []
|
40
|
-
toks.each do |token|
|
41
|
-
next unless token.is_a? Array
|
42
|
-
partials += if token[0..1] == [:mustache, :partial]
|
43
|
-
[token[2]] # partial here
|
44
|
-
else
|
45
|
-
recursor(token)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
partials
|
49
|
-
end
|
50
|
-
recursor(tokens).reject(&:nil?).uniq
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
54
|
-
|
55
|
-
if __FILE__ == $0
|
56
|
-
require "test/unit"
|
57
|
-
|
58
|
-
class TestMustacheTokenNames < Test::Unit::TestCase
|
59
|
-
|
60
|
-
def setup
|
61
|
-
@template = Mustache::Template.new(@@template_text ||= DATA.read)
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_token_names
|
65
|
-
assert_equal(@template.token_names,
|
66
|
-
[ "yourname",
|
67
|
-
"HOME",
|
68
|
-
"friend.name",
|
69
|
-
"friend.morr.word",
|
70
|
-
"friend.morr.up",
|
71
|
-
"friend.morr.awesomesauce",
|
72
|
-
"friend.morr.hiss",
|
73
|
-
"friend.notinmorr",
|
74
|
-
"friend.person",
|
75
|
-
"love",
|
76
|
-
"triplestash"
|
77
|
-
]
|
78
|
-
)
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_partial_names
|
82
|
-
assert_equal(@template.partial_names, ["partial1", "partial2"])
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_section_names
|
86
|
-
assert_equal(@template.section_names, ["friend", "friend.morr"])
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
__END__
|
92
|
-
Hi there {{yourname}}. Your home directory is {{HOME}}.
|
93
|
-
|
94
|
-
{{#friend}}
|
95
|
-
Your friend is named {{name}}
|
96
|
-
{{#morr}}
|
97
|
-
Hey {{word}} {{up}} {{{awesomesauce}}}.
|
98
|
-
{{/morr}}
|
99
|
-
{{^morr}}
|
100
|
-
Booooo. {{hiss}}
|
101
|
-
{{/morr}}
|
102
|
-
{{notinmorr}}
|
103
|
-
{{> partial1}}
|
104
|
-
{{/friend}}
|
105
|
-
{{^friend}}
|
106
|
-
You have no friends, {{person}}. You suck.
|
107
|
-
{{/friend}}
|
108
|
-
|
109
|
-
{{> partial2}}
|
110
|
-
{{! comments are awesome }}
|
111
|
-
|
112
|
-
{{={% %}=}}
|
113
|
-
|
114
|
-
{%love%}
|
115
|
-
{%={{ }}=%}
|
116
|
-
{{{triplestash}}}
|