tilt 2.0.8 → 2.0.11

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.
Files changed (73) hide show
  1. checksums.yaml +5 -5
  2. data/lib/tilt/commonmarker.rb +68 -1
  3. data/lib/tilt/csv.rb +1 -1
  4. data/lib/tilt/erb.rb +7 -1
  5. data/lib/tilt/haml.rb +2 -2
  6. data/lib/tilt/pandoc.rb +23 -15
  7. data/lib/tilt/redcarpet.rb +5 -2
  8. data/lib/tilt/rst-pandoc.rb +12 -7
  9. data/lib/tilt/sass.rb +40 -3
  10. data/lib/tilt/template.rb +18 -12
  11. data/lib/tilt.rb +2 -1
  12. metadata +8 -110
  13. data/CHANGELOG.md +0 -127
  14. data/Gemfile +0 -65
  15. data/HACKING +0 -16
  16. data/README.md +0 -233
  17. data/Rakefile +0 -106
  18. data/docs/TEMPLATES.md +0 -555
  19. data/docs/common.css +0 -14
  20. data/man/index.txt +0 -2
  21. data/man/tilt.1.ronn +0 -59
  22. data/test/markaby/locals.mab +0 -1
  23. data/test/markaby/markaby.mab +0 -1
  24. data/test/markaby/markaby_other_static.mab +0 -1
  25. data/test/markaby/render_twice.mab +0 -1
  26. data/test/markaby/scope.mab +0 -1
  27. data/test/markaby/yielding.mab +0 -2
  28. data/test/mytemplate.rb +0 -2
  29. data/test/test_helper.rb +0 -64
  30. data/test/tilt_asciidoctor_test.rb +0 -50
  31. data/test/tilt_babeltemplate.rb +0 -33
  32. data/test/tilt_blueclothtemplate_test.rb +0 -33
  33. data/test/tilt_buildertemplate_test.rb +0 -72
  34. data/test/tilt_cache_test.rb +0 -43
  35. data/test/tilt_coffeescripttemplate_test.rb +0 -141
  36. data/test/tilt_commonmarkertemplate_test.rb +0 -20
  37. data/test/tilt_compilesite_test.rb +0 -51
  38. data/test/tilt_creoletemplate_test.rb +0 -24
  39. data/test/tilt_csv_test.rb +0 -77
  40. data/test/tilt_erbtemplate_test.rb +0 -239
  41. data/test/tilt_erubistemplate_test.rb +0 -151
  42. data/test/tilt_erubitemplate_test.rb +0 -158
  43. data/test/tilt_etannitemplate_test.rb +0 -174
  44. data/test/tilt_hamltemplate_test.rb +0 -166
  45. data/test/tilt_kramdown_test.rb +0 -20
  46. data/test/tilt_lesstemplate_test.less +0 -1
  47. data/test/tilt_lesstemplate_test.rb +0 -42
  48. data/test/tilt_liquidtemplate_test.rb +0 -87
  49. data/test/tilt_livescripttemplate_test.rb +0 -37
  50. data/test/tilt_mapping_test.rb +0 -232
  51. data/test/tilt_markaby_test.rb +0 -88
  52. data/test/tilt_markdown_test.rb +0 -186
  53. data/test/tilt_marukutemplate_test.rb +0 -36
  54. data/test/tilt_metadata_test.rb +0 -42
  55. data/test/tilt_nokogiritemplate_test.rb +0 -87
  56. data/test/tilt_pandoctemplate_test.rb +0 -67
  57. data/test/tilt_prawntemplate.prawn +0 -1
  58. data/test/tilt_prawntemplate_test.rb +0 -75
  59. data/test/tilt_radiustemplate_test.rb +0 -75
  60. data/test/tilt_rdiscounttemplate_test.rb +0 -43
  61. data/test/tilt_rdoctemplate_test.rb +0 -29
  62. data/test/tilt_redcarpettemplate_test.rb +0 -54
  63. data/test/tilt_redclothtemplate_test.rb +0 -36
  64. data/test/tilt_rstpandoctemplate_test.rb +0 -32
  65. data/test/tilt_sasstemplate_test.rb +0 -41
  66. data/test/tilt_sigil_test.rb +0 -41
  67. data/test/tilt_stringtemplate_test.rb +0 -171
  68. data/test/tilt_template_test.rb +0 -314
  69. data/test/tilt_test.rb +0 -60
  70. data/test/tilt_typescript_test.rb +0 -38
  71. data/test/tilt_wikiclothtemplate_test.rb +0 -32
  72. data/test/tilt_yajltemplate_test.rb +0 -101
  73. data/tilt.gemspec +0 -130
@@ -1,232 +0,0 @@
1
- require 'test_helper'
2
- require 'tilt'
3
- require 'tilt/mapping'
4
-
5
- module Tilt
6
-
7
- class MappingTest < Minitest::Test
8
- class Stub
9
- end
10
-
11
- class Stub2
12
- end
13
-
14
- setup do
15
- @mapping = Mapping.new
16
- end
17
-
18
- test "registered?" do
19
- @mapping.register(Stub, 'foo', 'bar')
20
- assert @mapping.registered?('foo')
21
- assert @mapping.registered?('bar')
22
- refute @mapping.registered?('baz')
23
- end
24
-
25
- test "lookups on registered" do
26
- @mapping.register(Stub, 'foo', 'bar')
27
- assert_equal Stub, @mapping['foo']
28
- assert_equal Stub, @mapping['bar']
29
- assert_equal Stub, @mapping['hello.foo']
30
- assert_nil @mapping['foo.baz']
31
- end
32
-
33
- test "can be dup'd" do
34
- @mapping.register(Stub, 'foo')
35
- other = @mapping.dup
36
- assert other.registered?('foo')
37
-
38
- # @mapping doesn't leak to other
39
- @mapping.register(Stub, 'bar')
40
- refute other.registered?('bar')
41
-
42
- # other doesn't leak to @mapping
43
- other.register(Stub, 'baz')
44
- refute @mapping.registered?('baz')
45
- end
46
-
47
- test "#extensions_for" do
48
- @mapping.register(Stub, 'foo', 'bar')
49
- assert_equal ['foo', 'bar'].sort, @mapping.extensions_for(Stub).sort
50
- end
51
-
52
- test "supports old-style #register" do
53
- @mapping.register('foo', Stub)
54
- assert_equal Stub, @mapping['foo']
55
- end
56
-
57
- context "lazy with one template class" do
58
- setup do
59
- @mapping.register_lazy('MyTemplate', 'my_template', 'mt')
60
- @loaded_before = $LOADED_FEATURES.dup
61
- end
62
-
63
- teardown do
64
- Object.send :remove_const, :MyTemplate if defined? ::MyTemplate
65
- $LOADED_FEATURES.replace(@loaded_before)
66
- end
67
-
68
- test "registered?" do
69
- assert @mapping.registered?('mt')
70
- end
71
-
72
- test "#extensions_for" do
73
- assert_equal ['mt'], @mapping.extensions_for('MyTemplate')
74
- end
75
-
76
- test "basic lookup" do
77
- req = proc do |file|
78
- assert_equal 'my_template', file
79
- class ::MyTemplate; end
80
- true
81
- end
82
-
83
- @mapping.stub :require, req do
84
- klass = @mapping['hello.mt']
85
- assert_equal ::MyTemplate, klass
86
- end
87
- end
88
-
89
- test "doesn't require when template class is present" do
90
- class ::MyTemplate; end
91
-
92
- req = proc do |file|
93
- flunk "#require shouldn't be called"
94
- end
95
-
96
- @mapping.stub :require, req do
97
- klass = @mapping['hello.mt']
98
- assert_equal ::MyTemplate, klass
99
- end
100
- end
101
-
102
- test "doesn't require when the template class is autoloaded, and then defined" do
103
- Object.autoload :MyTemplate, 'mytemplate'
104
- did_load = require 'mytemplate'
105
- assert did_load, "mytemplate wasn't freshly required"
106
-
107
- req = proc do |file|
108
- flunk "#require shouldn't be called"
109
- end
110
-
111
- @mapping.stub :require, req do
112
- klass = @mapping['hello.mt']
113
- assert_equal ::MyTemplate, klass
114
- end
115
- end
116
-
117
- test "raises NameError when the class name is defined" do
118
- req = proc do |file|
119
- # do nothing
120
- end
121
-
122
- @mapping.stub :require, req do
123
- assert_raises(NameError) do
124
- @mapping['hello.mt']
125
- end
126
- end
127
- end
128
- end
129
-
130
- context "lazy with two template classes" do
131
- setup do
132
- @mapping.register_lazy('MyTemplate1', 'my_template1', 'mt')
133
- @mapping.register_lazy('MyTemplate2', 'my_template2', 'mt')
134
- end
135
-
136
- teardown do
137
- Object.send :remove_const, :MyTemplate1 if defined? ::MyTemplate1
138
- Object.send :remove_const, :MyTemplate2 if defined? ::MyTemplate2
139
- end
140
-
141
- test "registered?" do
142
- assert @mapping.registered?('mt')
143
- end
144
-
145
- test "only attempt to load the last template" do
146
- req = proc do |file|
147
- assert_equal 'my_template2', file
148
- class ::MyTemplate2; end
149
- true
150
- end
151
-
152
- @mapping.stub :require, req do
153
- klass = @mapping['hello.mt']
154
- assert_equal ::MyTemplate2, klass
155
- end
156
- end
157
-
158
- test "uses the first template if it's present" do
159
- class ::MyTemplate1; end
160
-
161
- req = proc do |file|
162
- flunk
163
- end
164
-
165
- @mapping.stub :require, req do
166
- klass = @mapping['hello.mt']
167
- assert_equal ::MyTemplate1, klass
168
- end
169
- end
170
-
171
- test "falls back when LoadError is thrown" do
172
- req = proc do |file|
173
- raise LoadError unless file == 'my_template1'
174
- class ::MyTemplate1; end
175
- true
176
- end
177
-
178
- @mapping.stub :require, req do
179
- klass = @mapping['hello.mt']
180
- assert_equal ::MyTemplate1, klass
181
- end
182
- end
183
-
184
- test "raises the first LoadError when everything fails" do
185
- req = proc do |file|
186
- raise LoadError, file
187
- end
188
-
189
- @mapping.stub :require, req do
190
- err = assert_raises(LoadError) do
191
- @mapping['hello.mt']
192
- end
193
-
194
- assert_equal 'my_template2', err.message
195
- end
196
- end
197
-
198
- test "handles autoloaded constants" do
199
- Object.autoload :MyTemplate2, 'my_template2'
200
- class ::MyTemplate1; end
201
-
202
- assert_equal MyTemplate1, @mapping['hello.mt']
203
- end
204
- end
205
-
206
- test "raises NameError on invalid class name" do
207
- @mapping.register_lazy '#foo', 'my_template', 'mt'
208
-
209
- req = proc do |file|
210
- # do nothing
211
- end
212
-
213
- @mapping.stub :require, req do
214
- assert_raises(NameError) do
215
- @mapping['hello.mt']
216
- end
217
- end
218
- end
219
-
220
- context "#templates_for" do
221
- setup do
222
- @mapping.register Stub, 'a'
223
- @mapping.register Stub2, 'b'
224
- end
225
-
226
- test "handles multiple engines" do
227
- assert_equal [Stub2, Stub], @mapping.templates_for('hello/world.a.b')
228
- end
229
- end
230
- end
231
- end
232
-
@@ -1,88 +0,0 @@
1
- require 'test_helper'
2
- require 'tilt'
3
-
4
- begin
5
- require 'tilt/markaby'
6
-
7
- class MarkabyTiltTest < Minitest::Test
8
- def setup
9
- @block = lambda do |t|
10
- File.read(File.dirname(__FILE__) + "/#{t.file}")
11
- end
12
- end
13
-
14
- test "should be able to render a markaby template with static html" do
15
- tilt = Tilt::MarkabyTemplate.new("markaby/markaby.mab", &@block)
16
- assert_equal "hello from markaby!", tilt.render
17
- end
18
-
19
- test "should use the contents of the template" do
20
- tilt = ::Tilt::MarkabyTemplate.new("markaby/markaby_other_static.mab", &@block)
21
- assert_equal "_why?", tilt.render
22
- end
23
-
24
- test "should render from a string (given as data)" do
25
- tilt = ::Tilt::MarkabyTemplate.new { "html do; end" }
26
- assert_equal "<html></html>", tilt.render
27
- end
28
-
29
- test "can be rendered more than once" do
30
- tilt = ::Tilt::MarkabyTemplate.new { "html do; end" }
31
- 3.times { assert_equal "<html></html>", tilt.render }
32
- end
33
-
34
- test "should evaluate a template file in the scope given" do
35
- scope = Object.new
36
- def scope.foo
37
- "bar"
38
- end
39
-
40
- tilt = ::Tilt::MarkabyTemplate.new("markaby/scope.mab", &@block)
41
- assert_equal "<li>bar</li>", tilt.render(scope)
42
- end
43
-
44
- test "should pass locals to the template" do
45
- tilt = ::Tilt::MarkabyTemplate.new("markaby/locals.mab", &@block)
46
- assert_equal "<li>bar</li>", tilt.render(Object.new, { :foo => "bar" })
47
- end
48
-
49
- test "should yield to the block given" do
50
- tilt = ::Tilt::MarkabyTemplate.new("markaby/yielding.mab", &@block)
51
- eval_scope = Markaby::Builder.new
52
-
53
- output = tilt.render(Object.new, {}) do
54
- text("Joe")
55
- end
56
-
57
- assert_equal "Hey Joe", output
58
- end
59
-
60
- test "should be able to render two templates in a row" do
61
- tilt = ::Tilt::MarkabyTemplate.new("markaby/render_twice.mab", &@block)
62
-
63
- assert_equal "foo", tilt.render
64
- assert_equal "foo", tilt.render
65
- end
66
-
67
- test "should retrieve a Tilt::MarkabyTemplate when calling Tilt['hello.mab']" do
68
- assert_equal Tilt::MarkabyTemplate, ::Tilt['./markaby/markaby.mab']
69
- end
70
-
71
- test "should return a new instance of the implementation class (when calling Tilt.new)" do
72
- assert ::Tilt.new(File.dirname(__FILE__) + "/markaby/markaby.mab").kind_of?(Tilt::MarkabyTemplate)
73
- end
74
-
75
- test "should be able to evaluate block style templates" do
76
- tilt = Tilt::MarkabyTemplate.new { |t| lambda { h1 "Hello World!" }}
77
- assert_equal "<h1>Hello World!</h1>", tilt.render
78
- end
79
-
80
- test "should pass locals to block style templates" do
81
- tilt = Tilt::MarkabyTemplate.new { |t| lambda { h1 "Hello #{name}!" }}
82
- assert_equal "<h1>Hello _why!</h1>", tilt.render(nil, :name => "_why")
83
- end
84
- end
85
-
86
- rescue LoadError
87
- warn "Tilt::MarkabyTemplate (disabled)"
88
- end
@@ -1,186 +0,0 @@
1
- # coding: UTF-8
2
- require 'tilt'
3
- require 'test_helper'
4
-
5
- begin
6
- require 'nokogiri'
7
-
8
- module MarkdownTests
9
- def self.included(mod)
10
- class << mod
11
- def template(t = nil)
12
- t.nil? ? @template : @template = t
13
- end
14
- end
15
- end
16
-
17
- def render(text, options = {})
18
- self.class.template.new(options) { text }.render
19
- end
20
-
21
- def normalize(html)
22
- Nokogiri::HTML.fragment(html).to_s.strip
23
- end
24
-
25
- def nrender(text, options = {})
26
- html = render(text, options)
27
- html.encode!("UTF-8") if html.respond_to?(:encode)
28
- normalize(html)
29
- end
30
-
31
- def test_escape_html
32
- html = nrender "Hello <b>World</b>"
33
- assert_equal "<p>Hello <b>World</b></p>", html
34
- end
35
-
36
- def test_escape_html_false
37
- html = nrender "Hello <b>World</b>", :escape_html => false
38
- assert_equal "<p>Hello <b>World</b></p>", html
39
- end
40
-
41
- def test_escape_html_true
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
- end
71
-
72
- begin
73
- require 'tilt/rdiscount'
74
-
75
- class MarkdownRDiscountTest < Minitest::Test
76
- include MarkdownTests
77
- template Tilt::RDiscountTemplate
78
-
79
- def test_smarty_pants_true
80
- html = nrender "Hello ``World'' -- This is --- a test ...", :smartypants => true
81
- assert_equal "<p>Hello “World” – This is — a test …</p>", html
82
- end
83
- end
84
- rescue LoadError => boom
85
- # It should already be warned in the main tests
86
- end
87
-
88
- begin
89
- require 'tilt/redcarpet'
90
-
91
- class MarkdownRedcarpetTest < Minitest::Test
92
- include MarkdownTests
93
- template Tilt::RedcarpetTemplate
94
-
95
- def test_smarty_pants_true
96
- # Various versions of Redcarpet support various versions of Smart pants.
97
- html = nrender "Hello ``World'' -- This is --- a test ...", :smartypants => true
98
- assert_match %r!<p>Hello “World(''|”) – This is — a test …<\/p>!, html
99
- end
100
-
101
- def test_renderer_options
102
- html = nrender "Hello [World](http://example.com)", :smartypants => true, :no_links => true
103
- assert_equal "<p>Hello [World](http://example.com)</p>", html
104
- end
105
-
106
- def test_fenced_code_blocks_with_lang
107
- code = <<-COD.gsub(/^\s+/,"")
108
- ```ruby
109
- puts "hello world"
110
- ```
111
- COD
112
-
113
- html = nrender code, :fenced_code_blocks => true
114
- assert_equal %Q{<pre><code class="ruby">puts "hello world"\n</code></pre>}, html
115
- end
116
- end
117
- rescue LoadError => boom
118
- # It should already be warned in the main tests
119
- end
120
-
121
- begin
122
- require 'tilt/bluecloth'
123
-
124
- class MarkdownBlueClothTest < Minitest::Test
125
- include MarkdownTests
126
- template Tilt::BlueClothTemplate
127
-
128
- def test_smarty_pants_true
129
- html = nrender "Hello ``World'' -- This is --- a test ...", :smartypants => true
130
- assert_equal "<p>Hello “World” — This is —– a test …</p>", html
131
- end
132
- end
133
- rescue LoadError => boom
134
- # It should already be warned in the main tests
135
- end
136
-
137
- begin
138
- require 'tilt/kramdown'
139
-
140
- class MarkdownKramdownTest < Minitest::Test
141
- include MarkdownTests
142
- template Tilt::KramdownTemplate
143
- # Doesn't support escaping
144
- undef test_escape_html_true
145
- # Smarty Pants is *always* on, but doesn't support it fully
146
- undef test_smarty_pants
147
- undef test_smarty_pants_false
148
- end
149
- rescue LoadError => boom
150
- # It should already be warned in the main tests
151
- end
152
-
153
-
154
- begin
155
- require 'tilt/maruku'
156
-
157
- class MarkdownMarukuTest < Minitest::Test
158
- include MarkdownTests
159
- template Tilt::MarukuTemplate
160
- # Doesn't support escaping
161
- undef test_escape_html_true
162
- # Doesn't support Smarty Pants, and even fails on ``Foobar''
163
- undef test_smarty_pants
164
- undef test_smarty_pants_false
165
- # Smart Quotes is always on
166
- undef test_smart_quotes
167
- undef test_smart_quotes_false
168
- end
169
- rescue LoadError => boom
170
- # It should already be warned in the main tests
171
- end
172
-
173
- rescue LoadError
174
- warn "Markdown tests need Nokogiri"
175
- end
176
-
177
- begin
178
- require 'tilt/pandoc'
179
-
180
- class MarkdownPandocTest < Minitest::Test
181
- include MarkdownTests
182
- template Tilt::PandocTemplate
183
- end
184
- rescue LoadError => boom
185
- # It should already be warned in the main tests
186
- end
@@ -1,36 +0,0 @@
1
- require 'test_helper'
2
- require 'tilt'
3
-
4
- begin
5
- require 'tilt/maruku'
6
-
7
- class MarukuTemplateTest < Minitest::Test
8
- test "registered below Kramdown" do
9
- %w[md mkd markdown].each do |ext|
10
- lazy = Tilt.lazy_map[ext]
11
- kram_idx = lazy.index { |klass, file| klass == 'Tilt::KramdownTemplate' }
12
- maru_idx = lazy.index { |klass, file| klass == 'Tilt::MarukuTemplate' }
13
- assert maru_idx > kram_idx,
14
- "#{maru_idx} should be higher than #{kram_idx}"
15
- end
16
- end
17
-
18
- test "preparing and evaluating templates on #render" do
19
- template = Tilt::MarukuTemplate.new { |t| "# Hello World!" }
20
- assert_equal "<h1 id=\"hello_world\">Hello World!</h1>", template.render.strip
21
- end
22
-
23
- test "can be rendered more than once" do
24
- template = Tilt::MarukuTemplate.new { |t| "# Hello World!" }
25
- 3.times { assert_equal "<h1 id=\"hello_world\">Hello World!</h1>", template.render.strip }
26
- end
27
-
28
- test "removes HTML when :filter_html is set" do
29
- template = Tilt::MarukuTemplate.new(:filter_html => true) { |t|
30
- "HELLO <blink>WORLD</blink>" }
31
- assert_equal "<p>HELLO</p>", template.render.strip
32
- end
33
- end
34
- rescue LoadError
35
- warn "Tilt::MarukuTemplate (disabled)"
36
- end
@@ -1,42 +0,0 @@
1
- require 'test_helper'
2
- require 'tilt/template'
3
-
4
- module Tilt
5
- class TemplateMetadataTest < Minitest::Test
6
- class MyTemplate < Template
7
- metadata[:global] = 1
8
- self.default_mime_type = 'text/html'
9
-
10
- def prepare
11
- end
12
-
13
- def allows_script?
14
- true
15
- end
16
- end
17
-
18
- test "global metadata" do
19
- assert MyTemplate.metadata
20
- assert_equal 1, MyTemplate.metadata[:global]
21
- end
22
-
23
- test "instance metadata" do
24
- tmpl = MyTemplate.new { '' }
25
- assert_equal 1, tmpl.metadata[:global]
26
- end
27
-
28
- test "gracefully handles default_mime_type" do
29
- assert_equal 'text/html', MyTemplate.metadata[:mime_type]
30
- end
31
-
32
- test "still allows .default_mime_type" do
33
- assert_equal 'text/html', MyTemplate.default_mime_type
34
- end
35
-
36
- test "gracefully handles allows_script?" do
37
- tmpl = MyTemplate.new { '' }
38
- assert_equal true, tmpl.metadata[:allows_script]
39
- end
40
- end
41
- end
42
-
@@ -1,87 +0,0 @@
1
- require 'test_helper'
2
- require 'tilt'
3
-
4
- begin
5
- require 'tilt/nokogiri'
6
- class NokogiriTemplateTest < Minitest::Test
7
- test "registered for '.nokogiri' files" do
8
- assert_equal Tilt::NokogiriTemplate, Tilt['test.nokogiri']
9
- assert_equal Tilt::NokogiriTemplate, Tilt['test.xml.nokogiri']
10
- end
11
-
12
- test "preparing and evaluating the template on #render" do
13
- template = Tilt::NokogiriTemplate.new { |t| "xml.em 'Hello World!'" }
14
- doc = Nokogiri.XML template.render
15
- assert_equal 'Hello World!', doc.root.text
16
- assert_equal 'em', doc.root.name
17
- end
18
-
19
- test "can be rendered more than once" do
20
- template = Tilt::NokogiriTemplate.new { |t| "xml.em 'Hello World!'" }
21
- 3.times do
22
- doc = Nokogiri.XML template.render
23
- assert_equal 'Hello World!', doc.root.text
24
- assert_equal 'em', doc.root.name
25
- end
26
- end
27
-
28
- test "passing locals" do
29
- template = Tilt::NokogiriTemplate.new { "xml.em('Hey ' + name + '!')" }
30
- doc = Nokogiri.XML template.render(Object.new, :name => 'Joe')
31
- assert_equal 'Hey Joe!', doc.root.text
32
- assert_equal 'em', doc.root.name
33
- end
34
-
35
- test "evaluating in an object scope" do
36
- template = Tilt::NokogiriTemplate.new { "xml.em('Hey ' + @name + '!')" }
37
- scope = Object.new
38
- scope.instance_variable_set :@name, 'Joe'
39
- doc = Nokogiri.XML template.render(scope)
40
- assert_equal 'Hey Joe!', doc.root.text
41
- assert_equal 'em', doc.root.name
42
- end
43
-
44
- test "passing a block for yield" do
45
- template = Tilt::NokogiriTemplate.new { "xml.em('Hey ' + yield + '!')" }
46
- 3.times do
47
- doc = Nokogiri.XML template.render { 'Joe' }
48
- assert_equal 'Hey Joe!', doc.root.text
49
- assert_equal 'em', doc.root.name
50
- end
51
- end
52
-
53
- test "block style templates" do
54
- template =
55
- Tilt::NokogiriTemplate.new do |t|
56
- lambda { |xml| xml.em('Hey Joe!') }
57
- end
58
- doc = Nokogiri.XML template.render
59
- assert_equal 'Hey Joe!', doc.root.text
60
- assert_equal 'em', doc.root.name
61
- end
62
-
63
- test "allows nesting raw XML, API-compatible to Builder" do
64
- subtemplate = Tilt::NokogiriTemplate.new { "xml.em 'Hello World!'" }
65
- template = Tilt::NokogiriTemplate.new { "xml.strong { xml << yield }" }
66
- 3.times do
67
- options = { :xml => Nokogiri::XML::Builder.new }
68
- doc = Nokogiri.XML(template.render(options) { subtemplate.render(options) })
69
- assert_equal 'Hello World!', doc.root.text.strip
70
- assert_equal 'strong', doc.root.name
71
- end
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
84
- end
85
- rescue LoadError
86
- warn "Tilt::NokogiriTemplate (disabled)"
87
- end