mustache 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- N2E0NDQ2MDc0ZDI0ZWM1NGU2N2M4MTdlMTAxOTkyY2JkZDYzOWE3Yw==
4
+ NTQ2NzA3NTY3ZTQ4MzNkNWY1MzU4MjBlZjgwZmNiZDg3NjA5OTU4NQ==
5
5
  data.tar.gz: !binary |-
6
- NzFlMjg3YmFjNWY5NTY4MmQ2NmQ3OTkyNjgxYTQyYWEzY2VlN2Q0Mw==
6
+ MGYwNTg4YTNlMGIzMDFlM2RlZWRlYjgxOWVkYzVmMjBkYTY0NjJlMg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YTM2ZTgwMzEzOWY2MjFhY2FkMGQ5OWY5NWY3OWRhNjQ2YmUyNTc1ZDdhNGZl
10
- MWU3OWQ4ZjE1ZmExZWY3Nzg5Y2E3N2ZkMmEyZWE0ZWZmYmQwNmM5YjMwOGQy
11
- ZjA5MTUxMzkxMTZjMWFmNGY3YmY5YmMwOGY0ZGFlYTViOGE1ZjI=
9
+ ZDZkYjBjYmJlN2E3ZTg0ODliZDM0MTAwM2Q5YTQ4OTU4YmRhZDQwMzZjMWU2
10
+ ODk0MDY3NTliYjM2NGI1OGUzMzZiNDkzNzA4NjEzNWJhMGRhZGFiZmUwYjJj
11
+ ODYzNjY3MWU0MDg2NjUzMzdkYTcwZGZhOTk4NWQ1MWZhYzBlNGQ=
12
12
  data.tar.gz: !binary |-
13
- NzAwNzI4YjUzNzM5MDY1OGQ5YzZjMGVlMDAxZjg0NWVmMmRjZjg5MWY5OGU5
14
- OTI2YWY0NmVjZTEzZGNkNGMwYWQ3ZGIzNmVmOGNhYjY2MmYyYmFjYWM4MDkx
15
- ZjQ3YjY5ODM2ZmUwNGVkZjQyODI0OWUyZGI1OGUwNzkxYjM0MmY=
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: <http://rubygems.org/gems/mustache>
382
+ * Gems: <https://rubygems.org/gems/mustache>
383
383
 
384
- [1]: http://code.google.com/p/google-ctemplate/
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]: http://help.github.com/forking/
390
- [is]: https://github.com/defunkt/mustache/issues
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
@@ -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
@@ -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
- !!fetch(key, false)
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 value != :__missing
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
- key = to_tag(key)
142
- return default unless obj.respond_to?(key)
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
- obj.fetch(key, default)
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
@@ -113,7 +113,7 @@ class Mustache
113
113
  elsif v.is_a?(Proc)
114
114
  t = Mustache::Template.new(v.call(#{raw.inspect}).to_s)
115
115
  def t.tokens(src=@source)
116
- p = Parser.new
116
+ p = Mustache::Parser.new
117
117
  p.otag, p.ctag = #{delims.inspect}
118
118
  p.compile(src)
119
119
  end
@@ -121,7 +121,7 @@ EOF
121
121
  scan_tags || scan_text
122
122
  end
123
123
 
124
- if !@sections.empty?
124
+ unless @sections.empty?
125
125
  # We have parsed the whole file, but there's still opened sections.
126
126
  type, pos, _ = @sections.pop
127
127
  error "Unclosed section #{type.inspect}", pos
@@ -110,9 +110,6 @@ class Mustache
110
110
  end
111
111
 
112
112
 
113
- private
114
-
115
-
116
113
  # Simple recursive iterator for tokens
117
114
  def self.recursor(toks, section, &block)
118
115
  toks.map do |token|
@@ -1,3 +1,3 @@
1
1
  class Mustache
2
- VERSION = '1.0.2'
2
+ VERSION = '1.0.3'
3
3
  end
@@ -1 +1 @@
1
- {{first-name}} {{middle_name!}} {{lastName?}}
1
+ {{first-name}} {{middle_name!}} {{lastName?}} {{street-address}}
@@ -14,6 +14,10 @@ class Liberal < Mustache
14
14
  def lastName?
15
15
  'sheurs'
16
16
  end
17
+
18
+ define_method :'street-address' do
19
+ '123 Somewhere St'
20
+ end
17
21
  end
18
22
 
19
23
  if $0 == __FILE__
@@ -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.2
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: 2015-06-24 00:00:00.000000000 Z
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.4.5
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.