class Haml::Filters::Opal

Public Instance Methods

compile(node) click to toggle source
# File lib/opal/rails/haml6_filter.rb, line 11
def compile(node)
  template = [:multi]
  template << [:static, "<script type='#{mime_type}'>\n"]
  template << [:static, ::Opal.compile(node.value[:text]) ]
  template << [:static, "\n</script>"]
  template
end
mime_type() click to toggle source
# File lib/opal/rails/haml5_filter.rb, line 4
def mime_type
  ::Opal::Config.esm ? 'module' : 'text/javascript'
end
render_with_options(ruby, options) click to toggle source
# File lib/opal/rails/haml5_filter.rb, line 8
  def render_with_options ruby, options
    text = ::Opal.compile(ruby)

    if options[:format] == :html5
      type = ''
    else
      type = " type=#{options[:attr_wrapper]}#{mime_type}#{options[:attr_wrapper]}"
    end

    text.rstrip!
    text.gsub!("\n", "\n    ")

    <<HTML
<script#{type}>
  //<![CDATA[
    #{text}
  //]]>
</script>
HTML
  end