mustache 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +4 -4
- data/bin/mustache +6 -1
- data/lib/mustache/context.rb +14 -11
- data/lib/mustache/generator.rb +1 -1
- data/lib/mustache/parser.rb +1 -1
- data/lib/mustache/template.rb +0 -3
- data/lib/mustache/version.rb +1 -1
- data/test/fixtures/liberal.mustache +1 -1
- data/test/fixtures/liberal.rb +4 -0
- data/test/mustache_test.rb +24 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NTQ2NzA3NTY3ZTQ4MzNkNWY1MzU4MjBlZjgwZmNiZDg3NjA5OTU4NQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MGYwNTg4YTNlMGIzMDFlM2RlZWRlYjgxOWVkYzVmMjBkYTY0NjJlMg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZDZkYjBjYmJlN2E3ZTg0ODliZDM0MTAwM2Q5YTQ4OTU4YmRhZDQwMzZjMWU2
|
10
|
+
ODk0MDY3NTliYjM2NGI1OGUzMzZiNDkzNzA4NjEzNWJhMGRhZGFiZmUwYjJj
|
11
|
+
ODYzNjY3MWU0MDg2NjUzMzdkYTcwZGZhOTk4NWQ1MWZhYzBlNGQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NDA2ZDRiNjRlYTg3MjRkZjhmNWFjZDAyMjY3YzU1YzM0NTU4MWNlMzkzMmI0
|
14
|
+
MjAxMjAxOWYyNDdmYWE5MzEwODYzYzExZjBmM2VkN2E3YzdmODYxNGI2NTc3
|
15
|
+
N2U3ZGExOTcxMmE3MDBmMTdmMWI1YmUzNmE4YTFlMTdiMjQwNmM=
|
data/README.md
CHANGED
@@ -379,15 +379,15 @@ or IRC:
|
|
379
379
|
* Home: <http://mustache.github.io>
|
380
380
|
* Bugs: <https://github.com/mustache/mustache/issues>
|
381
381
|
* List: <mustache@librelist.com>
|
382
|
-
* Gems: <
|
382
|
+
* Gems: <https://rubygems.org/gems/mustache>
|
383
383
|
|
384
|
-
[1]:
|
384
|
+
[1]: https://github.com/olafvdspek/ctemplate
|
385
385
|
[2]: http://www.ivan.fomichev.name/2008/05/erlang-template-engine-prototype.html
|
386
386
|
[3]: http://google-ctemplate.googlecode.com/svn/trunk/doc/howto.html
|
387
387
|
[4]: https://github.com/brynary/rack-bug/
|
388
388
|
[5]: http://img.skitch.com/20091027-n8pxwwx8r61tc318a15q1n6m14.png
|
389
|
-
[fk]:
|
390
|
-
[is]: https://github.com/
|
389
|
+
[fk]: https://help.github.com/forking/
|
390
|
+
[is]: https://github.com/mustache/mustache/issues
|
391
391
|
[irc]: irc://irc.freenode.net/#{
|
392
392
|
[vim]: https://github.com/mustache/vim-mustache-handlebars
|
393
393
|
[emacs]: https://github.com/mustache/vim-mustache-handlebars
|
data/bin/mustache
CHANGED
@@ -11,7 +11,7 @@ class Mustache
|
|
11
11
|
# Return a structure describing the options.
|
12
12
|
def self.parse_options(args)
|
13
13
|
opts = OptionParser.new do |opts|
|
14
|
-
opts.banner = "Usage: mustache [-c] [-t] [-r library] FILE ..."
|
14
|
+
opts.banner = "Usage: mustache [-c] [-t] [-e] [-r library] FILE ..."
|
15
15
|
|
16
16
|
opts.separator " "
|
17
17
|
|
@@ -42,6 +42,11 @@ class Mustache
|
|
42
42
|
exit
|
43
43
|
end
|
44
44
|
|
45
|
+
opts.on("-e", "--error",
|
46
|
+
"Raise an error on context misses.") do |e|
|
47
|
+
Mustache.raise_on_context_miss = true
|
48
|
+
end
|
49
|
+
|
45
50
|
opts.on('-r', '--require LIB', 'Require a Ruby library before running.') do |lib|
|
46
51
|
require lib
|
47
52
|
end
|
data/lib/mustache/context.rb
CHANGED
@@ -97,7 +97,7 @@ class Mustache
|
|
97
97
|
# Do we know about a particular key? In other words, will calling
|
98
98
|
# `context[key]` give us a result that was set. Basically.
|
99
99
|
def has_key?(key)
|
100
|
-
|
100
|
+
fetch(key, false)
|
101
101
|
rescue ContextMiss
|
102
102
|
false
|
103
103
|
end
|
@@ -114,7 +114,7 @@ class Mustache
|
|
114
114
|
next if frame == self
|
115
115
|
|
116
116
|
value = find(frame, name, :__missing)
|
117
|
-
return value if
|
117
|
+
return value if :__missing != value
|
118
118
|
end
|
119
119
|
|
120
120
|
if default == :__raise || mustache_in_stack.raise_on_context_miss?
|
@@ -138,8 +138,11 @@ class Mustache
|
|
138
138
|
def find(obj, key, default = nil)
|
139
139
|
return find_in_hash(obj.to_hash, key, default) if obj.respond_to?(:to_hash)
|
140
140
|
|
141
|
-
|
142
|
-
|
141
|
+
unless obj.respond_to?(key)
|
142
|
+
# no match for the key, but it may include a hyphen, so try again replacing hyphens with underscores.
|
143
|
+
key = key.to_s.tr('-', '_')
|
144
|
+
return default unless obj.respond_to?(key)
|
145
|
+
end
|
143
146
|
|
144
147
|
meth = obj.method(key) rescue proc { obj.send(key) }
|
145
148
|
meth.arity == 1 ? meth.to_proc : meth.call
|
@@ -152,18 +155,18 @@ class Mustache
|
|
152
155
|
|
153
156
|
private
|
154
157
|
|
155
|
-
|
156
|
-
# If a class, we need to find tags (methods) per Parser::ALLOWED_CONTENT.
|
157
|
-
def to_tag key
|
158
|
-
key.to_s.include?('-') ? key.to_s.tr('-', '_') : key
|
159
|
-
end
|
160
|
-
|
161
158
|
# Fetches a hash key if it exists, or returns the given default.
|
162
159
|
def find_in_hash(obj, key, default)
|
163
160
|
return obj[key] if obj.has_key?(key)
|
164
161
|
return obj[key.to_s] if obj.has_key?(key.to_s)
|
165
162
|
|
166
|
-
|
163
|
+
# If default is :__missing then we are from #fetch which is hunting through the stack
|
164
|
+
# If default is nil then we are reducing dot notation
|
165
|
+
if :__missing != default && mustache_in_stack.raise_on_context_miss?
|
166
|
+
raise ContextMiss.new("Can't find #{key} in #{obj}")
|
167
|
+
else
|
168
|
+
obj.fetch(key, default)
|
169
|
+
end
|
167
170
|
end
|
168
171
|
end
|
169
172
|
end
|
data/lib/mustache/generator.rb
CHANGED
data/lib/mustache/parser.rb
CHANGED
data/lib/mustache/template.rb
CHANGED
data/lib/mustache/version.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{{first-name}} {{middle_name!}} {{lastName?}}
|
1
|
+
{{first-name}} {{middle_name!}} {{lastName?}} {{street-address}}
|
data/test/fixtures/liberal.rb
CHANGED
data/test/mustache_test.rb
CHANGED
@@ -430,6 +430,29 @@ Benvolio is 15
|
|
430
430
|
end
|
431
431
|
end
|
432
432
|
|
433
|
+
def test_not_found_deep_in_context_raises_when_asked_to
|
434
|
+
instance = Mustache.new
|
435
|
+
instance.raise_on_context_miss = true
|
436
|
+
|
437
|
+
instance[:list] = { :item => { :value => 1234 } }
|
438
|
+
|
439
|
+
instance.template = '{{list.item.no_value}}'
|
440
|
+
|
441
|
+
assert_raises Mustache::ContextMiss do
|
442
|
+
instance.render
|
443
|
+
end
|
444
|
+
end
|
445
|
+
|
446
|
+
def test_found_in_nested_context_when_asked_to_raise
|
447
|
+
instance = Mustache.new
|
448
|
+
instance.raise_on_context_miss = true
|
449
|
+
|
450
|
+
instance[:item] = { :list => [ { :value => 1235, :deep_list => [{:x => 'y'}]}] }
|
451
|
+
|
452
|
+
instance.template = '{{#item.list}}{{#deep_list}}{{value}}{{/deep_list}}{{/item.list}}'
|
453
|
+
assert_equal '1235', instance.render
|
454
|
+
end
|
455
|
+
|
433
456
|
def test_knows_when_its_been_compiled_when_set_with_string
|
434
457
|
klass = Class.new(Mustache)
|
435
458
|
|
@@ -518,7 +541,7 @@ Benvolio is 15
|
|
518
541
|
|
519
542
|
def test_liberal_tag_names_in_class
|
520
543
|
assert_equal <<-end_liberal, Liberal.render
|
521
|
-
kevin j sheurs
|
544
|
+
kevin j sheurs 123 Somewhere St
|
522
545
|
end_liberal
|
523
546
|
end
|
524
547
|
|
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.0.3
|
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: 2016-03-24 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|
@@ -229,7 +229,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
229
229
|
version: '0'
|
230
230
|
requirements: []
|
231
231
|
rubyforge_project:
|
232
|
-
rubygems_version: 2.
|
232
|
+
rubygems_version: 2.5.1
|
233
233
|
signing_key:
|
234
234
|
specification_version: 4
|
235
235
|
summary: Mustache is a framework-agnostic way to render logic-free views.
|