Permalink
Browse files

Add Rails 3.2.3 compatibility

  • Loading branch information...
maccman committed Apr 22, 2012
1 parent bab6881 commit f9414732f6c06fea925480479768312361330996
Showing with 17 additions and 81 deletions.
  1. +1 −0 .gitignore
  2. +2 −64 examples/example.js
  3. +0 −5 lib/rails/init.rb
  4. +4 −12 lib/sprockets/commonjs.rb
  5. +10 −0 lib/sprockets/engine.rb
View
@@ -2,3 +2,4 @@
.bundle
Gemfile.lock
pkg/*
+.DS_Store
View
@@ -1,73 +1,11 @@
-(function() {
- if (!this.require) {
- var modules = {}, cache = {};
-
- var require = function(name, root) {
- var path = expand(root, name), indexPath = expand(path, './index'), module, fn;
- module = cache[path] || cache[indexPath];
- if (module) {
- return module;
- } else if (fn = modules[path] || modules[path = indexPath]) {
- module = {id: path, exports: {}};
- cache[path] = module.exports;
- fn(module.exports, function(name) {
- return require(name, dirname(path));
- }, module);
- return cache[path] = module.exports;
- } else {
- throw 'module ' + name + ' not found';
- }
- };
-
- var expand = function(root, name) {
- var results = [], parts, part;
- // If path is relative
- if (/^\.\.?(\/|$)/.test(name)) {
- parts = [root, name].join('/').split('/');
- } else {
- parts = name.split('/');
- }
- for (var i = 0, length = parts.length; i < length; i++) {
- part = parts[i];
- if (part == '..') {
- results.pop();
- } else if (part != '.' && part != '') {
- results.push(part);
- }
- }
- return results.join('/');
- };
-
- var dirname = function(path) {
- return path.split('/').slice(0, -1).join('/');
- };
-
- this.require = function(name) {
- return require(name, '');
- };
-
- this.require.define = function(bundle) {
- for (var key in bundle) {
- modules[key] = bundle[key];
- }
- };
-
- this.require.modules = modules;
- this.require.cache = cache;
- }
-
- return this.require;
-}).call(this);
-this.require.define({"modules/program":function(exports, require, module){module.exports = function(){
+module.exports = function(){
alert('Long live the Programs!');
};
-;}});
-this.require.define({"modules/user":function(exports, require, module){var Program = require('modules/program');
+var Program = require('modules/program');
module.exports = function(){
alert('Long live the Users');
Program();
};
-;}});
var self = 'application.js';
View
@@ -1,5 +0,0 @@
-puts 'LOADED'
-
-# Rails 3.2.3 compatibility
-Rails.application.assets.register_preprocessor 'application/javascript', Sprockets::CommonJS
-Rails.application.assets.append_path File.expand_path('..', __FILE__)
View
@@ -16,8 +16,8 @@ def prepare
attr_reader :namespace
def evaluate(scope, locals, &block)
- if File.extname(scope.logical_path) == '.module'
- path = scope.logical_path.chomp('.module').inspect
+ if scope.pathname.basename.to_s.include?('.module')
+ path = scope.logical_path.inspect
scope.require_asset 'sprockets/commonjs'
@@ -32,14 +32,6 @@ def evaluate(scope, locals, &block)
end
end
end
+end
- # These methods are not available in older versions of Sprockets
-
- if respond_to?(:register_postprocessor)
- register_postprocessor 'application/javascript', CommonJS
- end
-
- if respond_to?(:append_path)
- append_path File.expand_path('../..', __FILE__)
- end
-end
+require 'sprockets/engine'
View
@@ -0,0 +1,10 @@
+if defined?(Rails)
+ module Sprockets
+ class CommonJSEngine < Rails::Engine
+ config.after_initialize do
+ Rails.application.assets.register_postprocessor 'application/javascript', CommonJS
+ Rails.application.assets.append_path File.expand_path('../..', __FILE__)
+ end
+ end
+ end
+end

0 comments on commit f941473

Please sign in to comment.