Skip to content

Commit

Permalink
allow CJS as a ext
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-stripe committed Aug 17, 2012
1 parent 453cc37 commit a08dfff
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/example.js
Expand Up @@ -58,7 +58,7 @@


return this.require; return this.require;
}).call(this); }).call(this);
this.require.define({"modules/program":function(exports, require, module){module.exports = function(){ this.require.define({"modules/program.cjs":function(exports, require, module){module.exports = function(){
alert('Long live the Programs!'); alert('Long live the Programs!');
}; };
;}}); ;}});
Expand Down
File renamed without changes.
6 changes: 4 additions & 2 deletions lib/sprockets/commonjs.rb
Expand Up @@ -4,11 +4,13 @@
module Sprockets module Sprockets
class CommonJS < Tilt::Template class CommonJS < Tilt::Template


DEFINE_WRAPPER = '%s.define({%s:' + WRAPPER = '%s.define({%s:' +
'function(exports, require, module){' + 'function(exports, require, module){' +
'%s' + '%s' +
";}});\n" ";}});\n"


EXTENSIONS = %w{.module .cjs}

class << self class << self
attr_accessor :default_namespace attr_accessor :default_namespace
end end
Expand Down Expand Up @@ -36,7 +38,7 @@ def evaluate(scope, locals, &block)
attr_reader :namespace attr_reader :namespace


def commonjs_module?(scope) def commonjs_module?(scope)
File.extname(scope.logical_path) == '.module' EXTENSIONS.include?(File.extname(scope.logical_path))
end end


def module_name(scope) def module_name(scope)
Expand Down

0 comments on commit a08dfff

Please sign in to comment.