Sha256: 5fe607b5b89c421b1672672e4b14a09d0e7c0b7104e897bcb21e0e88cbc47315

Contents?: true

Size: 771 Bytes

Versions: 8

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)
        @@context['def'] = {}
      end

      def render(scope=Object.new, locals={}, &block)
        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

8 entries across 8 versions & 1 rubygems

Version Path
sprockets-dotjs-2.0.2 lib/sprockets/dotjs/compiler.rb
sprockets-dotjs-2.0.0 lib/sprockets/dotjs/compiler.rb
sprockets-dotjs-1.1.3 lib/sprockets/dotjs/compiler.rb
sprockets-dotjs-1.1.2 lib/sprockets/dotjs/compiler.rb
sprockets-dotjs-1.1.1 lib/sprockets/dotjs/compiler.rb
sprockets-dotjs-1.1.0 lib/sprockets/dotjs/compiler.rb
sprockets-dotjs-1.0.1 lib/sprockets/dotjs/compiler.rb
sprockets-dotjs-1.0.0 lib/sprockets/dotjs/compiler.rb