Sha256: 46de944240cdbf9c89bb4a5cbee8310eb442b6e15700d77dc7d358cdb3bff08e

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

Contents

module Barista
  module HamlFilter
    module CoffeeScript
      
      def render_with_options(text, options)
        type = render_type
        case type
        when :coffeescript
          content_type  = 'text/coffeescript'
          cdata_wrapper = '#%s'
          inner         = text
        when :javascript
          content_type  = 'text/javascript'
          cdata_wrapper = '//%s'
          inner         = Barista::Compiler.compile(text)
        end
        output = []
        output << "<script type=#{options[:attr_wrapper]}#{content_type(type)}#{options[:attr_wrapper]}>"
        output << "  #{cdata_wrapper % '<![CDATA['}"
        output << "  #{inner}".rstrip.gsub("\n", "\n  ")
        output << "  #{cdata_wrapper % ']]>'}"
        output << "</script>"
        output.join("\n")
      end
     
      def render_type
        Barista.embedded_interpreter? ? :coffeescript : :javascript
      end
      
      def content_type(render_type)
        Barista::Server::CONTENT_TYPE_MAPPING[render_type]
      end
        
    end
    
    def self.setup
      if defined?(Haml)
        CoffeeScript.module_eval { include Haml::Filters::Base }
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
barista-0.7.0.pre3 lib/barista/haml_filter.rb
barista-0.7.0.pre2 lib/barista/haml_filter.rb