/scalate-jruby/src/main/resources/haml-3.0.25/lib/haml/helpers/action_view_extensions.rb

http://github.com/scalate/scalate · Ruby · 57 lines · 18 code · 3 blank · 36 comment · 0 complexity · 65a7848175c56c979bb5bdaaefc62531 MD5 · raw file

  1. module Haml
  2. module Helpers
  3. @@action_view_defined = true
  4. # This module contains various useful helper methods
  5. # that either tie into ActionView or the rest of the ActionPack stack,
  6. # or are only useful in that context.
  7. # Thus, the methods defined here are only available
  8. # if ActionView is installed.
  9. module ActionViewExtensions
  10. # Returns a value for the "class" attribute
  11. # unique to this controller/action pair.
  12. # This can be used to target styles specifically at this action or controller.
  13. # For example, if the current action were `EntryController#show`,
  14. #
  15. # %div{:class => page_class} My Div
  16. #
  17. # would become
  18. #
  19. # <div class="entry show">My Div</div>
  20. #
  21. # Then, in a stylesheet (shown here as {Sass}),
  22. # you could refer to this specific action:
  23. #
  24. # .entry.show
  25. # font-weight: bold
  26. #
  27. # or to all actions in the entry controller:
  28. #
  29. # .entry
  30. # color: #00f
  31. #
  32. # @return [String] The class name for the current page
  33. def page_class
  34. controller.controller_name + " " + controller.action_name
  35. end
  36. alias_method :generate_content_class_names, :page_class
  37. # Treats all input to \{Haml::Helpers#haml\_concat} within the block
  38. # as being HTML safe for Rails' XSS protection.
  39. # This is useful for wrapping blocks of code that concatenate HTML en masse.
  40. #
  41. # This has no effect if Rails' XSS protection isn't enabled.
  42. #
  43. # @yield A block in which all input to `#haml_concat` is treated as raw.
  44. # @see Haml::Util#rails_xss_safe?
  45. def with_raw_haml_concat
  46. @_haml_concat_raw, old = true, @_haml_concat_raw
  47. yield
  48. ensure
  49. @_haml_concat_raw = old
  50. end
  51. end
  52. include ActionViewExtensions
  53. end
  54. end