sprockets-cjs 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/Appraisals +31 -0
- data/Gemfile +4 -0
- data/README.md +39 -0
- data/Rakefile +22 -0
- data/examples/application.js +3 -0
- data/examples/example.js +11 -0
- data/examples/index.html +4 -0
- data/examples/modules/program.js +3 -0
- data/examples/modules/user.js +6 -0
- data/gemfiles/sprockets_2_1.gemfile +7 -0
- data/gemfiles/sprockets_2_1.gemfile.lock +28 -0
- data/gemfiles/sprockets_2_2.gemfile +7 -0
- data/gemfiles/sprockets_2_2.gemfile.lock +30 -0
- data/gemfiles/sprockets_2_3.gemfile +7 -0
- data/gemfiles/sprockets_2_3.gemfile.lock +30 -0
- data/gemfiles/sprockets_2_4.gemfile +7 -0
- data/gemfiles/sprockets_2_4.gemfile.lock +30 -0
- data/gemfiles/sprockets_2_5.gemfile +7 -0
- data/gemfiles/sprockets_2_5.gemfile.lock +30 -0
- data/gemfiles/sprockets_2_6.gemfile +7 -0
- data/gemfiles/sprockets_2_6.gemfile.lock +30 -0
- data/gemfiles/sprockets_2_7.gemfile +7 -0
- data/gemfiles/sprockets_2_7.gemfile.lock +30 -0
- data/gemfiles/sprockets_2_8.gemfile +7 -0
- data/gemfiles/sprockets_2_8.gemfile.lock +30 -0
- data/lib/assets/javascripts/sprockets/cjs.js +61 -0
- data/lib/sprockets/cjs/engine.rb +15 -0
- data/lib/sprockets/cjs.rb +49 -0
- data/lib/sprockets-cjs.rb +2 -0
- data/sprockets-cjs.gemspec +25 -0
- data/test/bar.js +1 -0
- data/test/modules/foo.js +1 -0
- data/test/source.js +2 -0
- data/test/sprockets_cjs_test.rb +35 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 64898acf10d5fe233bdd169808758a84fce68076
|
4
|
+
data.tar.gz: 1c6fcc6b441b0f1273cbec13080b3b5042cefb8a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 411b66b90a36da5426b002df41a05bd87eb6afff0c13a023a91a1c8ea8f4f72c9063c9af83bf1d39850b8c94d9d4688c4d321e156f84317041cbfe1b8726d8b7
|
7
|
+
data.tar.gz: cfba1fe22f96ebc00ce6355712cbc40aba10bf10aa33bbbead9f7e37272566d4585281f122ae9fab2fbd44a53efb6432e4fdd471f1fae1e0000efe98f1608753
|
data/.gitignore
ADDED
data/Appraisals
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
appraise "sprockets-2-1" do
|
2
|
+
gem 'sprockets', '~> 2.1.3'
|
3
|
+
end
|
4
|
+
|
5
|
+
appraise "sprockets-2-2" do
|
6
|
+
gem 'sprockets', '~> 2.2.2'
|
7
|
+
end
|
8
|
+
|
9
|
+
appraise "sprockets-2-3" do
|
10
|
+
gem 'sprockets', '~> 2.3.2'
|
11
|
+
end
|
12
|
+
|
13
|
+
appraise "sprockets-2-4" do
|
14
|
+
gem 'sprockets', '~> 2.4.5'
|
15
|
+
end
|
16
|
+
|
17
|
+
appraise "sprockets-2-5" do
|
18
|
+
gem 'sprockets', '~> 2.5.0'
|
19
|
+
end
|
20
|
+
|
21
|
+
appraise "sprockets-2-6" do
|
22
|
+
gem 'sprockets', '~> 2.6.0'
|
23
|
+
end
|
24
|
+
|
25
|
+
appraise "sprockets-2-7" do
|
26
|
+
gem 'sprockets', '~> 2.7.0'
|
27
|
+
end
|
28
|
+
|
29
|
+
appraise "sprockets-2-8" do
|
30
|
+
gem 'sprockets', '~> 2.8.2'
|
31
|
+
end
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
This library adds CommonJS support to [Sprockets](https://github.com/sstephenson/sprockets).
|
2
|
+
|
3
|
+
## About
|
4
|
+
|
5
|
+
This project is a fork of the original [sprockets-commonjs](https://github.com/maccman/sprockets-commonjs).
|
6
|
+
|
7
|
+
Due to the lack of maintainance of the original project, I decided to create a new one based on it, make some changes and publish it as a new gem.
|
8
|
+
|
9
|
+
## What is CommonJS?
|
10
|
+
|
11
|
+
The CommonJS module format is a way of encapsulating JavaScript libraries, ensuring they have to explicitly require and export properties they use. In a nutshell:
|
12
|
+
|
13
|
+
1. You require in files using `require()`:
|
14
|
+
|
15
|
+
var Asset = require('models/asset');
|
16
|
+
|
17
|
+
2. You export properties using `module.exports`:
|
18
|
+
|
19
|
+
var Asset = function(){ /* ... */ };
|
20
|
+
module.exports = Asset;
|
21
|
+
|
22
|
+
## This library
|
23
|
+
|
24
|
+
This library adds CommonJS support to Sprockets, so it can wrap up JavaScript files as modules, and serve them appropriately. This is done by storing any JS files you want in a folder called `modules`
|
25
|
+
|
26
|
+
Sprockets will then wrap up the JS library when it's requested, with the following:
|
27
|
+
|
28
|
+
require.define({'library/name': function(exports, require, module){ /* Your library */ }});
|
29
|
+
|
30
|
+
`require.define()` is defined inside `commonjs.js`, which you'll need to include in the page before any modules are loaded.
|
31
|
+
|
32
|
+
One caveat to the approach this library takes, is that dependencies loaded through `require()` will not be added to the dependency graph. This library will not parse the AST tree for require calls. This decision has been made for a variety of reasons, but it does mean you need to require files through both CommonJS and Sprockets.
|
33
|
+
|
34
|
+
## Usage
|
35
|
+
|
36
|
+
1. Add `gem 'sprockets-cjs'` to your `Gemfile`
|
37
|
+
1. Add your javascript files inside a `modules` folder
|
38
|
+
1. Require all the modules, e.g.: `//= require_tree ./modules`
|
39
|
+
1. Or, require individual modules, e.g.: `//= require ./modules/users`
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'sprockets'
|
3
|
+
require 'sprockets/cjs'
|
4
|
+
require 'rake/testtask'
|
5
|
+
require 'appraisal'
|
6
|
+
|
7
|
+
task :example do
|
8
|
+
env = Sprockets::Environment.new(File.expand_path('..', __FILE__))
|
9
|
+
env.append_path 'examples/'
|
10
|
+
|
11
|
+
target = File.expand_path('../examples/example.js', __FILE__)
|
12
|
+
env['application.js'].write_to target
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
task :default => :test
|
17
|
+
|
18
|
+
Rake::TestTask.new do |t|
|
19
|
+
t.test_files = FileList['test/**/*_test.rb']
|
20
|
+
t.libs << 'lib' << 'test'
|
21
|
+
t.warning = true
|
22
|
+
end
|
data/examples/example.js
ADDED
data/examples/index.html
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
PATH
|
2
|
+
remote: /Users/jamesarosen/Projects/sprockets-commonjs
|
3
|
+
specs:
|
4
|
+
sprockets-commonjs (0.0.4)
|
5
|
+
sprockets (~> 2.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
appraisal (0.5.1)
|
11
|
+
bundler
|
12
|
+
rake
|
13
|
+
hike (1.2.1)
|
14
|
+
rack (1.4.1)
|
15
|
+
rake (10.0.3)
|
16
|
+
sprockets (2.1.3)
|
17
|
+
hike (~> 1.2)
|
18
|
+
rack (~> 1.0)
|
19
|
+
tilt (~> 1.1, != 1.3.0)
|
20
|
+
tilt (1.3.3)
|
21
|
+
|
22
|
+
PLATFORMS
|
23
|
+
ruby
|
24
|
+
|
25
|
+
DEPENDENCIES
|
26
|
+
appraisal (~> 0.5.1)
|
27
|
+
sprockets (~> 2.1.3)
|
28
|
+
sprockets-commonjs!
|
@@ -0,0 +1,30 @@
|
|
1
|
+
PATH
|
2
|
+
remote: /Users/jamesarosen/Projects/sprockets-commonjs
|
3
|
+
specs:
|
4
|
+
sprockets-commonjs (0.0.4)
|
5
|
+
sprockets (~> 2.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
appraisal (0.5.1)
|
11
|
+
bundler
|
12
|
+
rake
|
13
|
+
hike (1.2.1)
|
14
|
+
multi_json (1.5.0)
|
15
|
+
rack (1.4.1)
|
16
|
+
rake (10.0.3)
|
17
|
+
sprockets (2.2.2)
|
18
|
+
hike (~> 1.2)
|
19
|
+
multi_json (~> 1.0)
|
20
|
+
rack (~> 1.0)
|
21
|
+
tilt (~> 1.1, != 1.3.0)
|
22
|
+
tilt (1.3.3)
|
23
|
+
|
24
|
+
PLATFORMS
|
25
|
+
ruby
|
26
|
+
|
27
|
+
DEPENDENCIES
|
28
|
+
appraisal (~> 0.5.1)
|
29
|
+
sprockets (~> 2.2.2)
|
30
|
+
sprockets-commonjs!
|
@@ -0,0 +1,30 @@
|
|
1
|
+
PATH
|
2
|
+
remote: /Users/jamesarosen/Projects/sprockets-commonjs
|
3
|
+
specs:
|
4
|
+
sprockets-commonjs (0.0.4)
|
5
|
+
sprockets (~> 2.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
appraisal (0.5.1)
|
11
|
+
bundler
|
12
|
+
rake
|
13
|
+
hike (1.2.1)
|
14
|
+
multi_json (1.5.0)
|
15
|
+
rack (1.4.1)
|
16
|
+
rake (10.0.3)
|
17
|
+
sprockets (2.3.2)
|
18
|
+
hike (~> 1.2)
|
19
|
+
multi_json (~> 1.0)
|
20
|
+
rack (~> 1.0)
|
21
|
+
tilt (~> 1.1, != 1.3.0)
|
22
|
+
tilt (1.3.3)
|
23
|
+
|
24
|
+
PLATFORMS
|
25
|
+
ruby
|
26
|
+
|
27
|
+
DEPENDENCIES
|
28
|
+
appraisal (~> 0.5.1)
|
29
|
+
sprockets (~> 2.3.2)
|
30
|
+
sprockets-commonjs!
|
@@ -0,0 +1,30 @@
|
|
1
|
+
PATH
|
2
|
+
remote: /Users/jamesarosen/Projects/sprockets-commonjs
|
3
|
+
specs:
|
4
|
+
sprockets-commonjs (0.0.4)
|
5
|
+
sprockets (~> 2.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
appraisal (0.5.1)
|
11
|
+
bundler
|
12
|
+
rake
|
13
|
+
hike (1.2.1)
|
14
|
+
multi_json (1.5.0)
|
15
|
+
rack (1.4.1)
|
16
|
+
rake (10.0.3)
|
17
|
+
sprockets (2.4.5)
|
18
|
+
hike (~> 1.2)
|
19
|
+
multi_json (~> 1.0)
|
20
|
+
rack (~> 1.0)
|
21
|
+
tilt (~> 1.1, != 1.3.0)
|
22
|
+
tilt (1.3.3)
|
23
|
+
|
24
|
+
PLATFORMS
|
25
|
+
ruby
|
26
|
+
|
27
|
+
DEPENDENCIES
|
28
|
+
appraisal (~> 0.5.1)
|
29
|
+
sprockets (~> 2.4.5)
|
30
|
+
sprockets-commonjs!
|
@@ -0,0 +1,30 @@
|
|
1
|
+
PATH
|
2
|
+
remote: /Users/jamesarosen/Projects/sprockets-commonjs
|
3
|
+
specs:
|
4
|
+
sprockets-commonjs (0.0.4)
|
5
|
+
sprockets (~> 2.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
appraisal (0.5.1)
|
11
|
+
bundler
|
12
|
+
rake
|
13
|
+
hike (1.2.1)
|
14
|
+
multi_json (1.5.0)
|
15
|
+
rack (1.4.1)
|
16
|
+
rake (10.0.3)
|
17
|
+
sprockets (2.5.0)
|
18
|
+
hike (~> 1.2)
|
19
|
+
multi_json (~> 1.0)
|
20
|
+
rack (~> 1.0)
|
21
|
+
tilt (~> 1.1, != 1.3.0)
|
22
|
+
tilt (1.3.3)
|
23
|
+
|
24
|
+
PLATFORMS
|
25
|
+
ruby
|
26
|
+
|
27
|
+
DEPENDENCIES
|
28
|
+
appraisal (~> 0.5.1)
|
29
|
+
sprockets (~> 2.5.0)
|
30
|
+
sprockets-commonjs!
|
@@ -0,0 +1,30 @@
|
|
1
|
+
PATH
|
2
|
+
remote: /Users/jamesarosen/Projects/sprockets-commonjs
|
3
|
+
specs:
|
4
|
+
sprockets-commonjs (0.0.4)
|
5
|
+
sprockets (~> 2.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
appraisal (0.5.1)
|
11
|
+
bundler
|
12
|
+
rake
|
13
|
+
hike (1.2.1)
|
14
|
+
multi_json (1.5.0)
|
15
|
+
rack (1.4.1)
|
16
|
+
rake (10.0.3)
|
17
|
+
sprockets (2.6.0)
|
18
|
+
hike (~> 1.2)
|
19
|
+
multi_json (~> 1.0)
|
20
|
+
rack (~> 1.0)
|
21
|
+
tilt (~> 1.1, != 1.3.0)
|
22
|
+
tilt (1.3.3)
|
23
|
+
|
24
|
+
PLATFORMS
|
25
|
+
ruby
|
26
|
+
|
27
|
+
DEPENDENCIES
|
28
|
+
appraisal (~> 0.5.1)
|
29
|
+
sprockets (~> 2.6.0)
|
30
|
+
sprockets-commonjs!
|
@@ -0,0 +1,30 @@
|
|
1
|
+
PATH
|
2
|
+
remote: /Users/jamesarosen/Projects/sprockets-commonjs
|
3
|
+
specs:
|
4
|
+
sprockets-commonjs (0.0.4)
|
5
|
+
sprockets (~> 2.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
appraisal (0.5.1)
|
11
|
+
bundler
|
12
|
+
rake
|
13
|
+
hike (1.2.1)
|
14
|
+
multi_json (1.5.0)
|
15
|
+
rack (1.4.1)
|
16
|
+
rake (10.0.3)
|
17
|
+
sprockets (2.7.0)
|
18
|
+
hike (~> 1.2)
|
19
|
+
multi_json (~> 1.0)
|
20
|
+
rack (~> 1.0)
|
21
|
+
tilt (~> 1.1, != 1.3.0)
|
22
|
+
tilt (1.3.3)
|
23
|
+
|
24
|
+
PLATFORMS
|
25
|
+
ruby
|
26
|
+
|
27
|
+
DEPENDENCIES
|
28
|
+
appraisal (~> 0.5.1)
|
29
|
+
sprockets (~> 2.7.0)
|
30
|
+
sprockets-commonjs!
|
@@ -0,0 +1,30 @@
|
|
1
|
+
PATH
|
2
|
+
remote: /Users/jamesarosen/Projects/sprockets-commonjs
|
3
|
+
specs:
|
4
|
+
sprockets-commonjs (0.0.4)
|
5
|
+
sprockets (~> 2.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
appraisal (0.5.1)
|
11
|
+
bundler
|
12
|
+
rake
|
13
|
+
hike (1.2.1)
|
14
|
+
multi_json (1.5.0)
|
15
|
+
rack (1.4.1)
|
16
|
+
rake (10.0.3)
|
17
|
+
sprockets (2.8.2)
|
18
|
+
hike (~> 1.2)
|
19
|
+
multi_json (~> 1.0)
|
20
|
+
rack (~> 1.0)
|
21
|
+
tilt (~> 1.1, != 1.3.0)
|
22
|
+
tilt (1.3.3)
|
23
|
+
|
24
|
+
PLATFORMS
|
25
|
+
ruby
|
26
|
+
|
27
|
+
DEPENDENCIES
|
28
|
+
appraisal (~> 0.5.1)
|
29
|
+
sprockets (~> 2.8.2)
|
30
|
+
sprockets-commonjs!
|
@@ -0,0 +1,61 @@
|
|
1
|
+
(function() {
|
2
|
+
if (!this.require) {
|
3
|
+
var modules = {}, cache = {};
|
4
|
+
|
5
|
+
var require = function(name, root) {
|
6
|
+
var path = expand(root, name), indexPath = expand(path, './index'), module, fn;
|
7
|
+
module = cache[path] || cache[indexPath];
|
8
|
+
if (module) {
|
9
|
+
return module;
|
10
|
+
} else if (fn = modules[path] || modules[path = indexPath]) {
|
11
|
+
module = {id: path, exports: {}};
|
12
|
+
cache[path] = module.exports;
|
13
|
+
fn(module.exports, function(name) {
|
14
|
+
cache[path] = module.exports;
|
15
|
+
return require(name, dirname(path));
|
16
|
+
}, module);
|
17
|
+
return cache[path] = module.exports;
|
18
|
+
} else {
|
19
|
+
throw 'module ' + name + ' not found';
|
20
|
+
}
|
21
|
+
};
|
22
|
+
|
23
|
+
var expand = function(root, name) {
|
24
|
+
var results = [], parts, part;
|
25
|
+
// If path is relative
|
26
|
+
if (/^\.\.?(\/|$)/.test(name)) {
|
27
|
+
parts = [root, name].join('/').split('/');
|
28
|
+
} else {
|
29
|
+
parts = name.split('/');
|
30
|
+
}
|
31
|
+
for (var i = 0, length = parts.length; i < length; i++) {
|
32
|
+
part = parts[i];
|
33
|
+
if (part == '..') {
|
34
|
+
results.pop();
|
35
|
+
} else if (part != '.' && part != '') {
|
36
|
+
results.push(part);
|
37
|
+
}
|
38
|
+
}
|
39
|
+
return results.join('/');
|
40
|
+
};
|
41
|
+
|
42
|
+
var dirname = function(path) {
|
43
|
+
return path.split('/').slice(0, -1).join('/');
|
44
|
+
};
|
45
|
+
|
46
|
+
this.require = function(name) {
|
47
|
+
return require(name, '');
|
48
|
+
};
|
49
|
+
|
50
|
+
this.require.define = function(bundle) {
|
51
|
+
for (var key in bundle) {
|
52
|
+
modules[key] = bundle[key];
|
53
|
+
}
|
54
|
+
};
|
55
|
+
|
56
|
+
this.require.modules = modules;
|
57
|
+
this.require.cache = cache;
|
58
|
+
}
|
59
|
+
|
60
|
+
return this.require;
|
61
|
+
}).call(this);
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'sprockets/cjs'
|
2
|
+
|
3
|
+
if defined?(Rails)
|
4
|
+
module Sprockets
|
5
|
+
class CJS
|
6
|
+
|
7
|
+
class Engine < ::Rails::Engine
|
8
|
+
initializer :setup_commonjs, :after => "sprockets.environment", :group => :all do |app|
|
9
|
+
app.assets.register_postprocessor 'application/javascript', CJS
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'sprockets'
|
2
|
+
require 'tilt'
|
3
|
+
|
4
|
+
module Sprockets
|
5
|
+
class CJS < Tilt::Template
|
6
|
+
|
7
|
+
WRAPPER = '%s.define({"%s":' +
|
8
|
+
'function(exports, require, module){' +
|
9
|
+
'%s' +
|
10
|
+
";}});\n"
|
11
|
+
|
12
|
+
class << self
|
13
|
+
attr_accessor :default_namespace
|
14
|
+
end
|
15
|
+
|
16
|
+
self.default_mime_type = 'application/javascript'
|
17
|
+
self.default_namespace = 'this.require'
|
18
|
+
|
19
|
+
protected
|
20
|
+
|
21
|
+
def prepare
|
22
|
+
@namespace = self.class.default_namespace
|
23
|
+
end
|
24
|
+
|
25
|
+
def evaluate(scope, locals, &block)
|
26
|
+
if commonjs_module?(scope)
|
27
|
+
scope.require_asset 'sprockets/cjs'
|
28
|
+
WRAPPER % [ namespace, commonjs_module_name(scope), data ]
|
29
|
+
else
|
30
|
+
data
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
attr_reader :namespace
|
37
|
+
|
38
|
+
def commonjs_module?(scope)
|
39
|
+
scope.pathname.to_s.include?('modules')
|
40
|
+
end
|
41
|
+
|
42
|
+
def commonjs_module_name(scope)
|
43
|
+
scope.logical_path.to_s
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
require 'sprockets/cjs/engine'
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "sprockets-cjs"
|
6
|
+
s.version = '0.1.0'
|
7
|
+
s.authors = ["Alex MacCaw, Giulian Drimba"]
|
8
|
+
s.email = ["info@eribium.org","giuliandrimba@gmail.com"]
|
9
|
+
s.homepage = ""
|
10
|
+
s.license = 'MIT'
|
11
|
+
s.summary = %q{Adds CommonJS support to Sprockets}
|
12
|
+
s.description = s.summary
|
13
|
+
|
14
|
+
s.rubyforge_project = "sprockets-cjs"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
# s.add_development_dependency "rspec"
|
23
|
+
s.add_runtime_dependency "sprockets", "~> 2.1"
|
24
|
+
s.add_development_dependency 'appraisal', '~> 0.5.1'
|
25
|
+
end
|
data/test/bar.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
window.bar = "Bar!"
|
data/test/modules/foo.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
module.exports = "Foo!";
|
data/test/source.js
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'tempfile'
|
3
|
+
require 'sprockets-cjs'
|
4
|
+
|
5
|
+
class SprocketsCJSTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
TEST_DIR = File.expand_path('..', __FILE__)
|
8
|
+
LIB_DIR = File.expand_path('../lib/assets/javascripts', TEST_DIR)
|
9
|
+
|
10
|
+
attr_reader :output
|
11
|
+
|
12
|
+
def setup
|
13
|
+
env = Sprockets::Environment.new
|
14
|
+
env.register_postprocessor 'application/javascript', Sprockets::CJS
|
15
|
+
env.append_path TEST_DIR
|
16
|
+
env.append_path LIB_DIR
|
17
|
+
outfile = Tempfile.new('sprockets-output')
|
18
|
+
env['source.js'].write_to outfile.path
|
19
|
+
@output = File.read outfile.path
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_adds_commonjs_require
|
23
|
+
assert_match %r[var require = function\(name, root\) {], @output
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_modularizes_modules
|
27
|
+
assert_match %r[require.define\({\"modules/foo\":function], @output
|
28
|
+
assert_match %r["Foo!"], @output
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_does_not_modularize_non_modules
|
32
|
+
assert_no_match %r[require.define\({\"bar\":function], @output
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sprockets-cjs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alex MacCaw, Giulian Drimba
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-11-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sprockets
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: appraisal
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.5.1
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.5.1
|
41
|
+
description: Adds CommonJS support to Sprockets
|
42
|
+
email:
|
43
|
+
- info@eribium.org
|
44
|
+
- giuliandrimba@gmail.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- .gitignore
|
50
|
+
- Appraisals
|
51
|
+
- Gemfile
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- examples/application.js
|
55
|
+
- examples/example.js
|
56
|
+
- examples/index.html
|
57
|
+
- examples/modules/program.js
|
58
|
+
- examples/modules/user.js
|
59
|
+
- gemfiles/sprockets_2_1.gemfile
|
60
|
+
- gemfiles/sprockets_2_1.gemfile.lock
|
61
|
+
- gemfiles/sprockets_2_2.gemfile
|
62
|
+
- gemfiles/sprockets_2_2.gemfile.lock
|
63
|
+
- gemfiles/sprockets_2_3.gemfile
|
64
|
+
- gemfiles/sprockets_2_3.gemfile.lock
|
65
|
+
- gemfiles/sprockets_2_4.gemfile
|
66
|
+
- gemfiles/sprockets_2_4.gemfile.lock
|
67
|
+
- gemfiles/sprockets_2_5.gemfile
|
68
|
+
- gemfiles/sprockets_2_5.gemfile.lock
|
69
|
+
- gemfiles/sprockets_2_6.gemfile
|
70
|
+
- gemfiles/sprockets_2_6.gemfile.lock
|
71
|
+
- gemfiles/sprockets_2_7.gemfile
|
72
|
+
- gemfiles/sprockets_2_7.gemfile.lock
|
73
|
+
- gemfiles/sprockets_2_8.gemfile
|
74
|
+
- gemfiles/sprockets_2_8.gemfile.lock
|
75
|
+
- lib/assets/javascripts/sprockets/cjs.js
|
76
|
+
- lib/sprockets-cjs.rb
|
77
|
+
- lib/sprockets/cjs.rb
|
78
|
+
- lib/sprockets/cjs/engine.rb
|
79
|
+
- sprockets-cjs.gemspec
|
80
|
+
- test/bar.js
|
81
|
+
- test/modules/foo.js
|
82
|
+
- test/source.js
|
83
|
+
- test/sprockets_cjs_test.rb
|
84
|
+
homepage: ''
|
85
|
+
licenses:
|
86
|
+
- MIT
|
87
|
+
metadata: {}
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project: sprockets-cjs
|
104
|
+
rubygems_version: 2.0.3
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: Adds CommonJS support to Sprockets
|
108
|
+
test_files:
|
109
|
+
- test/bar.js
|
110
|
+
- test/modules/foo.js
|
111
|
+
- test/source.js
|
112
|
+
- test/sprockets_cjs_test.rb
|