Module: Haml::Template

Extended by:
Template
Included in:
Template
Defined in:
lib/haml/template.rb

Overview

The class that keeps track of the global options for Haml within Rails.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#options{Symbol => Object}

The options hash for Haml when used within Rails. See the Haml options documentation.

Returns:

  • ({Symbol => Object})


15
16
17
# File 'lib/haml/template.rb', line 15

def options
  @options
end

Instance Method Details

#try_enabling_xss_integrationBoolean

Enables integration with the Rails 2.2.5+ XSS protection, if it's available and enabled.

Returns:

  • (Boolean)

    Whether the XSS integration was enabled.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/haml/template.rb', line 21

def try_enabling_xss_integration
  return false unless ActionView::Base.respond_to?(:xss_safe?) && ActionView::Base.xss_safe?

  Haml::Template.options[:escape_html] = true

  Haml::Util.module_eval {def rails_xss_safe?; true; end}

  require 'haml/helpers/xss_mods'
  Haml::Helpers.send(:include, Haml::Helpers::XssMods)

  Haml::Precompiler.module_eval do
    def precompiled_method_return_value_with_haml_xss
      "::Haml::Util.html_safe(#{precompiled_method_return_value_without_haml_xss})"
    end
    alias_method :precompiled_method_return_value_without_haml_xss, :precompiled_method_return_value
    alias_method :precompiled_method_return_value, :precompiled_method_return_value_with_haml_xss
  end

  true
end