Module: Haml::Filters::Javascript

Includes:
Base
Defined in:
lib/haml/filters.rb

Overview

Surrounds the filtered text with <script> and CDATA tags. Useful for including inline Javascript.

Instance Method Summary collapse

Methods included from Base

#compile, included, #internal_compile, #render

Instance Method Details

#render_with_options(text, options)

212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/haml/filters.rb', line 212

def render_with_options(text, options)
  indent = options[:cdata] ? '    ' : '  ' # 4 or 2 spaces
  if options[:format] == :html5
    type = ''
  else
    type = " type=#{options[:attr_wrapper]}text/javascript#{options[:attr_wrapper]}"
  end

  text = text.rstrip
  text.gsub!("\n", "\n#{indent}")

  %!<script#{type}>\n#{"  //<![CDATA[\n" if options[:cdata]}#{indent}#{text}\n#{"  //]]>\n" if options[:cdata]}</script>!
end