Module: EZML::Filters::Javascript

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

Instance Method Summary collapse

Methods included from Base

#compile, included, #internal_compile, #render

Instance Method Details

#render_with_options(text, options) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/ezml/filters.rb', line 94

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