public
Description: HTML Abstraction Markup Language - A Markup Haiku
Homepage: http://haml.hamptoncatlin.com
Clone URL: git://github.com/nex3/haml.git
Making local variable setting render-method-specific.

git-svn-id: svn://hamptoncatlin.com/haml/trunk@661 
7063305b-7217-0410-af8c-cdc13e5119b9
nex3 (author)
Sat Nov 24 00:35:10 -0800 2007
commit  70893f21a095832815862ef188c71f2cc59ffdaf
tree    28f07b9a3524cf219c550994c1311ee68be6acbf
parent  9e04234a17d6e1996d766c42ca7503ce6d6373ea
...
693
694
695
696
697
698
699
700
701
702
703
...
693
694
695
 
 
 
 
 
696
697
698
0
@@ -693,11 +693,6 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
0
 # * An +initialize+ method that accepts one parameter,
0
 # the text to be filtered.
0
 # * A +render+ method that returns the result of the filtering.
0
-#
0
-# [<tt>:locals</tt>] The local variables that will be available within the
0
-# template. For instance, if <tt>:locals</tt> is
0
-# <tt>{ :foo => "bar" }</tt>, then within the template,
0
-# <tt>= foo</tt> will produce <tt>bar</tt>.
0
 #
0
 # [<tt>:autoclose</tt>] A list of tag names that should be automatically self-closed
0
 # if they have no content.
...
33
34
35
36
37
38
39
...
43
44
45
46
47
48
49
...
54
55
56
 
 
 
 
 
 
 
 
57
58
59
...
74
75
76
77
78
79
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
81
82
83
84
85
 
86
87
88
89
90
91
92
 
 
93
94
95
...
100
101
102
103
 
104
105
106
...
112
113
114
115
 
116
117
118
...
130
131
132
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
134
135
136
137
138
139
 
140
141
142
...
144
145
146
147
148
149
150
 
 
151
152
 
153
154
155
...
159
160
161
162
163
164
165
166
167
168
169
170
171
...
175
176
177
178
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
180
181
182
 
183
184
 
185
186
187
...
193
194
195
196
 
197
198
199
...
33
34
35
 
36
37
38
...
42
43
44
 
45
46
47
...
52
53
54
55
56
57
58
59
60
61
62
63
64
65
...
80
81
82
 
 
 
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
 
104
105
106
107
108
109
110
 
111
112
113
114
115
...
120
121
122
 
123
124
125
126
...
132
133
134
 
135
136
137
138
...
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
 
 
 
 
 
169
170
171
172
...
174
175
176
 
 
177
 
178
179
180
 
181
182
183
184
...
188
189
190
 
 
 
 
 
 
 
191
192
193
...
197
198
199
 
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
 
224
225
 
226
227
228
229
...
235
236
237
 
238
239
240
241
0
@@ -33,7 +33,6 @@ module Haml
0
       @options = {
0
         :suppress_eval => false,
0
         :attr_wrapper => "'",
0
- :locals => {},
0
         :autoclose => ['meta', 'img', 'link', 'br', 'hr', 'input', 'area'],
0
         :filters => {
0
           'sass' => Sass::Engine,
0
@@ -43,7 +42,6 @@ module Haml
0
           'textile' => Haml::Filters::Textile,
0
           'markdown' => Haml::Filters::Markdown }
0
       }
0
-
0
       @options.rec_merge! options
0
 
0
       unless @options[:suppress_eval]
0
@@ -54,6 +52,14 @@ module Haml
0
       end
0
       @options[:filters].rec_merge! options[:filters] if options[:filters]
0
 
0
+ if @options[:locals]
0
+ warn <<END
0
+DEPRECATION WARNING:
0
+The Haml :locals option is deprecated and will be removed in version 2.0.
0
+Use the locals option for Haml::Engine#render instead.
0
+END
0
+ end
0
+
0
       @template = template.strip #String
0
       @to_close_stack = []
0
       @output_tabs = 0
0
@@ -74,22 +80,36 @@ module Haml
0
     # Haml uses it as the second argument to Kernel#eval;
0
     # otherwise, Haml just uses its #instance_eval context.
0
     #
0
- # Note that Haml modifies the evaluation context,
0
- # extending it with Haml::Helpers
0
- # and performing various other modifications.
0
+ # Note that Haml modifies the evaluation context
0
+ # (either the scope object or the "self" object of the scope binding).
0
+ # It extends Haml::Helpers, and various instance variables are set
0
+ # (all prefixed with "haml").
0
+ # For example:
0
+ #
0
+ # s = "foobar"
0
+ # Haml::Engine.new("%p= upcase").render(s) #=> "<p>FOOBAR</p>"
0
+ #
0
+ # # s now extends Haml::Helpers
0
+ # s.responds_to?(:html_attrs) #=> true
0
+ #
0
+ # +locals+ is a hash of local variables to make available to the template.
0
+ # For example:
0
+ #
0
+ # Haml::Engine.new("%p= foo").render(Object.new, :foo => "Hello, world!") #=> "<p>Hello, world!</p>"
0
     #
0
     # If a block is passed to render,
0
     # that block is run when +yield+ is called
0
     # within the template.
0
     #
0
- # Note that due to some Ruby quirks,
0
+ # Due to some Ruby quirks,
0
     # if scope is a Binding or Proc object and a block is given,
0
     # the evaluation context may not be quite what the user expects.
0
     # In particular, it's equivalent to passing <tt>eval("self", scope)</tt> as scope.
0
     # This won't have an effect in most cases,
0
     # but if you're relying on local variables defined in the context of scope,
0
     # they won't work.
0
- def render(scope = Object.new, &block)
0
+ def render(scope = Object.new, locals = {}, &block)
0
+ locals = (@options[:locals] || {}).merge(locals)
0
       buffer = Haml::Buffer.new(options_for_buffer)
0
 
0
       if scope.is_a?(Binding) || scope.is_a?(Proc)
0
@@ -100,7 +120,7 @@ module Haml
0
         scope = scope_object.instance_eval{binding}
0
       end
0
 
0
- set_locals(@options[:locals].merge(:_hamlout => buffer, :_erbout => buffer.buffer), scope, scope_object)
0
+ set_locals(locals.merge(:_hamlout => buffer, :_erbout => buffer.buffer), scope, scope_object)
0
 
0
       scope_object.instance_eval do
0
         extend Haml::Helpers
0
@@ -112,7 +132,7 @@ module Haml
0
       begin
0
         eval(@precompiled, scope, '(haml-eval)')
0
       rescue Exception => e
0
- raise Engine.add_exception_info(e, scope_object, @precompiled, @options[:filename])
0
+ raise Engine.add_exception_info(e, @precompiled, @options[:filename])
0
       end
0
 
0
       # Get rid of the current buffer
0
@@ -130,13 +150,23 @@ module Haml
0
     #
0
     # +scope+ works the same as it does for render.
0
     #
0
+ # The first argument of the returned proc is a hash of local variable names to values.
0
+ # However, due to an unfortunate Ruby quirk,
0
+ # the local variables which can be assigned must be pre-declared.
0
+ # This is done with the +local_names+ argument.
0
+ # For example:
0
+ #
0
+ # # This works
0
+ # Haml::Engine.new("%p= foo").render_proc(Object.new, :foo).call :foo => "Hello!"
0
+ # #=> "<p>Hello!</p>"
0
+ #
0
+ # # This doesn't
0
+ # Haml::Engine.new("%p= foo").render_proc.call :foo => "Hello!"
0
+ # #=> NameError: undefined local variable or method `foo'
0
+ #
0
     # The proc doesn't take a block;
0
     # any yields in the template will fail.
0
- #
0
- # Note that Haml modifies the evaluation context,
0
- # extending it with Haml::Helpers
0
- # and performing various other modifications.
0
- def render_proc(scope = Object.new)
0
+ def render_proc(scope = Object.new, *local_names)
0
       if scope.is_a?(Binding) || scope.is_a?(Proc)
0
         scope_object = eval("self", scope)
0
       else
0
@@ -144,12 +174,11 @@ module Haml
0
         scope = scope_object.instance_eval{binding}
0
       end
0
 
0
- set_locals(@options[:locals], scope, scope_object)
0
-
0
       begin
0
- eval("proc {#{precompiled_with_ambles}}\n", scope, '(haml-eval)')
0
+ eval("Proc.new { |*_haml_locals| _haml_locals = _haml_locals[0] || {};" +
0
+ precompiled_with_ambles(local_names) + "}\n", scope, '(haml-eval)')
0
       rescue Exception => e
0
- raise add_exception_info(e, scope_object)
0
+ raise Haml::Engine.add_exception_info(e, @precompiled, @options[:filename])
0
       end
0
     end
0
 
0
@@ -159,13 +188,6 @@ module Haml
0
     #
0
     # If +object+ is a class or module,
0
     # the method will instead by defined as an instance method.
0
- #
0
- # Note that the :locals option has no effect for def_method.
0
- #
0
- # Note also that Haml modifies the evaluation context,
0
- # extending it with Haml::Helpers
0
- # and performing various other modifications.
0
- #
0
     # For example:
0
     #
0
     # t = Time.now
0
@@ -175,13 +197,33 @@ module Haml
0
     # Haml::Engine.new(".upcased= upcase").def_method(String, :upcased_div)
0
     # "foobar".upcased_div #=> "<div class='upcased'>FOOBAR</div>\n"
0
     #
0
- def def_method(object, name)
0
+ # The first argument of the defined method is a hash of local variable names to values.
0
+ # However, due to an unfortunate Ruby quirk,
0
+ # the local variables which can be assigned must be pre-declared.
0
+ # This is done with the +local_names+ argument.
0
+ # For example:
0
+ #
0
+ # # This works
0
+ # obj = Object.new
0
+ # Haml::Engine.new("%p= foo").def_method(obj, :render, :foo)
0
+ # obj.render(:foo => "Hello!") #=> "<p>Hello!</p>"
0
+ #
0
+ # # This doesn't
0
+ # obj = Object.new
0
+ # Haml::Engine.new("%p= foo").def_method(obj, :render)
0
+ # obj.render(:foo => "Hello!") #=> NameError: undefined local variable or method `foo'
0
+ #
0
+ # Note that Haml modifies the evaluation context
0
+ # (either the scope object or the "self" object of the scope binding).
0
+ # It extends Haml::Helpers, and various instance variables are set
0
+ # (all prefixed with "haml").
0
+ def def_method(object, name, *local_names)
0
       method = object.is_a?(Module) ? :module_eval : :instance_eval
0
 
0
       begin
0
- object.send(method, "def #{name}; #{precompiled_with_ambles}; end", '(haml-eval)')
0
+ object.send(method, "def #{name}(_haml_locals = {}); #{precompiled_with_ambles(local_names)}; end", '(haml-eval)')
0
       rescue Exception => e
0
- raise add_exception_info(e, scope_object)
0
+ raise Haml::Engine.add_exception_info(e, @precompiled, @options[:filename])
0
       end
0
     end
0
 
0
@@ -193,7 +235,7 @@ module Haml
0
       eval(set_locals, scope)
0
     end
0
 
0
- def self.add_exception_info(e, scope_object, precompiled, filename)
0
+ def self.add_exception_info(e, precompiled, filename)
0
       metaclass = class << e; self; end
0
       metaclass.send(:include, Haml::Error)
0
 
...
88
89
90
91
 
92
93
94
...
100
101
102
103
 
104
105
106
107
108
 
 
 
 
 
 
 
 
 
109
110
111
...
88
89
90
 
91
92
93
94
...
100
101
102
 
103
104
105
106
107
 
108
109
110
111
112
113
114
115
116
117
118
119
0
@@ -88,7 +88,7 @@ module Haml
0
     private
0
 
0
     # Returns the precompiled string with the preamble and postamble
0
- def precompiled_with_ambles
0
+ def precompiled_with_ambles(local_names)
0
       preamble = <<END.gsub("\n", ";")
0
 extend Haml::Helpers
0
 @haml_stack ||= Array.new
0
@@ -100,12 +100,20 @@ begin
0
 END
0
       postamble = <<END.gsub("\n", ";")
0
 rescue Exception => e
0
- raise Haml::Engine.add_exception_info(e, self, #{@precompiled.inspect}, #{@options[:filename].inspect})
0
+ raise Haml::Engine.add_exception_info(e, #{@precompiled.inspect}, #{@options[:filename].inspect})
0
 end
0
 @haml_is_haml = false
0
 _hamlout.buffer
0
 END
0
- preamble + @precompiled + postamble
0
+ preamble + locals_code(local_names) + @precompiled + postamble
0
+ end
0
+
0
+ def locals_code(names)
0
+ names = names.keys if Hash == names
0
+
0
+ names.map do |name|
0
+ "#{name} = _haml_locals[#{name.to_sym.inspect}] || _haml_locals[#{name.to_s.inspect}]"
0
+ end.join(';') + ';'
0
     end
0
 
0
     def precompile
...
49
50
51
52
53
54
55
56
57
58
59
 
60
61
62
 
63
64
65
...
49
50
51
 
 
 
52
53
54
55
 
56
57
58
 
59
60
61
62
0
@@ -49,17 +49,14 @@ module Haml
0
       @view.send(:evaluate_assigns)
0
 
0
       options = @@options.dup
0
- locals = options[:locals] || {}
0
- locals.merge! local_assigns
0
- options[:locals] = locals
0
 
0
       yield_proc = @view.instance_eval do
0
         proc { |*name| instance_variable_get("@content_for_#{name.first || 'layout'}") }
0
       end
0
- return Haml::Engine.new(template, options).to_html(@view, &yield_proc) if @view.haml_inline
0
+ return Haml::Engine.new(template, options).to_html(@view, local_assigns, &yield_proc) if @view.haml_inline
0
 
0
       options[:filename] ||= template
0
- Haml::Engine.new(File.read(template), options).to_html(@view, &yield_proc)
0
+ Haml::Engine.new(File.read(template), options).to_html(@view, local_assigns, &yield_proc)
0
     end
0
   end
0
 end
...
12
13
14
15
 
 
 
16
17
18
...
137
138
139
140
141
142
 
 
 
 
 
 
 
 
143
144
145
 
146
147
148
...
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
...
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
236
237
238
239
240
241
242
243
244
245
246
247
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
248
249
250
...
354
355
356
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
357
...
12
13
14
 
15
16
17
18
19
20
...
139
140
141
 
 
 
142
143
144
145
146
147
148
149
150
 
 
151
152
153
154
...
165
166
167
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
169
170
...
184
185
186
 
 
 
 
 
 
 
 
 
 
 
 
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
 
 
 
 
 
 
 
 
 
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
...
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
0
@@ -12,7 +12,9 @@ require 'haml/engine'
0
 class EngineTest < Test::Unit::TestCase
0
 
0
   def render(text, options = {}, &block)
0
- Haml::Engine.new(text, options).to_html(options.delete(:scope) || Object.new, &block)
0
+ scope = options.delete(:scope) || Object.new
0
+ locals = options.delete(:locals) || {}
0
+ Haml::Engine.new(text, options).to_html(scope, locals, &block)
0
   end
0
 
0
   def test_empty_render_should_remain_empty
0
@@ -137,12 +139,16 @@ class EngineTest < Test::Unit::TestCase
0
     assert_equal("<p>Paragraph!</p>\n", render("%p= text", :locals => { :text => "Paragraph!" }))
0
   end
0
 
0
- def test_same_templates_with_different_options_should_cache_separately
0
- assert_equal("foobar\n", render("- puts 'foobar'"))
0
- assert_equal("", render("- puts 'foobar'", :suppress_eval => true))
0
+ def test_deprecated_locals_option
0
+ Kernel.module_eval do
0
+ def warn_with_stub(msg); end
0
+ alias_method :warn_without_stub, :warn
0
+ alias_method :warn, :warn_with_stub
0
+ end
0
+
0
+ assert_equal("<p>Paragraph!</p>\n", Haml::Engine.new("%p= text", :locals => { :text => "Paragraph!" }).render)
0
 
0
- assert_equal("<a href='boo'>Boo!</a>\n", render("%a{:href => 'boo'} Boo!"))
0
- assert_equal("<a href=\"boo\">Boo!</a>\n", render("%a{:href => 'boo'} Boo!", :attr_wrapper => '"'))
0
+ Kernel.module_eval { alias_method :warn, :warn_without_stub }
0
   end
0
 
0
   def test_dynamic_attrs_shouldnt_register_as_literal_values
0
@@ -159,49 +165,6 @@ class EngineTest < Test::Unit::TestCase
0
     assert_equal(hash3, hash1)
0
   end
0
 
0
- def test_exception_type
0
- begin
0
- render("%p hi\n= undefined\n= 12")
0
- rescue Exception => e
0
- assert(e.is_a?(Haml::Error))
0
- assert_equal(2, e.haml_line)
0
- assert_equal(nil, e.haml_filename)
0
- assert_equal('(haml):2', e.backtrace[0])
0
- else
0
- # Test failed... should have raised an exception
0
- assert(false)
0
- end
0
- end
0
-
0
- def test_def_method_exception_type
0
- begin
0
- o = Object.new
0
- Haml::Engine.new("%p hi\n= undefined\n= 12").def_method(o, :render)
0
- o.render
0
- rescue Exception => e
0
- assert(e.is_a?(Haml::Error))
0
- assert_equal(2, e.haml_line)
0
- assert_equal(nil, e.haml_filename)
0
- assert_equal('(haml):2', e.backtrace[0])
0
- else
0
- # Test failed... should have raised an exception
0
- assert(false)
0
- end
0
- end
0
- def test_render_proc_exception_type
0
- begin
0
- Haml::Engine.new("%p hi\n= undefined\n= 12").render_proc.call
0
- rescue Exception => e
0
- assert(e.is_a?(Haml::Error))
0
- assert_equal(2, e.haml_line)
0
- assert_equal(nil, e.haml_filename)
0
- assert_equal('(haml):2', e.backtrace[0])
0
- else
0
- # Test failed... should have raised an exception
0
- assert(false)
0
- end
0
- end
0
-
0
   def test_syntax_errors
0
     errs = [ "!!!\n a", "a\n b", "a\n:foo\nb", "/ a\n b",
0
              "% a", "%p a\n b", "a\n%p=\nb", "%p=\n a",
0
@@ -221,30 +184,85 @@ class EngineTest < Test::Unit::TestCase
0
   end
0
 
0
   def test_syntax_error
0
- begin
0
- render("a\nb\n!!!\n c\nd")
0
- rescue Haml::SyntaxError => e
0
- assert_equal(e.message, "Illegal Nesting: Nesting within a header command is illegal.")
0
- assert_equal(3, e.haml_line)
0
- assert_equal(nil, e.haml_filename)
0
- assert_equal('(haml):3', e.backtrace[0])
0
- rescue Exception => e
0
- assert(false, '"a\nb\n!!!\n c\nd" doesn\'t produce a Haml::SyntaxError')
0
- else
0
- assert(false, '"a\nb\n!!!\n c\nd" doesn\'t produce an exception')
0
- end
0
+ render("a\nb\n!!!\n c\nd")
0
+ rescue Haml::SyntaxError => e
0
+ assert_equal(e.message, "Illegal Nesting: Nesting within a header command is illegal.")
0
+ assert_equal(3, e.haml_line)
0
+ assert_equal(nil, e.haml_filename)
0
+ assert_equal('(haml):3', e.backtrace[0])
0
+ rescue Exception => e
0
+ assert(false, '"a\nb\n!!!\n c\nd" doesn\'t produce a Haml::SyntaxError')
0
+ else
0
+ assert(false, '"a\nb\n!!!\n c\nd" doesn\'t produce an exception')
0
+ end
0
+
0
+ def test_exception_type
0
+ render("%p hi\n= undefined\n= 12")
0
+ rescue Exception => e
0
+ assert(e.is_a?(Haml::Error))
0
+ assert_equal(2, e.haml_line)
0
+ assert_equal(nil, e.haml_filename)
0
+ assert_equal('(haml):2', e.backtrace[0])
0
+ else
0
+ # Test failed... should have raised an exception
0
+ assert(false)
0
+ end
0
+
0
+ def test_def_method_exception_type
0
+ o = Object.new
0
+ Haml::Engine.new("%p hi\n= undefined\n= 12").def_method(o, :render)
0
+ o.render
0
+ rescue Exception => e
0
+ assert(e.is_a?(Haml::Error))
0
+ assert_equal(2, e.haml_line)
0
+ assert_equal(nil, e.haml_filename)
0
+ assert_equal('(haml):2', e.backtrace[0])
0
+ else
0
+ # Test failed... should have raised an exception
0
+ assert(false)
0
+ end
0
+
0
+ def test_render_proc_exception_type
0
+ Haml::Engine.new("%p hi\n= undefined\n= 12").render_proc.call
0
+ rescue Exception => e
0
+ assert(e.is_a?(Haml::Error))
0
+ assert_equal(2, e.haml_line)
0
+ assert_equal(nil, e.haml_filename)
0
+ assert_equal('(haml):2', e.backtrace[0])
0
+ else
0
+ # Test failed... should have raised an exception
0
+ assert(false)
0
   end
0
 
0
   def test_compile_error
0
- begin
0
- render("a\nb\n- fee do\nc")
0
- rescue Exception => e
0
- assert_equal("compile error: syntax error, unexpected $end, expecting kEND", e.message)
0
- assert_equal(3, e.haml_line)
0
- else
0
- assert(false,
0
- '"a\nb\n- fee do\nc" doesn\'t produce an exception!')
0
- end
0
+ render("a\nb\n- fee do\nc")
0
+ rescue Exception => e
0
+ assert_match(/^compile error: syntax error/, e.message)
0
+ assert_equal(3, e.haml_line)
0
+ else
0
+ assert(false,
0
+ '"a\nb\n- fee do\nc" doesn\'t produce an exception!')
0
+ end
0
+
0
+ def test_def_method_compile_error
0
+ o = Object.new
0
+ Haml::Engine.new("a\nb\n- fee do\nc").def_method(o, :render)
0
+ rescue Exception => e
0
+ assert_match(/^compile error: syntax error/, e.message)
0
+ assert_equal(3, e.haml_line)
0
+ else
0
+ assert(false,
0
+ '"a\nb\n- fee do\nc" doesn\'t produce an exception!')
0
+ end
0
+
0
+ def test_render_proc_compile_error
0
+ Haml::Engine.new("a\nb\n- fee do\nc").render_proc
0
+ rescue Exception => e
0
+ assert_match(/^compile error: syntax error/, e.message)
0
+ assert_equal(3, e.haml_line)
0
+ else
0
+ assert(false,
0
+ '"a\nb\n- fee do\nc" doesn\'t produce an exception!')
0
   end
0
 
0
   def test_no_bluecloth
0
@@ -354,4 +372,19 @@ class EngineTest < Test::Unit::TestCase
0
     Haml::Engine.new("= yield\n= upcase").def_method(String, :render_haml)
0
     assert_equal("12\nFOO\n", "foo".render_haml { 12 })
0
   end
0
+
0
+ def test_def_method_locals
0
+ obj = Object.new
0
+ Haml::Engine.new("%p= foo\n.bar{:baz => baz}= boom").def_method(obj, :render, :foo, :baz, :boom)
0
+ assert_equal("<p>1</p>\n<div baz='2' class='bar'>3</div>\n", obj.render(:foo => 1, :baz => 2, :boom => 3))
0
+ end
0
+
0
+ def test_render_proc_locals
0
+ proc = Haml::Engine.new("%p= foo\n.bar{:baz => baz}= boom").render_proc(Object.new, :foo, :baz, :boom)
0
+ assert_equal("<p>1</p>\n<div baz='2' class='bar'>3</div>\n", proc[:foo => 1, :baz => 2, :boom => 3])
0
+ end
0
+
0
+ def test_render_proc_with_binding
0
+ assert_equal("FOO\n", Haml::Engine.new("= upcase").render_proc("foo".instance_eval{binding}).call)
0
+ end
0
 end

Comments

    No one has commented yet.