tilt 1.2.2 → 1.3.2

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.
@@ -5,35 +5,16 @@ begin
5
5
  require 'bluecloth'
6
6
 
7
7
  class BlueClothTemplateTest < Test::Unit::TestCase
8
- setup do
9
- Tilt.register('markdown', Tilt::BlueClothTemplate)
10
- Tilt.register('md', Tilt::BlueClothTemplate)
11
- Tilt.register('mkd', Tilt::BlueClothTemplate)
8
+ test "registered for '.md' files" do
9
+ assert Tilt.mappings['md'].include?(Tilt::BlueClothTemplate)
12
10
  end
13
11
 
14
- teardown do
15
- # Need to revert to RDiscount, otherwise the RDiscount test will fail
16
- Tilt.register('markdown', Tilt::RDiscountTemplate)
17
- Tilt.register('md', Tilt::RDiscountTemplate)
18
- Tilt.register('mkd', Tilt::RDiscountTemplate)
12
+ test "registered for '.mkd' files" do
13
+ assert Tilt.mappings['mkd'].include?(Tilt::BlueClothTemplate)
19
14
  end
20
15
 
21
- test "registered for '.markdown' files unless RDiscount is loaded" do
22
- unless defined?(RDiscount)
23
- assert_equal Tilt::BlueClothTemplate, Tilt['test.markdown']
24
- end
25
- end
26
-
27
- test "registered for '.md' files unless RDiscount is loaded" do
28
- unless defined?(RDiscount)
29
- assert_equal Tilt::BlueClothTemplate, Tilt['test.md']
30
- end
31
- end
32
-
33
- test "registered for '.mkd' files unless RDiscount is loaded" do
34
- unless defined?(RDiscount)
35
- assert_equal Tilt::BlueClothTemplate, Tilt['test.mkd']
36
- end
16
+ test "registered for '.markdown' files" do
17
+ assert Tilt.mappings['markdown'].include?(Tilt::BlueClothTemplate)
37
18
  end
38
19
 
39
20
  test "preparing and evaluating templates on #render" do
@@ -20,9 +20,40 @@ begin
20
20
  end
21
21
 
22
22
  test "disabling coffee-script wrapper" do
23
- template = Tilt::CoffeeScriptTemplate.new(:no_wrap => true) { |t| "puts 'Hello, World!'\n" }
23
+ str = "puts 'Hello, World!'\n"
24
+
25
+ template = Tilt::CoffeeScriptTemplate.new(:bare => true) { str }
26
+ assert_equal "puts('Hello, World!');", template.render
27
+
28
+ template2 = Tilt::CoffeeScriptTemplate.new(:no_wrap => true) { str}
24
29
  assert_equal "puts('Hello, World!');", template.render
25
30
  end
31
+
32
+ context "disabling coffee-script wrapper globally" do
33
+ setup do
34
+ @bare = Tilt::CoffeeScriptTemplate.default_bare
35
+ end
36
+
37
+ teardown do
38
+ Tilt::CoffeeScriptTemplate.default_bare = @bare
39
+ end
40
+
41
+ test "no options" do
42
+ template = Tilt::CoffeeScriptTemplate.new { |t| "puts 'Hello, World!'\n" }
43
+ assert_match "puts('Hello, World!');", template.render
44
+ assert_match "(function() {", template.render
45
+ end
46
+
47
+ test "overridden by :bare" do
48
+ template = Tilt::CoffeeScriptTemplate.new(:bare => false) { "puts 'Hello, World!'\n" }
49
+ assert_not_equal "puts('Hello, World!');", template.render
50
+ end
51
+
52
+ test "overridden by :no_wrap" do
53
+ template = Tilt::CoffeeScriptTemplate.new(:no_wrap => false) { "puts 'Hello, World!'\n" }
54
+ assert_not_equal "puts('Hello, World!');", template.render
55
+ end
56
+ end
26
57
  end
27
58
 
28
59
  rescue LoadError => boom
@@ -0,0 +1,24 @@
1
+ require 'contest'
2
+ require 'tilt'
3
+
4
+ begin
5
+ require 'creole'
6
+
7
+ class CreoleTemplateTest < Test::Unit::TestCase
8
+ test "is registered for '.creole' files" do
9
+ assert_equal Tilt::CreoleTemplate, Tilt['test.creole']
10
+ end
11
+
12
+ test "compiles and evaluates the template on #render" do
13
+ template = Tilt::CreoleTemplate.new { |t| "= Hello World!" }
14
+ assert_equal "<h1>Hello World!</h1>", template.render
15
+ end
16
+
17
+ test "can be rendered more than once" do
18
+ template = Tilt::CreoleTemplate.new { |t| "= Hello World!" }
19
+ 3.times { assert_equal "<h1>Hello World!</h1>", template.render }
20
+ end
21
+ end
22
+ rescue LoadError => boom
23
+ warn "Tilt::CreoleTemplate (disabled)\n"
24
+ end
@@ -6,12 +6,11 @@ require 'tempfile'
6
6
 
7
7
  class ERBTemplateTest < Test::Unit::TestCase
8
8
  test "registered for '.erb' files" do
9
- assert_equal Tilt::ERBTemplate, Tilt['test.erb']
10
- assert_equal Tilt::ERBTemplate, Tilt['test.html.erb']
9
+ assert Tilt.mappings['erb'].include?(Tilt::ERBTemplate)
11
10
  end
12
11
 
13
12
  test "registered for '.rhtml' files" do
14
- assert_equal Tilt::ERBTemplate, Tilt['test.rhtml']
13
+ assert Tilt.mappings['rhtml'].include?(Tilt::ERBTemplate)
15
14
  end
16
15
 
17
16
  test "loading and evaluating templates on #render" do
@@ -67,9 +66,9 @@ class ERBTemplateTest < Test::Unit::TestCase
67
66
  fail 'should have raised an exception'
68
67
  rescue => boom
69
68
  assert_kind_of NameError, boom
70
- line = boom.backtrace.first
69
+ line = boom.backtrace.grep(/^test\.erb:/).first
70
+ assert line, "Backtrace didn't contain test.erb"
71
71
  file, line, meth = line.split(":")
72
- assert_equal 'test.erb', file
73
72
  assert_equal '13', line
74
73
  end
75
74
  end
@@ -90,18 +89,18 @@ class ERBTemplateTest < Test::Unit::TestCase
90
89
  end
91
90
  end
92
91
 
93
- test "default non-stripping trim mode" do
94
- template = Tilt.new('test.erb', 1) { "\n<%= 1 + 1 %>\n" }
95
- assert_equal "\n2\n", template.render
92
+ test "default stripping trim mode" do
93
+ template = Tilt::ERBTemplate.new('test.erb', 1) { "\n<%= 1 + 1 %>\n" }
94
+ assert_equal "\n2", template.render
96
95
  end
97
96
 
98
97
  test "stripping trim mode" do
99
- template = Tilt.new('test.erb', 1, :trim => '-') { "\n<%= 1 + 1 -%>\n" }
98
+ template = Tilt::ERBTemplate.new('test.erb', 1, :trim => '-') { "\n<%= 1 + 1 -%>\n" }
100
99
  assert_equal "\n2", template.render
101
100
  end
102
101
 
103
102
  test "shorthand whole line syntax trim mode" do
104
- template = Tilt.new('test.erb', :trim => '%') { "\n% if true\nhello\n%end\n" }
103
+ template = Tilt::ERBTemplate.new('test.erb', :trim => '%') { "\n% if true\nhello\n%end\n" }
105
104
  assert_equal "\nhello\n", template.render
106
105
  end
107
106
 
@@ -164,9 +163,9 @@ class CompiledERBTemplateTest < Test::Unit::TestCase
164
163
  fail 'should have raised an exception'
165
164
  rescue => boom
166
165
  assert_kind_of NameError, boom
167
- line = boom.backtrace.first
166
+ line = boom.backtrace.grep(/^test\.erb:/).first
167
+ assert line, "Backtrace didn't contain test.erb"
168
168
  file, line, meth = line.split(":")
169
- assert_equal 'test.erb', file
170
169
  assert_equal '13', line
171
170
  end
172
171
  end
@@ -187,18 +186,18 @@ class CompiledERBTemplateTest < Test::Unit::TestCase
187
186
  end
188
187
  end
189
188
 
190
- test "default non-stripping trim mode" do
191
- template = Tilt.new('test.erb') { "\n<%= 1 + 1 %>\n" }
192
- assert_equal "\n2\n", template.render(Scope.new)
189
+ test "default stripping trim mode" do
190
+ template = Tilt::ERBTemplate.new('test.erb') { "\n<%= 1 + 1 %>\n" }
191
+ assert_equal "\n2", template.render(Scope.new)
193
192
  end
194
193
 
195
194
  test "stripping trim mode" do
196
- template = Tilt.new('test.erb', :trim => '-') { "\n<%= 1 + 1 -%>\n" }
195
+ template = Tilt::ERBTemplate.new('test.erb', :trim => '-') { "\n<%= 1 + 1 -%>\n" }
197
196
  assert_equal "\n2", template.render(Scope.new)
198
197
  end
199
198
 
200
199
  test "shorthand whole line syntax trim mode" do
201
- template = Tilt.new('test.erb', :trim => '%') { "\n% if true\nhello\n%end\n" }
200
+ template = Tilt::ERBTemplate.new('test.erb', :trim => '%') { "\n% if true\nhello\n%end\n" }
202
201
  assert_equal "\nhello\n", template.render(Scope.new)
203
202
  end
204
203
 
@@ -208,7 +207,7 @@ class CompiledERBTemplateTest < Test::Unit::TestCase
208
207
  f.puts('ふが <%= @hoge %>')
209
208
  f.close()
210
209
  @hoge = "ほげ"
211
- erb = Tilt['erb'].new(f.path)
210
+ erb = Tilt::ERBTemplate.new(f.path)
212
211
  3.times { erb.render(self) }
213
212
  f.delete
214
213
  end
@@ -218,7 +217,7 @@ class CompiledERBTemplateTest < Test::Unit::TestCase
218
217
  f.puts('ふが <%= @hoge %>')
219
218
  f.close()
220
219
  @hoge = "ほげ"
221
- erb = Tilt['erb'].new(f.path, :default_encoding => 'UTF-8')
220
+ erb = Tilt::ERBTemplate.new(f.path, :default_encoding => 'UTF-8')
222
221
  3.times { erb.render(self) }
223
222
  f.delete
224
223
  end
@@ -9,6 +9,16 @@ begin
9
9
  assert_equal Tilt::ErubisTemplate, Tilt['test.html.erubis']
10
10
  end
11
11
 
12
+ test "registered above ERB" do
13
+ %w[erb rhtml].each do |ext|
14
+ mappings = Tilt.mappings[ext]
15
+ erubis_idx = mappings.index(Tilt::ErubisTemplate)
16
+ erb_idx = mappings.index(Tilt::ERBTemplate)
17
+ assert erubis_idx < erb_idx,
18
+ "#{erubis_idx} should be lower than #{erb_idx}"
19
+ end
20
+ end
21
+
12
22
  test "preparing and evaluating templates on #render" do
13
23
  template = Tilt::ErubisTemplate.new { |t| "Hello World!" }
14
24
  assert_equal "Hello World!", template.render
@@ -62,9 +72,9 @@ begin
62
72
  fail 'should have raised an exception'
63
73
  rescue => boom
64
74
  assert_kind_of NameError, boom
65
- line = boom.backtrace.first
75
+ line = boom.backtrace.grep(/^test\.erubis:/).first
76
+ assert line, "Backtrace didn't contain test.erubis"
66
77
  file, line, meth = line.split(":")
67
- assert_equal 'test.erubis', file
68
78
  assert_equal '13', line
69
79
  end
70
80
  end
@@ -0,0 +1,122 @@
1
+ require 'contest'
2
+ require 'tilt'
3
+
4
+ class TiltFallbackTest < Test::Unit::TestCase
5
+ class FailTemplate < Tilt::Template
6
+ def self.engine_initialized?; false end
7
+ def prepare; end
8
+
9
+ def initialize_engine
10
+ raise LoadError, "can't load #{self.class}"
11
+ end
12
+ end
13
+
14
+ class WinTemplate < Tilt::Template
15
+ def self.engine_initialized?; true end
16
+ def prepare; end
17
+ end
18
+
19
+ FailTemplate2 = Class.new(FailTemplate)
20
+ WinTemplate2 = Class.new(WinTemplate)
21
+
22
+ def set_ivar(obj, name, value)
23
+ obj.instance_variable_set("@#{name}", value)
24
+ end
25
+
26
+ def clear_ivar(obj, name)
27
+ ivar = "@#{name}"
28
+ value = obj.instance_variable_get(ivar)
29
+ ensure
30
+ obj.instance_variable_set(ivar, value.dup.clear)
31
+ end
32
+
33
+ setup do
34
+ # Make sure every test have no mappings.
35
+ @p = clear_ivar(Tilt, :preferred_mappings)
36
+ @t = clear_ivar(Tilt, :template_mappings)
37
+ end
38
+
39
+ teardown do
40
+ set_ivar(Tilt, :preferred_mappings, @p)
41
+ set_ivar(Tilt, :template_mappings, @t)
42
+ end
43
+
44
+ test "returns nil on unregistered extensions" do
45
+ template = Tilt["md"]
46
+ assert_equal nil, template
47
+ end
48
+
49
+ test "returns the last registered template" do
50
+ Tilt.register("md", WinTemplate)
51
+ Tilt.register("md", WinTemplate2)
52
+
53
+ template = Tilt["md"]
54
+ assert_equal WinTemplate2, template
55
+ end
56
+
57
+ test "returns the last registered working template" do
58
+ Tilt.register("md", WinTemplate)
59
+ Tilt.register("md", FailTemplate)
60
+
61
+ template = Tilt["md"]
62
+ assert_equal WinTemplate, template
63
+ end
64
+
65
+ test "if every template fails, raise the exception from the first template" do
66
+ Tilt.register("md", FailTemplate)
67
+ Tilt.register("md", FailTemplate2)
68
+
69
+ exc = assert_raise(LoadError) { Tilt["md"] }
70
+ assert_match /FailTemplate2/, exc.message
71
+ end
72
+
73
+ test ".prefer should also register the template" do
74
+ Tilt.prefer(WinTemplate, "md")
75
+ assert Tilt.registered?("md")
76
+ end
77
+
78
+ test ".prefer always win" do
79
+ Tilt.register("md", FailTemplate)
80
+ Tilt.register("md", WinTemplate)
81
+ Tilt.prefer(FailTemplate, "md")
82
+
83
+ template = Tilt["md"]
84
+ assert_equal FailTemplate, template
85
+ end
86
+
87
+ test ".prefer accepts multiple extensions" do
88
+ extensions = %w[md mkd markdown]
89
+ Tilt.prefer(FailTemplate, *extensions)
90
+
91
+ extensions.each do |ext|
92
+ template = Tilt[ext]
93
+ assert_equal FailTemplate, template
94
+ end
95
+ end
96
+
97
+ test ".prefer with no extension should use already registered extensions" do
98
+ extensions = %w[md mkd markdown]
99
+
100
+ extensions.each do |ext|
101
+ Tilt.register(ext, FailTemplate)
102
+ Tilt.register(ext, WinTemplate)
103
+ end
104
+
105
+ Tilt.prefer(FailTemplate)
106
+
107
+ extensions.each do |ext|
108
+ template = Tilt[ext]
109
+ assert_equal FailTemplate, template
110
+ end
111
+ end
112
+
113
+ test ".prefer should only override extensions the preferred library is registered for" do
114
+ Tilt.register("md", WinTemplate)
115
+ Tilt.register("mkd", FailTemplate)
116
+ Tilt.register("mkd", WinTemplate)
117
+ Tilt.prefer(FailTemplate)
118
+ assert_equal FailTemplate, Tilt["mkd"]
119
+ assert_equal WinTemplate, Tilt["md"]
120
+ end
121
+ end
122
+
@@ -48,9 +48,9 @@ begin
48
48
  fail 'should have raised an exception'
49
49
  rescue => boom
50
50
  assert_kind_of NameError, boom
51
- line = boom.backtrace.first
51
+ line = boom.backtrace.grep(/^test\.haml:/).first
52
+ assert line, "Backtrace didn't contain test.haml"
52
53
  file, line, meth = line.split(":")
53
- assert_equal 'test.haml', file
54
54
  assert_equal '12', line
55
55
  end
56
56
  end
@@ -108,9 +108,9 @@ begin
108
108
  fail 'should have raised an exception'
109
109
  rescue => boom
110
110
  assert_kind_of NameError, boom
111
- line = boom.backtrace.first
111
+ line = boom.backtrace.grep(/^test\.haml:/).first
112
+ assert line, "Backtrace didn't contain test.haml"
112
113
  file, line, meth = line.split(":")
113
- assert_equal 'test.haml', file
114
114
  assert_equal '12', line
115
115
  end
116
116
  end
@@ -0,0 +1,42 @@
1
+ require 'contest'
2
+ require 'tilt'
3
+
4
+ begin
5
+ require 'kramdown'
6
+
7
+ class MarukuTemplateTest < Test::Unit::TestCase
8
+ test "registered for '.md' files" do
9
+ assert Tilt.mappings['md'].include?(Tilt::KramdownTemplate)
10
+ end
11
+
12
+ test "registered for '.mkd' files" do
13
+ assert Tilt.mappings['mkd'].include?(Tilt::KramdownTemplate)
14
+ end
15
+
16
+ test "registered for '.markdown' files" do
17
+ assert Tilt.mappings['markdown'].include?(Tilt::KramdownTemplate)
18
+ end
19
+
20
+ test "registered above MarukuTemplate" do
21
+ %w[md mkd markdown].each do |ext|
22
+ mappings = Tilt.mappings[ext]
23
+ kram_idx = mappings.index(Tilt::KramdownTemplate)
24
+ maru_idx = mappings.index(Tilt::MarukuTemplate)
25
+ assert kram_idx < maru_idx,
26
+ "#{kram_idx} should be lower than #{maru_idx}"
27
+ end
28
+ end
29
+
30
+ test "preparing and evaluating templates on #render" do
31
+ template = Tilt::KramdownTemplate.new { |t| "# Hello World!" }
32
+ assert_equal "<h1 id='hello_world'>Hello World!</h1>", template.render
33
+ end
34
+
35
+ test "can be rendered more than once" do
36
+ template = Tilt::KramdownTemplate.new { |t| "# Hello World!" }
37
+ 3.times { assert_equal "<h1 id='hello_world'>Hello World!</h1>", template.render }
38
+ end
39
+ end
40
+ rescue LoadError => boom
41
+ warn "Tilt::KramdownTemplate (disabled)\n"
42
+ end
@@ -0,0 +1,148 @@
1
+ # coding: UTF-8
2
+ require 'tilt'
3
+ require 'nokogiri'
4
+
5
+ module MarkdownTests
6
+ def self.included(mod)
7
+ class << mod
8
+ def template(t = nil)
9
+ t.nil? ? @template : @template = t
10
+ end
11
+ end
12
+ end
13
+
14
+ def render(text, options = {})
15
+ self.class.template.new(options) { text }.render
16
+ end
17
+
18
+ def normalize(html)
19
+ Nokogiri::HTML.fragment(html).to_s
20
+ end
21
+
22
+ def nrender(text, options = {})
23
+ html = render(text, options)
24
+ html.encode!("UTF-8") if html.respond_to?(:encode)
25
+ normalize(html)
26
+ end
27
+
28
+ def test_escape_html
29
+ html = nrender "Hello <b>World</b>"
30
+ assert_equal "<p>Hello <b>World</b></p>", html
31
+ end
32
+
33
+ def test_escape_html_false
34
+ html = nrender "Hello <b>World</b>", :escape_html => false
35
+ assert_equal "<p>Hello <b>World</b></p>", html
36
+ end
37
+
38
+ def test_escape_html_true
39
+ if self.class.template == Tilt::RedcarpetTemplate
40
+ flunk "redcarpet doesn't support :escape_html yet"
41
+ end
42
+ html = nrender "Hello <b>World</b>", :escape_html => true
43
+ assert_equal "<p>Hello &lt;b&gt;World&lt;/b&gt;</p>", html
44
+ end
45
+
46
+ def test_smart_quotes
47
+ html = nrender 'Hello "World"'
48
+ assert_equal '<p>Hello "World"</p>', html
49
+ end
50
+
51
+ def test_smart_quotes_false
52
+ html = nrender 'Hello "World"', :smartypants => false
53
+ assert_equal '<p>Hello "World"</p>', html
54
+ end
55
+
56
+ def test_smart_quotes_true
57
+ html = nrender 'Hello "World"', :smartypants => true
58
+ assert_equal '<p>Hello “World”</p>', html
59
+ end
60
+
61
+ def test_smarty_pants
62
+ html = nrender "Hello ``World'' -- This is --- a test ..."
63
+ assert_equal "<p>Hello ``World'' -- This is --- a test ...</p>", html
64
+ end
65
+
66
+ def test_smarty_pants_false
67
+ html = nrender "Hello ``World'' -- This is --- a test ...", :smartypants => false
68
+ assert_equal "<p>Hello ``World'' -- This is --- a test ...</p>", html
69
+ end
70
+
71
+ def test_smarty_pants_true
72
+ html = nrender "Hello ``World'' -- This is --- a test ...", :smartypants => true
73
+ assert_equal "<p>Hello “World” — This is —– a test …</p>", html
74
+ end
75
+ end
76
+
77
+ begin
78
+ require 'rdiscount'
79
+
80
+ class MarkdownRDiscountTest < Test::Unit::TestCase
81
+ include MarkdownTests
82
+ template Tilt::RDiscountTemplate
83
+ end
84
+ rescue LoadError => boom
85
+ # It should already be warned in the main tests
86
+ end
87
+
88
+ begin
89
+ require 'redcarpet'
90
+
91
+ class MarkdownRedcarpetTest < Test::Unit::TestCase
92
+ include MarkdownTests
93
+ template Tilt::RedcarpetTemplate
94
+ end
95
+ rescue LoadError => boom
96
+ # It should already be warned in the main tests
97
+ end
98
+
99
+ begin
100
+ require 'bluecloth'
101
+
102
+ class MarkdownBlueClothTest < Test::Unit::TestCase
103
+ include MarkdownTests
104
+ template Tilt::BlueClothTemplate
105
+ end
106
+ rescue LoadError => boom
107
+ # It should already be warned in the main tests
108
+ end
109
+
110
+ begin
111
+ require 'kramdown'
112
+
113
+ class MarkdownKramdownTest < Test::Unit::TestCase
114
+ include MarkdownTests
115
+ template Tilt::KramdownTemplate
116
+ # Doesn't support escaping
117
+ undef test_escape_html_true
118
+ # Smarty Pants is *always* on, but doesn't support it fully
119
+ undef test_smarty_pants
120
+ undef test_smarty_pants_false
121
+ undef test_smarty_pants_true
122
+ end
123
+ rescue LoadError => boom
124
+ # It should already be warned in the main tests
125
+ end
126
+
127
+
128
+ begin
129
+ require 'maruku'
130
+
131
+ class MarkdownMarukuTest < Test::Unit::TestCase
132
+ include MarkdownTests
133
+ template Tilt::MarukuTemplate
134
+ # Doesn't support escaping
135
+ undef test_escape_html_true
136
+ # Doesn't support Smarty Pants, and even fails on ``Foobar''
137
+ undef test_smarty_pants
138
+ undef test_smarty_pants_false
139
+ undef test_smarty_pants_true
140
+ # Smart Quotes is always on
141
+ undef test_smart_quotes
142
+ undef test_smart_quotes_false
143
+ end
144
+ rescue LoadError => boom
145
+ # It should already be warned in the main tests
146
+ end
147
+
148
+
@@ -0,0 +1,48 @@
1
+ require 'contest'
2
+ require 'tilt'
3
+
4
+ begin
5
+ require 'maruku'
6
+
7
+ class MarukuTemplateTest < Test::Unit::TestCase
8
+ test "registered for '.md' files" do
9
+ assert Tilt.mappings['md'].include?(Tilt::MarukuTemplate)
10
+ end
11
+
12
+ test "registered for '.mkd' files" do
13
+ assert Tilt.mappings['mkd'].include?(Tilt::MarukuTemplate)
14
+ end
15
+
16
+ test "registered for '.markdown' files" do
17
+ assert Tilt.mappings['markdown'].include?(Tilt::MarukuTemplate)
18
+ end
19
+
20
+ test "registered below Kramdown" do
21
+ %w[md mkd markdown].each do |ext|
22
+ mappings = Tilt.mappings[ext]
23
+ kram_idx = mappings.index(Tilt::KramdownTemplate)
24
+ maru_idx = mappings.index(Tilt::MarukuTemplate)
25
+ assert maru_idx > kram_idx,
26
+ "#{maru_idx} should be higher than #{kram_idx}"
27
+ end
28
+ end
29
+
30
+ test "preparing and evaluating templates on #render" do
31
+ template = Tilt::MarukuTemplate.new { |t| "# Hello World!" }
32
+ assert_equal "<h1 id='hello_world'>Hello World!</h1>", template.render
33
+ end
34
+
35
+ test "can be rendered more than once" do
36
+ template = Tilt::MarukuTemplate.new { |t| "# Hello World!" }
37
+ 3.times { assert_equal "<h1 id='hello_world'>Hello World!</h1>", template.render }
38
+ end
39
+
40
+ test "removes HTML when :filter_html is set" do
41
+ template = Tilt::MarukuTemplate.new(:filter_html => true) { |t|
42
+ "HELLO <blink>WORLD</blink>" }
43
+ assert_equal "<p>HELLO </p>", template.render
44
+ end
45
+ end
46
+ rescue LoadError => boom
47
+ warn "Tilt::MarukuTemplate (disabled)\n"
48
+ end
@@ -70,6 +70,17 @@ begin
70
70
  assert_equal 'strong', doc.root.name
71
71
  end
72
72
  end
73
+
74
+ test "doesn't modify self when template is a string" do
75
+ template = Tilt::NokogiriTemplate.new { "xml.root { xml.child @hello }" }
76
+ scope = Object.new
77
+ scope.instance_variable_set(:@hello, "Hello World!")
78
+
79
+ 3.times do
80
+ doc = Nokogiri.XML(template.render(scope))
81
+ assert_equal "Hello World!", doc.text.strip
82
+ end
83
+ end
73
84
  end
74
85
  rescue LoadError
75
86
  warn "Tilt::NokogiriTemplate (disabled)"
@@ -5,16 +5,26 @@ begin
5
5
  require 'rdiscount'
6
6
 
7
7
  class RDiscountTemplateTest < Test::Unit::TestCase
8
- test "registered for '.markdown' files" do
9
- assert_equal Tilt::RDiscountTemplate, Tilt['test.markdown']
10
- end
11
-
12
8
  test "registered for '.md' files" do
13
- assert_equal Tilt::RDiscountTemplate, Tilt['test.md']
9
+ assert Tilt.mappings['md'].include?(Tilt::RDiscountTemplate)
14
10
  end
15
11
 
16
12
  test "registered for '.mkd' files" do
17
- assert_equal Tilt::RDiscountTemplate, Tilt['test.mkd']
13
+ assert Tilt.mappings['mkd'].include?(Tilt::RDiscountTemplate)
14
+ end
15
+
16
+ test "registered for '.markdown' files" do
17
+ assert Tilt.mappings['markdown'].include?(Tilt::RDiscountTemplate)
18
+ end
19
+
20
+ test "registered above BlueCloth" do
21
+ %w[md mkd markdown].each do |ext|
22
+ mappings = Tilt.mappings[ext]
23
+ blue_idx = mappings.index(Tilt::BlueClothTemplate)
24
+ rdis_idx = mappings.index(Tilt::RDiscountTemplate)
25
+ assert rdis_idx < blue_idx,
26
+ "#{rdis_idx} should be lower than #{blue_idx}"
27
+ end
18
28
  end
19
29
 
20
30
  test "preparing and evaluating templates on #render" do