Sha256: b9d5e7afcd2a76dc0ca7b933fd3bcbc874575937a4bbd98312703a730d16490f

Contents?: true

Size: 869 Bytes

Versions: 4

Compression:

Stored size: 869 Bytes

Contents

require 'haml-sprockets/version'
require 'tilt'
require 'sprockets'
require 'execjs'

module Haml
  module Sprockets
    class Template < ::Tilt::Template
      def self.engine_initialized?
        true
      end

      def initialize_engine
      end

      def prepare
      end

      def evaluate(scope, locals, &block)
        haml_code = data.dup
        haml_code = haml_code.gsub(/\\/,"\\\\").gsub(/\'/,"\\\\'").gsub(/\n/,"\\n")

        haml_path = File.expand_path("../../vendor/assets/javascripts/haml.js", __FILE__)
        haml_lib = File.read(haml_path)
        context = ExecJS.compile(haml_lib)
        return context.eval("new Haml('#{haml_code}', {escapeHtmlByDefault: true}).toString()")
      end
    end
  end
end

Sprockets::Engines
Sprockets.register_engine '.hamljs', Haml::Sprockets::Template
require 'haml-sprockets/engine' if defined?(Rails)

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mobox-0.0.3 vendor/haml-sprockets/lib/haml-sprockets.rb
mobox-0.0.2 vendor/haml-sprockets/lib/haml-sprockets.rb
mobox-0.0.1.1 vendor/haml-sprockets/lib/haml-sprockets.rb
mobox-0.0.1 vendor/haml-sprockets/lib/haml-sprockets.rb