PageRenderTime 37ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/tools/drillbit/Resources/tests/ruby/markaby/lib/markaby/rails.rb

http://github.com/appcelerator/titanium_desktop
Ruby | 46 lines | 22 code | 5 blank | 19 comment | 0 complexity | 3eed7c9400b96285d8c2596e2b3ae311 MD5 | raw file
Possible License(s): Apache-2.0
  1. module Markaby
  2. # Markaby helpers for Rails.
  3. module ActionControllerHelpers
  4. # Returns a string of HTML built from the attached +block+. Any +options+ are
  5. # passed into the render method.
  6. #
  7. # Use this method in your controllers to output Markaby directly from inside.
  8. def render_markaby(options = {}, &block)
  9. render options.merge({ :text => Builder.new({}, self, &block).to_s })
  10. end
  11. end
  12. class ActionViewTemplateHandler
  13. def initialize(action_view)
  14. @action_view = action_view
  15. end
  16. def render(template, local_assigns = {})
  17. Template.new(template).render(@action_view.assigns.merge(local_assigns), @action_view)
  18. end
  19. end
  20. class Builder
  21. # Emulate ERB to satisfy helpers like <tt>form_for</tt>.
  22. def _erbout; self end
  23. # Content_for will store the given block in an instance variable for later use
  24. # in another template or in the layout.
  25. #
  26. # The name of the instance variable is content_for_<name> to stay consistent
  27. # with @content_for_layout which is used by ActionView's layouts.
  28. #
  29. # Example:
  30. #
  31. # content_for("header") do
  32. # h1 "Half Shark and Half Lion"
  33. # end
  34. #
  35. # If used several times, the variable will contain all the parts concatenated.
  36. def content_for(name, &block)
  37. @helpers.assigns["content_for_#{name}"] =
  38. eval("@content_for_#{name} = (@content_for_#{name} || '') + capture(&block)")
  39. end
  40. end
  41. end