PageRenderTime 47ms CodeModel.GetById 39ms app.highlight 6ms RepoModel.GetById 2ms app.codeStats 0ms

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