Guest User

Untitled

a guest
Jul 27th, 2013
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. def compile_template_method(locals)
  2. source, offset = precompiled(locals)
  3. offset += 5
  4. method_name = "__tilt_#{Thread.current.object_id.abs}"
  5. Object.class_eval <<-RUBY, eval_file, line - offset
  6. #{extract_magic_comment source}
  7. TOPOBJECT.class_eval do
  8. def #{method_name}(locals)
  9. Thread.current[:tilt_vars] = [self, locals]
  10. class << self
  11. this, locals = Thread.current[:tilt_vars]
  12. this.instance_eval do
  13. #{source}
  14. end
  15. end
  16. end
  17. end
  18. RUBY
  19. unbind_compiled_method(method_name)
  20. end
  21.  
  22. <p>Hello <%= @name %></p>
  23.  
  24. scott = Person.new
  25. scott.name = "Scott"
  26. output = template.render(scott)
  27. => "<p>Hello Scott</p>"
  28.  
  29. baq = Person.new
  30. baq.name = "Baq"
  31. output = template.render(baq)
  32.  
  33. __tilt_2151955260.bind(baq).call
  34.  
  35. object = SomeClass.new
  36. object.param1 = "something"
  37. object.param2 = 43
  38. method.apply(object)
Advertisement
Add Comment
Please, Sign In to add comment