mustache 0.12.0 → 0.12.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -29,11 +29,11 @@ class Mustache
29
29
  # Look for the first Mustache in the stack.
30
30
  mustache = mustache_in_stack
31
31
 
32
- # Call its `partial` method and render the result.
33
- result = mustache.render(mustache.partial(name), self)
32
+ # Indent the partial template by the given indentation.
33
+ part = mustache.partial(name).to_s.gsub(/^/, indentation)
34
34
 
35
- # Indent the rendered partial by the given indentation.
36
- result.gsub(/^/, indentation)
35
+ # Call the Mustache's `partial` method and render the result.
36
+ result = mustache.render(part, self)
37
37
  end
38
38
 
39
39
  # Find the first Mustache in the stack. If we're being rendered
@@ -108,6 +108,7 @@ EOF
108
108
  # Scan until we hit an opening delimiter.
109
109
  start_of_line = @scanner.beginning_of_line?
110
110
  pre_match_position = @scanner.pos
111
+ last_index = @result.length
111
112
 
112
113
  return unless x = @scanner.scan(/([ \t]*)?#{Regexp.escape(otag)}/)
113
114
  padding = @scanner[1] || ''
@@ -144,11 +145,13 @@ EOF
144
145
  @result << [:mustache, :section, content, block]
145
146
  @sections << [content, position, @result]
146
147
  @result = block
148
+ last_index = 1
147
149
  when '^'
148
150
  block = [:multi]
149
151
  @result << [:mustache, :inverted_section, content, block]
150
152
  @sections << [content, position, @result]
151
153
  @result = block
154
+ last_index = 1
152
155
  when '/'
153
156
  section, pos, result = @sections.pop
154
157
  raw = @scanner.pre_match[pos[3]...pre_match_position] + padding
@@ -188,18 +191,18 @@ EOF
188
191
  # the remaining whitespace. If not, but we've been hanging on to padding
189
192
  # from the beginning of the line, re-insert the padding as static text.
190
193
  if start_of_line
191
- if SKIP_WHITESPACE.include?(type)
194
+ if @scanner.peek(1) == "\n" && SKIP_WHITESPACE.include?(type)
192
195
  @scanner.skip(/[ \t]*\n/)
193
196
  else
194
- @result.insert(-2, [:static, padding]) unless padding.empty?
197
+ @result.insert(last_index, [:static, padding]) unless padding.empty?
195
198
  end
196
199
  end
197
200
 
198
- return unless @result == [:multi]
199
-
200
201
  # Store off the current scanner position now that we've closed the tag
201
202
  # and consumed any irrelevant whitespace.
202
203
  @sections.last[1] << @scanner.pos unless @sections.empty?
204
+
205
+ return unless @result == [:multi]
203
206
  end
204
207
 
205
208
  # Try to find static text, e.g. raw HTML with no {{mustaches}}.
@@ -70,19 +70,18 @@ class Mustache
70
70
  else
71
71
  layout = layout.new
72
72
  end
73
-
74
73
  end
75
74
 
76
75
  # Find and cache the view class we want. This ensures the
77
76
  # compiled template is cached, too - no looking up and
78
77
  # compiling templates on each page load.
79
78
  klass = mustache_class(template, options)
80
-
79
+
81
80
  # Does the view subclass the layout? If so we'll use the
82
81
  # view to render the layout so you can override layout
83
82
  # methods in your view - tricky.
84
83
  view_subclasses_layout = klass < layout.class if layout
85
-
84
+
86
85
  # Create a new instance for playing with.
87
86
  instance = klass.new
88
87
 
@@ -1,3 +1,3 @@
1
1
  class Mustache
2
- Version = VERSION = '0.12.0'
2
+ Version = VERSION = '0.12.1'
3
3
  end
@@ -57,6 +57,14 @@ end_complex
57
57
  assert_equal %Q'<p class="flash-notice" style="display: none;">', instance.render
58
58
  end
59
59
 
60
+ def test_sassy_single_line_sections
61
+ instance = Mustache.new
62
+ instance[:full_time] = true
63
+ instance.template = "\n {{#full_time}}full time{{/full_time}}\n"
64
+
65
+ assert_equal "\n full time\n", instance.render
66
+ end
67
+
60
68
  def test_two_line_sections
61
69
  html = %(<p class="flash-notice" {{# no_flash }}style="display: none;"\n{{/ no_flash }}>)
62
70
 
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: 47
4
+ hash: 45
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 12
9
- - 0
10
- version: 0.12.0
9
+ - 1
10
+ version: 0.12.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Chris Wanstrath
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-10 00:00:00 -08:00
18
+ date: 2011-02-22 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies: []
21
21