mustache 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.2.2 (2009-10-11)
2
+
3
+ * Improved documentation
4
+ * Fixed single line sections
5
+ * Broke preserved indentation (issue #2)
6
+
1
7
  ## 0.2.1 (2009-10-11)
2
8
 
3
9
  * Mustache.underscore can now be called without an argument
data/README.md CHANGED
@@ -169,20 +169,20 @@ Dict-Style Views
169
169
  ----------------
170
170
 
171
171
  ctemplate and friends want you to hand a dictionary to the template
172
- processor. Naturally Mustache supports a similar concept. Feel free
173
- to mix the class-based and this more procedural style at your leisure.
172
+ processor. Mustache supports a similar concept. Feel free to mix the
173
+ class-based and this more procedural style at your leisure.
174
174
 
175
- Given this template (dict.html):
175
+ Given this template (winner.html):
176
176
 
177
177
  Hello {{name}}
178
178
  You have just won ${{value}}!
179
179
 
180
180
  We can fill in the values at will:
181
181
 
182
- dict = Dict.new
183
- dict[:name] = 'George'
184
- dict[:value] = 100
185
- dict.render
182
+ view = Winner.new
183
+ view[:name] = 'George'
184
+ view[:value] = 100
185
+ view.render
186
186
 
187
187
  Which returns:
188
188
 
@@ -191,8 +191,8 @@ Which returns:
191
191
 
192
192
  We can re-use the same object, too:
193
193
 
194
- dict[:name] = 'Tony'
195
- dict.render
194
+ view[:name] = 'Tony'
195
+ view.render
196
196
  Hello Tony
197
197
  You have just won $100!
198
198
 
data/benchmarks/speed.rb CHANGED
@@ -15,8 +15,10 @@ unless ENV['NOERB']
15
15
  erb.result(ComplexView.new.send(:binding))
16
16
  end
17
17
 
18
- bench 'ERB w/o caching' do
19
- ERB.new(template).result(ComplexView.new.send(:binding))
18
+ unless ENV['CACHED']
19
+ bench 'ERB w/o caching' do
20
+ ERB.new(template).result(ComplexView.new.send(:binding))
21
+ end
20
22
  end
21
23
  end
22
24
 
@@ -35,14 +37,14 @@ items << { :name => 'blue', :current => false, :url => '#Blue' }
35
37
 
36
38
  tpl[:item] = items
37
39
 
38
- bench '{ w/ caching' do
40
+ bench '{ w/ caching' do
39
41
  tpl.to_html
40
42
  end
41
43
 
42
44
  content = File.read(ComplexView.template_file)
43
45
 
44
46
  unless ENV['CACHED']
45
- bench '{ w/o caching' do
47
+ bench '{ w/o caching' do
46
48
  ctpl = ComplexView.new
47
49
  ctpl.template = content
48
50
  ctpl[:item] = items
@@ -2,7 +2,6 @@ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
2
  require 'mustache'
3
3
 
4
4
  class Passenger < Mustache
5
-
6
5
  self.path = File.dirname(__FILE__)
7
6
  self.template_extension = 'conf'
8
7
 
@@ -21,9 +20,8 @@ class Passenger < Mustache
21
20
  def timestamp
22
21
  Time.now.strftime('%Y%m%d%H%M%S')
23
22
  end
24
-
25
23
  end
26
24
 
27
25
  if $0 == __FILE__
28
26
  puts Passenger.to_text
29
- end
27
+ end
@@ -47,7 +47,7 @@ class Mustache
47
47
  # If enumerable, the return value is iterated over (a `for` loop).
48
48
  def compile_sections(src)
49
49
  res = ""
50
- while src =~ /^\s*\{\{\#(.+)\}\}\n*(.+)^\s*\{\{\/\1\}\}\n*/m
50
+ while src =~ /\{\{\#(.+)\}\}\s*(.+)\{\{\/\1\}\}\s*/m
51
51
  # $` = The string to the left of the last successful match
52
52
  res << compile_tags($`)
53
53
  name = $1.strip.to_sym.inspect
@@ -1,3 +1,3 @@
1
1
  class Mustache
2
- Version = '0.2.1'
2
+ Version = '0.2.2'
3
3
  end
@@ -11,7 +11,6 @@ require 'comments'
11
11
  require 'passenger'
12
12
 
13
13
  class MustacheTest < Test::Unit::TestCase
14
-
15
14
  def test_passenger
16
15
  assert_equal <<-end_passenger, Passenger.to_text
17
16
  <VirtualHost *>
@@ -33,6 +32,28 @@ end_passenger
33
32
  end_complex
34
33
  end
35
34
 
35
+ def test_single_line_sections
36
+ html = %(<p class="flash-notice" {{# no_flash }}style="display: none;"{{/ no_flash }}>)
37
+
38
+ instance = Mustache.new
39
+ instance.template = html
40
+ instance[:no_flash] = true
41
+ assert_equal <<-rendered.strip, instance.render
42
+ <p class="flash-notice" style="display: none;">
43
+ rendered
44
+ end
45
+
46
+ def test_two_line_sections
47
+ html = %(<p class="flash-notice" {{# no_flash }}style="display: none;"\n{{/ no_flash }}>)
48
+
49
+ instance = Mustache.new
50
+ instance.template = html
51
+ instance[:no_flash] = true
52
+ assert_equal <<-rendered.strip, instance.render
53
+ <p class="flash-notice" style="display: none;"\n>
54
+ rendered
55
+ end
56
+
36
57
  def test_simple
37
58
  assert_equal <<-end_simple, Simple.render
38
59
  Hello Chris
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: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Wanstrath