Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def compile_template_method(locals)
- source, offset = precompiled(locals)
- offset += 5
- method_name = "__tilt_#{Thread.current.object_id.abs}"
- Object.class_eval <<-RUBY, eval_file, line - offset
- #{extract_magic_comment source}
- TOPOBJECT.class_eval do
- def #{method_name}(locals)
- Thread.current[:tilt_vars] = [self, locals]
- class << self
- this, locals = Thread.current[:tilt_vars]
- this.instance_eval do
- #{source}
- end
- end
- end
- end
- RUBY
- unbind_compiled_method(method_name)
- end
- <p>Hello <%= @name %></p>
- scott = Person.new
- scott.name = "Scott"
- output = template.render(scott)
- => "<p>Hello Scott</p>"
- baq = Person.new
- baq.name = "Baq"
- output = template.render(baq)
- __tilt_2151955260.bind(baq).call
- object = SomeClass.new
- object.param1 = "something"
- object.param2 = 43
- method.apply(object)
Advertisement
Add Comment
Please, Sign In to add comment