sprockets-commonjs 0.0.6.pre → 0.0.6.rc1
Sign up to get free protection for your applications and to get access to all the features.
data/examples/example.js
CHANGED
@@ -58,7 +58,7 @@
|
|
58
58
|
|
59
59
|
return this.require;
|
60
60
|
}).call(this);
|
61
|
-
this.require.define({"modules/program":function(exports, require, module){module.exports = function(){
|
61
|
+
this.require.define({"modules/program.cjs":function(exports, require, module){module.exports = function(){
|
62
62
|
alert('Long live the Programs!');
|
63
63
|
};
|
64
64
|
;}});
|
File without changes
|
data/lib/sprockets/commonjs.rb
CHANGED
@@ -3,38 +3,53 @@ require 'tilt'
|
|
3
3
|
|
4
4
|
module Sprockets
|
5
5
|
class CommonJS < Tilt::Template
|
6
|
-
self.default_mime_type = 'application/javascript'
|
7
6
|
|
8
|
-
|
9
|
-
|
7
|
+
WRAPPER = '%s.define({%s:' +
|
8
|
+
'function(exports, require, module){' +
|
9
|
+
'%s' +
|
10
|
+
";}});\n"
|
11
|
+
|
12
|
+
EXTENSIONS = %w{.module .cjs}
|
13
|
+
|
14
|
+
class << self
|
15
|
+
attr_accessor :default_namespace
|
10
16
|
end
|
11
17
|
|
18
|
+
self.default_mime_type = 'application/javascript'
|
19
|
+
self.default_namespace = 'this.require'
|
20
|
+
|
21
|
+
protected
|
22
|
+
|
12
23
|
def prepare
|
13
24
|
@namespace = self.class.default_namespace
|
14
25
|
end
|
15
26
|
|
16
|
-
attr_reader :namespace
|
17
|
-
|
18
27
|
def evaluate(scope, locals, &block)
|
19
|
-
if
|
20
|
-
path = scope.logical_path
|
21
|
-
path = path.gsub(/^\.?\//, '') # Remove relative paths
|
22
|
-
path = path.chomp('.module') # Remove module ext
|
23
|
-
|
28
|
+
if commonjs_module?(scope)
|
24
29
|
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
|
30
|
+
WRAPPER % [ namespace, module_name(scope), data ]
|
32
31
|
else
|
33
32
|
data
|
34
33
|
end
|
35
34
|
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
attr_reader :namespace
|
39
|
+
|
40
|
+
def commonjs_module?(scope)
|
41
|
+
EXTENSIONS.include?(File.extname(scope.logical_path))
|
42
|
+
end
|
43
|
+
|
44
|
+
def module_name(scope)
|
45
|
+
scope.logical_path.
|
46
|
+
gsub(/^\.?\//, ''). # Remove relative paths
|
47
|
+
chomp('.module'). # Remove module ext
|
48
|
+
inspect
|
49
|
+
end
|
50
|
+
|
36
51
|
end
|
37
52
|
|
38
53
|
register_postprocessor 'application/javascript', CommonJS
|
39
54
|
append_path File.expand_path('../../../assets', __FILE__)
|
40
|
-
end
|
55
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'sprockets/commonjs'
|
data/sprockets-commonjs.gemspec
CHANGED
@@ -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.6.
|
6
|
+
s.version = '0.0.6.rc1'
|
7
7
|
s.authors = ["Alex MacCaw"]
|
8
8
|
s.email = ["info@eribium.org"]
|
9
9
|
s.homepage = ""
|
@@ -19,5 +19,5 @@ 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.
|
22
|
+
s.add_runtime_dependency "sprockets", "~>2.9.2"
|
23
23
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sprockets-commonjs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.6.
|
4
|
+
version: 0.0.6.rc1
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,19 +9,19 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-04-14 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sprockets
|
16
|
-
requirement: &
|
16
|
+
requirement: &70242533873200 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 2.
|
21
|
+
version: 2.9.2
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70242533873200
|
25
25
|
description: Adds CommonJS support to Sprockets
|
26
26
|
email:
|
27
27
|
- info@eribium.org
|
@@ -37,8 +37,9 @@ files:
|
|
37
37
|
- examples/application.js
|
38
38
|
- examples/example.js
|
39
39
|
- examples/index.html
|
40
|
-
- examples/modules/program.
|
40
|
+
- examples/modules/program.cjs.js
|
41
41
|
- examples/modules/user.module.js
|
42
|
+
- lib/sprockets-commonjs.rb
|
42
43
|
- lib/sprockets/commonjs.rb
|
43
44
|
- sprockets-commonjs.gemspec
|
44
45
|
homepage: ''
|