Sha256: 847fc3d2e4abcb8fc940d99fee156fa709cbfb908c60c39397c6f235cab92f97

Contents?: true

Size: 754 Bytes

Versions: 2

Compression:

Stored size: 754 Bytes

Contents

require 'sprockets'
require 'tilt'

module Sprockets
  class CommonJS < Tilt::Template
    self.default_mime_type = 'application/javascript'

    def self.default_namespace
      'this.require'
    end

    def prepare
      @namespace = self.class.default_namespace
    end

    attr_reader :namespace

    def evaluate(scope, locals, &block)
      if scope.pathname.basename.to_s.include?('.module')
        path = scope.logical_path.inspect

        scope.require_asset 'sprockets/commonjs'

        code = ''
        code << "#{namespace}.define({#{path}:"
        code << 'function(exports, require, module){'
        code << data
        code << ";}});\n"
        code
      else
        data
      end
    end
  end
end

require 'sprockets/engine'

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sprockets-commonjs-0.0.4 lib/sprockets/commonjs.rb
sprockets-commonjs-0.0.3 lib/sprockets/commonjs.rb