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,239 +0,0 @@
1
- # coding: utf-8
2
- require 'test_helper'
3
- require 'tilt'
4
- require 'tilt/erb'
5
- require 'tempfile'
6
-
7
- class ERBTemplateTest < Minitest::Test
8
- test "registered for '.erb' files" do
9
- assert_includes Tilt.lazy_map['erb'], ['Tilt::ERBTemplate', 'tilt/erb']
10
- end
11
-
12
- test "registered for '.rhtml' files" do
13
- assert_includes Tilt.lazy_map['rhtml'], ['Tilt::ERBTemplate', 'tilt/erb']
14
- end
15
-
16
- test "loading and evaluating templates on #render" do
17
- template = Tilt::ERBTemplate.new { |t| "Hello World!" }
18
- assert_equal "Hello World!", template.render
19
- end
20
-
21
- test "can be rendered more than once" do
22
- template = Tilt::ERBTemplate.new { |t| "Hello World!" }
23
- 3.times { assert_equal "Hello World!", template.render }
24
- end
25
-
26
- test "passing locals" do
27
- template = Tilt::ERBTemplate.new { 'Hey <%= name %>!' }
28
- assert_equal "Hey Joe!", template.render(Object.new, :name => 'Joe')
29
- end
30
-
31
- test "evaluating in an object scope" do
32
- template = Tilt::ERBTemplate.new { 'Hey <%= @name %>!' }
33
- scope = Object.new
34
- scope.instance_variable_set :@name, 'Joe'
35
- assert_equal "Hey Joe!", template.render(scope)
36
- end
37
-
38
- class MockOutputVariableScope
39
- attr_accessor :exposed_buffer
40
- end
41
-
42
- test "exposing the buffer to the template by default" do
43
- begin
44
- Tilt::ERBTemplate.default_output_variable = '@_out_buf'
45
- template = Tilt::ERBTemplate.new { '<% self.exposed_buffer = @_out_buf %>hey' }
46
- scope = MockOutputVariableScope.new
47
- template.render(scope)
48
- refute_nil scope.exposed_buffer
49
- assert_equal scope.exposed_buffer, 'hey'
50
- ensure
51
- Tilt::ERBTemplate.default_output_variable = '_erbout'
52
- end
53
- end
54
-
55
- test "passing a block for yield" do
56
- template = Tilt::ERBTemplate.new { 'Hey <%= yield %>!' }
57
- assert_equal "Hey Joe!", template.render { 'Joe' }
58
- end
59
-
60
- test "backtrace file and line reporting without locals" do
61
- data = File.read(__FILE__).split("\n__END__\n").last
62
- fail unless data[0] == ?<
63
- template = Tilt::ERBTemplate.new('test.erb', 11) { data }
64
- begin
65
- template.render
66
- fail 'should have raised an exception'
67
- rescue => boom
68
- assert_kind_of NameError, boom
69
- line = boom.backtrace.grep(/^test\.erb:/).first
70
- assert line, "Backtrace didn't contain test.erb"
71
- _file, line, _meth = line.split(":")
72
- assert_equal '13', line
73
- end
74
- end
75
-
76
- test "backtrace file and line reporting with locals" do
77
- data = File.read(__FILE__).split("\n__END__\n").last
78
- fail unless data[0] == ?<
79
- template = Tilt::ERBTemplate.new('test.erb', 1) { data }
80
- begin
81
- template.render(nil, :name => 'Joe', :foo => 'bar')
82
- fail 'should have raised an exception'
83
- rescue => boom
84
- assert_kind_of RuntimeError, boom
85
- line = boom.backtrace.first
86
- file, line, _meth = line.split(":")
87
- assert_equal 'test.erb', file
88
- assert_equal '6', line
89
- end
90
- end
91
-
92
- test "explicit disabling of trim mode" do
93
- template = Tilt::ERBTemplate.new('test.erb', 1, :trim => false) { "\n<%= 1 + 1 %>\n" }
94
- assert_equal "\n2\n", template.render
95
- end
96
-
97
- test "default stripping trim mode" do
98
- template = Tilt::ERBTemplate.new('test.erb', 1) { "\n<%= 1 + 1 %>\n" }
99
- assert_equal "\n2", template.render
100
- end
101
-
102
- test "stripping trim mode" do
103
- template = Tilt::ERBTemplate.new('test.erb', 1, :trim => '-') { "\n<%= 1 + 1 -%>\n" }
104
- assert_equal "\n2", template.render
105
- end
106
-
107
- test "shorthand whole line syntax trim mode" do
108
- template = Tilt::ERBTemplate.new('test.erb', :trim => '%') { "\n% if true\nhello\n%end\n" }
109
- assert_equal "\nhello\n", template.render
110
- end
111
-
112
- test "using an instance variable as the outvar" do
113
- template = Tilt::ERBTemplate.new(nil, :outvar => '@buf') { "<%= 1 + 1 %>" }
114
- scope = Object.new
115
- scope.instance_variable_set(:@buf, 'original value')
116
- assert_equal '2', template.render(scope)
117
- assert_equal 'original value', scope.instance_variable_get(:@buf)
118
- end
119
- end
120
-
121
- class CompiledERBTemplateTest < Minitest::Test
122
- def teardown
123
- GC.start
124
- end
125
-
126
- class Scope
127
- end
128
-
129
- test "compiling template source to a method" do
130
- template = Tilt::ERBTemplate.new { |t| "Hello World!" }
131
- template.render(Scope.new)
132
- method = template.send(:compiled_method, [])
133
- assert_kind_of UnboundMethod, method
134
- end
135
-
136
- test "loading and evaluating templates on #render" do
137
- template = Tilt::ERBTemplate.new { |t| "Hello World!" }
138
- assert_equal "Hello World!", template.render(Scope.new)
139
- assert_equal "Hello World!", template.render(Scope.new)
140
- end
141
-
142
- test "passing locals" do
143
- template = Tilt::ERBTemplate.new { 'Hey <%= name %>!' }
144
- assert_equal "Hey Joe!", template.render(Scope.new, :name => 'Joe')
145
- end
146
-
147
- test "evaluating in an object scope" do
148
- template = Tilt::ERBTemplate.new { 'Hey <%= @name %>!' }
149
- scope = Scope.new
150
- scope.instance_variable_set :@name, 'Joe'
151
- assert_equal "Hey Joe!", template.render(scope)
152
- scope.instance_variable_set :@name, 'Jane'
153
- assert_equal "Hey Jane!", template.render(scope)
154
- end
155
-
156
- test "passing a block for yield" do
157
- template = Tilt::ERBTemplate.new { 'Hey <%= yield %>!' }
158
- assert_equal "Hey Joe!", template.render(Scope.new) { 'Joe' }
159
- assert_equal "Hey Jane!", template.render(Scope.new) { 'Jane' }
160
- end
161
-
162
- test "backtrace file and line reporting without locals" do
163
- data = File.read(__FILE__).split("\n__END__\n").last
164
- fail unless data[0] == ?<
165
- template = Tilt::ERBTemplate.new('test.erb', 11) { data }
166
- begin
167
- template.render(Scope.new)
168
- fail 'should have raised an exception'
169
- rescue => boom
170
- assert_kind_of NameError, boom
171
- line = boom.backtrace.grep(/^test\.erb:/).first
172
- assert line, "Backtrace didn't contain test.erb"
173
- _file, line, _meth = line.split(":")
174
- assert_equal '13', line
175
- end
176
- end
177
-
178
- test "backtrace file and line reporting with locals" do
179
- data = File.read(__FILE__).split("\n__END__\n").last
180
- fail unless data[0] == ?<
181
- template = Tilt::ERBTemplate.new('test.erb') { data }
182
- begin
183
- template.render(Scope.new, :name => 'Joe', :foo => 'bar')
184
- fail 'should have raised an exception'
185
- rescue => boom
186
- assert_kind_of RuntimeError, boom
187
- line = boom.backtrace.first
188
- file, line, _meth = line.split(":")
189
- assert_equal 'test.erb', file
190
- assert_equal '6', line
191
- end
192
- end
193
-
194
- test "default stripping trim mode" do
195
- template = Tilt::ERBTemplate.new('test.erb') { "\n<%= 1 + 1 %>\n" }
196
- assert_equal "\n2", template.render(Scope.new)
197
- end
198
-
199
- test "stripping trim mode" do
200
- template = Tilt::ERBTemplate.new('test.erb', :trim => '-') { "\n<%= 1 + 1 -%>\n" }
201
- assert_equal "\n2", template.render(Scope.new)
202
- end
203
-
204
- test "shorthand whole line syntax trim mode" do
205
- template = Tilt::ERBTemplate.new('test.erb', :trim => '%') { "\n% if true\nhello\n%end\n" }
206
- assert_equal "\nhello\n", template.render(Scope.new)
207
- end
208
-
209
- test "encoding with magic comment" do
210
- f = Tempfile.open("template")
211
- f.puts('<%# coding: UTF-8 %>')
212
- f.puts('ふが <%= @hoge %>')
213
- f.close()
214
- @hoge = "ほげ"
215
- erb = Tilt::ERBTemplate.new(f.path)
216
- 3.times { erb.render(self) }
217
- f.delete
218
- end
219
-
220
- test "encoding with :default_encoding" do
221
- f = Tempfile.open("template")
222
- f.puts('ふが <%= @hoge %>')
223
- f.close()
224
- @hoge = "ほげ"
225
- erb = Tilt::ERBTemplate.new(f.path, :default_encoding => 'UTF-8')
226
- 3.times { erb.render(self) }
227
- f.delete
228
- end
229
- end
230
-
231
- __END__
232
- <html>
233
- <body>
234
- <h1>Hey <%= name %>!</h1>
235
-
236
-
237
- <p><% fail %></p>
238
- </body>
239
- </html>
@@ -1,151 +0,0 @@
1
- require 'test_helper'
2
- require 'tilt'
3
-
4
- begin
5
- require 'tilt/erubis'
6
- class ErubisTemplateTest < Minitest::Test
7
- test "registered for '.erubis' files" do
8
- assert_equal Tilt::ErubisTemplate, Tilt['test.erubis']
9
- assert_equal Tilt::ErubisTemplate, Tilt['test.html.erubis']
10
- end
11
-
12
- test "registered above ERB" do
13
- %w[erb rhtml].each do |ext|
14
- lazy = Tilt.lazy_map[ext]
15
- erubis_idx = lazy.index { |klass, file| klass == 'Tilt::ErubisTemplate' }
16
- erb_idx = lazy.index { |klass, file| klass == 'Tilt::ERBTemplate' }
17
- assert erubis_idx < erb_idx,
18
- "#{erubis_idx} should be lower than #{erb_idx}"
19
- end
20
- end
21
-
22
- test "preparing and evaluating templates on #render" do
23
- template = Tilt::ErubisTemplate.new { |t| "Hello World!" }
24
- assert_equal "Hello World!", template.render
25
- end
26
-
27
- test "can be rendered more than once" do
28
- template = Tilt::ErubisTemplate.new { |t| "Hello World!" }
29
- 3.times { assert_equal "Hello World!", template.render }
30
- end
31
-
32
- test "passing locals" do
33
- template = Tilt::ErubisTemplate.new { 'Hey <%= name %>!' }
34
- assert_equal "Hey Joe!", template.render(Object.new, :name => 'Joe')
35
- end
36
-
37
- test "evaluating in an object scope" do
38
- template = Tilt::ErubisTemplate.new { 'Hey <%= @name %>!' }
39
- scope = Object.new
40
- scope.instance_variable_set :@name, 'Joe'
41
- assert_equal "Hey Joe!", template.render(scope)
42
- end
43
-
44
- class MockOutputVariableScope
45
- attr_accessor :exposed_buffer
46
- end
47
-
48
- test "exposing the buffer to the template by default" do
49
- begin
50
- Tilt::ErubisTemplate.default_output_variable = '@_out_buf'
51
- template = Tilt::ErubisTemplate.new { '<% self.exposed_buffer = @_out_buf %>hey' }
52
- scope = MockOutputVariableScope.new
53
- template.render(scope)
54
- refute_nil scope.exposed_buffer
55
- assert_equal scope.exposed_buffer, 'hey'
56
- ensure
57
- Tilt::ErubisTemplate.default_output_variable = '_erbout'
58
- end
59
- end
60
-
61
- test "passing a block for yield" do
62
- template = Tilt::ErubisTemplate.new { 'Hey <%= yield %>!' }
63
- assert_equal "Hey Joe!", template.render { 'Joe' }
64
- end
65
-
66
- test "backtrace file and line reporting without locals" do
67
- data = File.read(__FILE__).split("\n__END__\n").last
68
- fail unless data[0] == ?<
69
- template = Tilt::ErubisTemplate.new('test.erubis', 11) { data }
70
- begin
71
- template.render
72
- fail 'should have raised an exception'
73
- rescue => boom
74
- assert_kind_of NameError, boom
75
- line = boom.backtrace.grep(/^test\.erubis:/).first
76
- assert line, "Backtrace didn't contain test.erubis"
77
- _file, line, _meth = line.split(":")
78
- assert_equal '13', line
79
- end
80
- end
81
-
82
- test "backtrace file and line reporting with locals" do
83
- data = File.read(__FILE__).split("\n__END__\n").last
84
- fail unless data[0] == ?<
85
- template = Tilt::ErubisTemplate.new('test.erubis', 1) { data }
86
- begin
87
- template.render(nil, :name => 'Joe', :foo => 'bar')
88
- fail 'should have raised an exception'
89
- rescue => boom
90
- assert_kind_of RuntimeError, boom
91
- line = boom.backtrace.first
92
- file, line, _meth = line.split(":")
93
- assert_equal 'test.erubis', file
94
- assert_equal '6', line
95
- end
96
- end
97
-
98
- test "erubis template options" do
99
- template = Tilt::ErubisTemplate.new(nil, :pattern => '\{% %\}') { 'Hey {%= @name %}!' }
100
- scope = Object.new
101
- scope.instance_variable_set :@name, 'Joe'
102
- assert_equal "Hey Joe!", template.render(scope)
103
- end
104
-
105
- test "using an instance variable as the outvar" do
106
- template = Tilt::ErubisTemplate.new(nil, :outvar => '@buf') { "<%= 1 + 1 %>" }
107
- scope = Object.new
108
- scope.instance_variable_set(:@buf, 'original value')
109
- assert_equal '2', template.render(scope)
110
- assert_equal 'original value', scope.instance_variable_get(:@buf)
111
- end
112
-
113
- test "using Erubis::EscapedEruby subclass via :engine_class option" do
114
- template = Tilt::ErubisTemplate.new(nil, :engine_class => ::Erubis::EscapedEruby) { |t| %(<%= "<p>Hello World!</p>" %>) }
115
- assert_equal "&lt;p&gt;Hello World!&lt;/p&gt;", template.render
116
- end
117
-
118
- test "using :escape_html => true option" do
119
- template = Tilt::ErubisTemplate.new(nil, :escape_html => true) { |t| %(<%= "<p>Hello World!</p>" %>) }
120
- assert_equal "&lt;p&gt;Hello World!&lt;/p&gt;", template.render
121
- end
122
-
123
- test "using :escape_html => false option" do
124
- template = Tilt::ErubisTemplate.new(nil, :escape_html => false) { |t| %(<%= "<p>Hello World!</p>" %>) }
125
- assert_equal "<p>Hello World!</p>", template.render
126
- end
127
-
128
- test "erubis default does not escape html" do
129
- template = Tilt::ErubisTemplate.new { |t| %(<%= "<p>Hello World!</p>" %>) }
130
- assert_equal "<p>Hello World!</p>", template.render
131
- end
132
-
133
- test "does not modify options argument" do
134
- options_hash = {:escape_html => true}
135
- Tilt::ErubisTemplate.new(nil, options_hash) { |t| "Hello World!" }
136
- assert_equal({:escape_html => true}, options_hash)
137
- end
138
- end
139
- rescue LoadError
140
- warn "Tilt::ErubisTemplate (disabled)"
141
- end
142
-
143
- __END__
144
- <html>
145
- <body>
146
- <h1>Hey <%= name %>!</h1>
147
-
148
-
149
- <p><% fail %></p>
150
- </body>
151
- </html>
@@ -1,158 +0,0 @@
1
- require 'test_helper'
2
- require 'tilt'
3
-
4
- begin
5
- require 'tilt/erubi'
6
- class ErubiTemplateTest < Minitest::Test
7
- test "registered for '.erubi' files" do
8
- assert_equal Tilt::ErubiTemplate, Tilt['test.erubi']
9
- assert_equal Tilt::ErubiTemplate, Tilt['test.html.erubi']
10
- end
11
-
12
- test "registered above ERB and Erubis" do
13
- %w[erb rhtml].each do |ext|
14
- lazy = Tilt.lazy_map[ext]
15
- erubi_idx = lazy.index { |klass, file| klass == 'Tilt::ErubiTemplate' }
16
- erubis_idx = lazy.index { |klass, file| klass == 'Tilt::ErubisTemplate' }
17
- erb_idx = lazy.index { |klass, file| klass == 'Tilt::ERBTemplate' }
18
- assert erubi_idx < erubis_idx,
19
- "#{erubi_idx} should be lower than #{erubis_idx}"
20
- assert erubi_idx < erb_idx,
21
- "#{erubi_idx} should be lower than #{erb_idx}"
22
- end
23
- end
24
-
25
- test "preparing and evaluating templates on #render" do
26
- template = Tilt::ErubiTemplate.new { |t| "Hello World!" }
27
- assert_equal "Hello World!", template.render
28
- end
29
-
30
- test "can be rendered more than once" do
31
- template = Tilt::ErubiTemplate.new { |t| "Hello World!" }
32
- 3.times { assert_equal "Hello World!", template.render }
33
- end
34
-
35
- test "passing locals" do
36
- template = Tilt::ErubiTemplate.new { 'Hey <%= name %>!' }
37
- assert_equal "Hey Joe!", template.render(Object.new, :name => 'Joe')
38
- end
39
-
40
- test "evaluating in an object scope" do
41
- template = Tilt::ErubiTemplate.new { 'Hey <%= @name %>!' }
42
- scope = Object.new
43
- scope.instance_variable_set :@name, 'Joe'
44
- assert_equal "Hey Joe!", template.render(scope)
45
- end
46
-
47
- class MockOutputVariableScope
48
- attr_accessor :exposed_buffer
49
- end
50
-
51
- test "exposing the buffer to the template by default" do
52
- template = Tilt::ErubiTemplate.new(nil, :bufvar=>'@_out_buf') { '<% self.exposed_buffer = @_out_buf %>hey' }
53
- scope = MockOutputVariableScope.new
54
- template.render(scope)
55
- refute_nil scope.exposed_buffer
56
- assert_equal scope.exposed_buffer, 'hey'
57
- end
58
-
59
- test "passing a block for yield" do
60
- template = Tilt::ErubiTemplate.new { 'Hey <%= yield %>!' }
61
- assert_equal "Hey Joe!", template.render { 'Joe' }
62
- end
63
-
64
- test "backtrace file and line reporting without locals" do
65
- data = File.read(__FILE__).split("\n__END__\n").last
66
- fail unless data[0] == ?<
67
- template = Tilt::ErubiTemplate.new('test.erubis', 11) { data }
68
- begin
69
- template.render
70
- fail 'should have raised an exception'
71
- rescue => boom
72
- assert_kind_of NameError, boom
73
- line = boom.backtrace.grep(/^test\.erubis:/).first
74
- assert line, "Backtrace didn't contain test.erubis"
75
- _file, line, _meth = line.split(":")
76
- assert_equal '13', line
77
- end
78
- end
79
-
80
- test "backtrace file and line reporting with locals" do
81
- data = File.read(__FILE__).split("\n__END__\n").last
82
- fail unless data[0] == ?<
83
- template = Tilt::ErubiTemplate.new('test.erubis', 1) { data }
84
- begin
85
- template.render(nil, :name => 'Joe', :foo => 'bar')
86
- fail 'should have raised an exception'
87
- rescue => boom
88
- assert_kind_of RuntimeError, boom
89
- line = boom.backtrace.first
90
- file, line, _meth = line.split(":")
91
- assert_equal 'test.erubis', file
92
- assert_equal '6', line
93
- end
94
- end
95
-
96
- test "erubis template options" do
97
- template = Tilt::ErubiTemplate.new(nil, :escapefunc=> 'h') { 'Hey <%== @name %>!' }
98
- scope = Object.new
99
- def scope.h(s) s * 2 end
100
- scope.instance_variable_set :@name, 'Joe'
101
- assert_equal "Hey JoeJoe!", template.render(scope)
102
- end
103
-
104
- test "using an instance variable as the outvar" do
105
- template = Tilt::ErubiTemplate.new(nil, :outvar => '@buf') { "<%= 1 + 1 %>" }
106
- scope = Object.new
107
- scope.instance_variable_set(:@buf, 'original value')
108
- assert_equal '2', template.render(scope)
109
- assert_equal 'original value', scope.instance_variable_get(:@buf)
110
- end
111
-
112
- test "using Erubi::CaptureEndEngine subclass via :engine_class option" do
113
- require 'erubi/capture_end'
114
- def self.bar
115
- @a << "a"
116
- yield
117
- @a << 'b'
118
- @a.upcase
119
- end
120
- template = Tilt::ErubiTemplate.new(nil, :engine_class => ::Erubi::CaptureEndEngine, :bufvar=>'@a') { 'c<%|= bar do %>d<%| end %>e' }
121
- assert_equal "cADBe", template.render(self)
122
- end
123
-
124
- test "using :escape_html => true option" do
125
- template = Tilt::ErubiTemplate.new(nil, :escape_html => true) { |t| %(<%= "<p>Hello World!</p>" %>) }
126
- assert_equal "&lt;p&gt;Hello World!&lt;/p&gt;", template.render
127
- end
128
-
129
- test "using :escape_html => false option" do
130
- template = Tilt::ErubiTemplate.new(nil, :escape_html => false) { |t| %(<%= "<p>Hello World!</p>" %>) }
131
- assert_equal "<p>Hello World!</p>", template.render
132
- end
133
-
134
- test "erubi default does not escape html" do
135
- template = Tilt::ErubiTemplate.new { |t| %(<%= "<p>Hello World!</p>" %>) }
136
- assert_equal "<p>Hello World!</p>", template.render
137
- end
138
-
139
- test "does not modify options argument" do
140
- options_hash = {:escape_html => true}
141
- Tilt::ErubiTemplate.new(nil, options_hash) { |t| "Hello World!" }
142
- assert_equal({:escape_html => true}, options_hash)
143
- end
144
- end
145
- rescue LoadError
146
- warn "Tilt::ErubiTemplate (disabled)"
147
- end
148
-
149
- __END__
150
- <html>
151
- <body>
152
- <h1>Hey <%= name %>!</h1>
153
-
154
-
155
- <p><% fail %></p>
156
- </body>
157
- </html>
158
-