sprockets-commonjs 0.0.5.pre → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
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 CHANGED
@@ -1,4 +1,4 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in sprockets-commonjs.gemspec
4
- gemspec
4
+ gemspec
data/Rakefile CHANGED
@@ -2,6 +2,7 @@ require 'bundler/gem_tasks'
2
2
  require 'sprockets'
3
3
  require 'sprockets/commonjs'
4
4
  require 'rake/testtask'
5
+ require 'appraisal'
5
6
 
6
7
  task :example do
7
8
  env = Sprockets::Environment.new(File.expand_path('..', __FILE__))
@@ -15,6 +16,7 @@ end
15
16
  task :default => :test
16
17
 
17
18
  Rake::TestTask.new do |t|
18
- t.libs << "test"
19
+ t.test_files = FileList['test/**/*_test.rb']
20
+ t.libs << 'lib' << 'test'
19
21
  t.warning = true
20
22
  end
data/examples/example.js CHANGED
@@ -1,73 +1,11 @@
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
- return require(name, dirname(path));
15
- }, module);
16
- return cache[path] = module.exports;
17
- } else {
18
- throw 'module ' + name + ' not found';
19
- }
20
- };
21
-
22
- var expand = function(root, name) {
23
- var results = [], parts, part;
24
- // If path is relative
25
- if (/^\.\.?(\/|$)/.test(name)) {
26
- parts = [root, name].join('/').split('/');
27
- } else {
28
- parts = name.split('/');
29
- }
30
- for (var i = 0, length = parts.length; i < length; i++) {
31
- part = parts[i];
32
- if (part == '..') {
33
- results.pop();
34
- } else if (part != '.' && part != '') {
35
- results.push(part);
36
- }
37
- }
38
- return results.join('/');
39
- };
40
-
41
- var dirname = function(path) {
42
- return path.split('/').slice(0, -1).join('/');
43
- };
44
-
45
- this.require = function(name) {
46
- return require(name, '');
47
- };
48
-
49
- this.require.define = function(bundle) {
50
- for (var key in bundle) {
51
- modules[key] = bundle[key];
52
- }
53
- };
54
-
55
- this.require.modules = modules;
56
- this.require.cache = cache;
57
- }
58
-
59
- return this.require;
60
- }).call(this);
61
- this.require.define({"modules/program":function(exports, require, module){module.exports = function(){
1
+ module.exports = function(){
62
2
  alert('Long live the Programs!');
63
3
  };
64
- ;}});
65
- this.require.define({"modules/user":function(exports, require, module){var Program = require('modules/program');
4
+ var Program = require('modules/program');
66
5
 
67
6
  module.exports = function(){
68
7
  alert('Long live the Users');
69
8
  Program();
70
9
  };
71
- ;}});
72
10
 
73
11
  var self = 'application.js';
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "sprockets", "~> 2.1.3"
6
+
7
+ gemspec :path=>"../"
@@ -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,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "sprockets", "~> 2.2.2"
6
+
7
+ gemspec :path=>"../"
@@ -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,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "sprockets", "~> 2.3.2"
6
+
7
+ gemspec :path=>"../"
@@ -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,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "sprockets", "~> 2.4.5"
6
+
7
+ gemspec :path=>"../"
@@ -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,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "sprockets", "~> 2.5.0"
6
+
7
+ gemspec :path=>"../"
@@ -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,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "sprockets", "~> 2.6.0"
6
+
7
+ gemspec :path=>"../"
@@ -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,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "sprockets", "~> 2.7.0"
6
+
7
+ gemspec :path=>"../"
@@ -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,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "sprockets", "~> 2.8.2"
6
+
7
+ gemspec :path=>"../"
@@ -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,2 @@
1
+ require 'sprockets/commonjs'
2
+ require 'sprockets/commonjs/engine'
@@ -3,38 +3,47 @@ require 'tilt'
3
3
 
4
4
  module Sprockets
5
5
  class CommonJS < Tilt::Template
6
- self.default_mime_type = 'application/javascript'
7
6
 
8
- def self.default_namespace
9
- 'this.require'
7
+ WRAPPER = '%s.define({"%s":' +
8
+ 'function(exports, require, module){' +
9
+ '%s' +
10
+ ";}});\n"
11
+
12
+ class << self
13
+ attr_accessor :default_namespace
10
14
  end
11
15
 
16
+ self.default_mime_type = 'application/javascript'
17
+ self.default_namespace = 'this.require'
18
+
19
+ protected
20
+
12
21
  def prepare
13
22
  @namespace = self.class.default_namespace
14
23
  end
15
24
 
16
- attr_reader :namespace
17
-
18
25
  def evaluate(scope, locals, &block)
19
- if File.extname(scope.logical_path) == '.module'
20
- path = scope.logical_path
21
- path = path.gsub(/^\.?\//, '') # Remove relative paths
22
- path = path.chomp('.module') # Remove module ext
23
-
26
+ if commonjs_module?(scope)
24
27
  scope.require_asset 'sprockets/commonjs'
25
-
26
- code = ''
27
- code << "#{namespace}.define({#{path.inspect}:"
28
- code << 'function(exports, require, module){'
29
- code << data
30
- code << ";}});\n"
31
- code
28
+ WRAPPER % [ namespace, commonjs_module_name(scope), data ]
32
29
  else
33
30
  data
34
31
  end
35
32
  end
33
+
34
+ private
35
+
36
+ attr_reader :namespace
37
+
38
+ def commonjs_module?(scope)
39
+ scope.pathname.basename.to_s.include?('.module')
40
+ end
41
+
42
+ def commonjs_module_name(scope)
43
+ scope.logical_path.sub(/\.module$/, '')
44
+ end
45
+
36
46
  end
47
+ end
37
48
 
38
- register_postprocessor 'application/javascript', CommonJS
39
- append_path File.expand_path('../..', __FILE__)
40
- end
49
+ require 'sprockets/commonjs/engine'
@@ -0,0 +1,15 @@
1
+ require 'sprockets/commonjs'
2
+
3
+ if defined?(Rails)
4
+ module Sprockets
5
+ class CommonJS
6
+
7
+ class Engine < Rails::Engine
8
+ initializer :setup_commonjs, :after => "sprockets.environment", :group => :all do |app|
9
+ app.assets.register_postprocessor 'application/javascript', CommonJS
10
+ end
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "sprockets-commonjs"
6
- s.version = '0.0.5.pre'
6
+ s.version = '0.0.5'
7
7
  s.authors = ["Alex MacCaw"]
8
8
  s.email = ["info@eribium.org"]
9
9
  s.homepage = ""
@@ -19,5 +19,6 @@ Gem::Specification.new do |s|
19
19
 
20
20
  # specify any dependencies here; for example:
21
21
  # s.add_development_dependency "rspec"
22
- s.add_runtime_dependency "sprockets", "~>2.4.0"
22
+ s.add_runtime_dependency "sprockets", "~> 2.1"
23
+ s.add_development_dependency 'appraisal', '~> 0.5.1'
23
24
  end
data/test/bar.js ADDED
@@ -0,0 +1 @@
1
+ window.bar = "Bar!"
@@ -0,0 +1 @@
1
+ module.exports = "Foo!";
data/test/source.js ADDED
@@ -0,0 +1,2 @@
1
+ //= require foo.module.js
2
+ //= require bar.js
@@ -0,0 +1,35 @@
1
+ require 'test/unit'
2
+ require 'tempfile'
3
+ require 'sprockets-commonjs'
4
+
5
+ class SprocketsCommonjsTest < 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::CommonJS
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\({\"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 CHANGED
@@ -1,27 +1,48 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sprockets-commonjs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5.pre
5
- prerelease: 6
4
+ version: 0.0.5
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Alex MacCaw
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-22 00:00:00.000000000Z
12
+ date: 2013-01-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sprockets
16
- requirement: &70340791091400 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 2.4.0
21
+ version: '2.1'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70340791091400
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '2.1'
30
+ - !ruby/object:Gem::Dependency
31
+ name: appraisal
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 0.5.1
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.5.1
25
46
  description: Adds CommonJS support to Sprockets
26
47
  email:
27
48
  - info@eribium.org
@@ -30,6 +51,7 @@ extensions: []
30
51
  extra_rdoc_files: []
31
52
  files:
32
53
  - .gitignore
54
+ - Appraisals
33
55
  - Gemfile
34
56
  - README.md
35
57
  - Rakefile
@@ -38,9 +60,31 @@ files:
38
60
  - examples/index.html
39
61
  - examples/modules/program.module.js
40
62
  - examples/modules/user.module.js
41
- - lib/sprockets/commonjs.js
63
+ - gemfiles/sprockets_2_1.gemfile
64
+ - gemfiles/sprockets_2_1.gemfile.lock
65
+ - gemfiles/sprockets_2_2.gemfile
66
+ - gemfiles/sprockets_2_2.gemfile.lock
67
+ - gemfiles/sprockets_2_3.gemfile
68
+ - gemfiles/sprockets_2_3.gemfile.lock
69
+ - gemfiles/sprockets_2_4.gemfile
70
+ - gemfiles/sprockets_2_4.gemfile.lock
71
+ - gemfiles/sprockets_2_5.gemfile
72
+ - gemfiles/sprockets_2_5.gemfile.lock
73
+ - gemfiles/sprockets_2_6.gemfile
74
+ - gemfiles/sprockets_2_6.gemfile.lock
75
+ - gemfiles/sprockets_2_7.gemfile
76
+ - gemfiles/sprockets_2_7.gemfile.lock
77
+ - gemfiles/sprockets_2_8.gemfile
78
+ - gemfiles/sprockets_2_8.gemfile.lock
79
+ - lib/assets/javascripts/sprockets/commonjs.js
80
+ - lib/sprockets-commonjs.rb
42
81
  - lib/sprockets/commonjs.rb
82
+ - lib/sprockets/commonjs/engine.rb
43
83
  - sprockets-commonjs.gemspec
84
+ - test/bar.js
85
+ - test/foo.module.js
86
+ - test/source.js
87
+ - test/sprockets_commonjs_test.rb
44
88
  homepage: ''
45
89
  licenses: []
46
90
  post_install_message:
@@ -53,16 +97,26 @@ required_ruby_version: !ruby/object:Gem::Requirement
53
97
  - - ! '>='
54
98
  - !ruby/object:Gem::Version
55
99
  version: '0'
100
+ segments:
101
+ - 0
102
+ hash: 26412344906566093
56
103
  required_rubygems_version: !ruby/object:Gem::Requirement
57
104
  none: false
58
105
  requirements:
59
- - - ! '>'
106
+ - - ! '>='
60
107
  - !ruby/object:Gem::Version
61
- version: 1.3.1
108
+ version: '0'
109
+ segments:
110
+ - 0
111
+ hash: 26412344906566093
62
112
  requirements: []
63
113
  rubyforge_project: sprockets-commonjs
64
- rubygems_version: 1.8.15
114
+ rubygems_version: 1.8.24
65
115
  signing_key:
66
116
  specification_version: 3
67
117
  summary: Adds CommonJS support to Sprockets
68
- test_files: []
118
+ test_files:
119
+ - test/bar.js
120
+ - test/foo.module.js
121
+ - test/source.js
122
+ - test/sprockets_commonjs_test.rb