mustache 0.99.2 → 0.99.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -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] FILE ..."
14
+ opts.banner = "Usage: mustache [-c] [-t] [-r library] FILE ..."
15
15
 
16
16
  opts.separator " "
17
17
 
@@ -42,6 +42,10 @@ class Mustache
42
42
  exit
43
43
  end
44
44
 
45
+ opts.on('-r', '--require LIB', 'Require a Ruby library before running.') do |lib|
46
+ require lib
47
+ end
48
+
45
49
  opts.separator "Common Options:"
46
50
 
47
51
  opts.on("-v", "--version", "Print the version") do |v|
@@ -128,7 +128,7 @@ class Mustache
128
128
  elsif hash && obj.has_key?(key.to_s)
129
129
  obj[key.to_s]
130
130
  elsif !hash && obj.respond_to?(key)
131
- meth = obj.method(key)
131
+ meth = obj.method(key) rescue proc { obj.send(key) }
132
132
  if meth.arity == 1
133
133
  meth.to_proc
134
134
  else
@@ -117,6 +117,7 @@ EOF
117
117
  # of a new line.
118
118
  unless start_of_line
119
119
  @result << [:static, padding] unless padding.empty?
120
+ pre_match_position += padding.length
120
121
  padding = ''
121
122
  end
122
123
 
@@ -140,7 +141,6 @@ EOF
140
141
 
141
142
  fetch = [:mustache, :fetch, content.split('.')]
142
143
  prev = @result
143
- last_index = @result.size
144
144
 
145
145
  # Based on the sigil, do what needs to be done.
146
146
  case type
@@ -192,7 +192,7 @@ EOF
192
192
  # If this tag was the only non-whitespace content on this line, strip
193
193
  # the remaining whitespace. If not, but we've been hanging on to padding
194
194
  # from the beginning of the line, re-insert the padding as static text.
195
- if start_of_line
195
+ if start_of_line && !@scanner.eos?
196
196
  if @scanner.peek(2) =~ /\r?\n/ && SKIP_WHITESPACE.include?(type)
197
197
  @scanner.skip(/\r?\n/)
198
198
  else
@@ -1,3 +1,3 @@
1
1
  class Mustache
2
- Version = VERSION = '0.99.2'
2
+ Version = VERSION = '0.99.3'
3
3
  end
@@ -0,0 +1,19 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
+ require 'mustache'
3
+
4
+ class MethodMissing < Mustache
5
+ self.template = '[ {{#list}}{{.}} {{/list}}]'
6
+
7
+ def method_missing(name, *args, &block)
8
+ return (0..10).to_a if name == :list
9
+ return super
10
+ end
11
+
12
+ def respond_to?(method)
13
+ method == :list
14
+ end
15
+ end
16
+
17
+ if $0 == __FILE__
18
+ puts MethodMissing.to_html
19
+ end
@@ -88,6 +88,13 @@ end_complex
88
88
  assert_equal "\taa", instance.render(:list => [1, 2])
89
89
  end
90
90
 
91
+ def test_padding_before_section_on_eos
92
+ instance = Mustache.new
93
+ instance.template = "{{#list}}\n\t{{/list}}"
94
+
95
+ assert_equal "", instance.render(:list => [1, 2])
96
+ end
97
+
91
98
  def test_two_line_sections
92
99
  html = %(<p class="flash-notice" {{# no_flash }}style="display: none;"\n{{/ no_flash }}>)
93
100
 
@@ -539,6 +546,10 @@ template
539
546
  assert_equal 'Marvin is 25', view.render
540
547
  end
541
548
 
549
+ def test_method_missing
550
+ assert_equal('[ 0 1 2 3 4 5 6 7 8 9 10 ]', MethodMissing.render)
551
+ end
552
+
542
553
  def test_custom_escaping
543
554
  view = Class.new(Mustache) do
544
555
  def escapeHTML(str)
@@ -56,4 +56,18 @@ EOF
56
56
 
57
57
  assert_equal expected, tokens
58
58
  end
59
+
60
+ def test_raw_content_and_whitespace
61
+ lexer = Mustache::Parser.new
62
+ tokens = lexer.compile("{{#list}}\t{{/list}}")
63
+
64
+ expected = [:multi,
65
+ [:mustache,
66
+ :section,
67
+ [:mustache, :fetch, ["list"]],
68
+ [:multi, [:static, "\t"]],
69
+ "\t"]]
70
+
71
+ assert_equal expected, tokens
72
+ end
59
73
  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: 407
4
+ hash: 405
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 99
9
- - 2
10
- version: 0.99.2
9
+ - 3
10
+ version: 0.99.3
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-03-06 00:00:00 -08:00
20
+ date: 2011-03-19 00:00:00 -07:00
21
21
  default_executable:
22
22
  dependencies: []
23
23
 
@@ -84,6 +84,7 @@ files:
84
84
  - test/fixtures/inverted_section.rb
85
85
  - test/fixtures/lambda.mustache
86
86
  - test/fixtures/lambda.rb
87
+ - test/fixtures/method_missing.rb
87
88
  - test/fixtures/namespaced.mustache
88
89
  - test/fixtures/namespaced.rb
89
90
  - test/fixtures/nested_objects.mustache