Sha256: be8d96e2b6dd3a1b5d09f89ae538dbd3dbfbda11f86c9367e0b46ca576866fb3

Contents?: true

Size: 771 Bytes

Versions: 3

Compression:

Stored size: 771 Bytes

Contents

require 'sprockets'
require 'tilt/template'
require 'v8'

module Sprockets
  module DotJS
    class Compiler < Tilt::Template
      def self.default_mime_type
        'application/javascript'
      end

      def prepare
      end


      def initialize_engine
        dotjs_lib = open(::File.join(::File.dirname(__FILE__), '..', '..', 'support', 'doT.js')).read
        @@context = ::V8::Context.new
        @@context.eval(dotjs_lib)
      end

      def render(scope=Object.new, locals={}, &block)
        @@context['def'] = {}
        scope._dependency_paths.each {|a|
          @@context['doT']['compile'].call(open(a).read,@@context['def'])
        }
        val = @@context['doT']['compile'].call(data,@@context['def'])
        val.to_s
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sprockets-dotjs-2.1.1 lib/sprockets/dotjs/compiler.rb
sprockets-dotjs-2.1.0 lib/sprockets/dotjs/compiler.rb
sprockets-dotjs-2.0.3 lib/sprockets/dotjs/compiler.rb