sprockets_cjs 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README.markdown +7 -0
- data/Rakefile +2 -0
- data/lib/sprockets_cjs.rb +10 -0
- data/lib/sprockets_cjs/cjs_template.rb +29 -0
- data/lib/sprockets_cjs/engine.rb +12 -0
- data/lib/sprockets_cjs/preprocessor.rb +27 -0
- data/lib/sprockets_cjs/version.rb +6 -0
- data/sprockets_cjs.gemspec +21 -0
- data/vendor/assets/javascripts/common_js.js +58 -0
- metadata +96 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 RedBeard Tech
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'tilt'
|
2
|
+
|
3
|
+
module Sprockets
|
4
|
+
module CommonJS
|
5
|
+
|
6
|
+
class CjsTemplate < Tilt::Template
|
7
|
+
self.default_mime_type = 'application/javascript'
|
8
|
+
|
9
|
+
def self.engine_initialized?
|
10
|
+
true
|
11
|
+
end
|
12
|
+
|
13
|
+
def prepare
|
14
|
+
options[:bare] = true
|
15
|
+
end
|
16
|
+
|
17
|
+
def evaluate(scope, locals, &block)
|
18
|
+
@output ||= "\nrequire.define({'#{ module_name(scope) }': function(exports, require, module) {\n" + data + "\n}});\n"
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def module_name(scope)
|
24
|
+
scope.logical_path =~ /\// ? scope.logical_path.split('/')[-2..-1].join('/') : scope.logical_path
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Sprockets
|
2
|
+
module CommonJS
|
3
|
+
|
4
|
+
class Engine < ::Rails::Engine
|
5
|
+
initializer 'sprockets.common_js.configure_rails_initialization' do |app|
|
6
|
+
app.assets.register_preprocessor 'application/javascript', Sprockets::CommonJS::Preprocessor
|
7
|
+
app.assets.register_engine '.cjs', Sprockets::CommonJS::CjsTemplate
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'tilt'
|
2
|
+
|
3
|
+
module Sprockets
|
4
|
+
module CommonJS
|
5
|
+
|
6
|
+
class Preprocessor < Tilt::Template
|
7
|
+
def prepare; end
|
8
|
+
|
9
|
+
def evaluate(context, locals, &block)
|
10
|
+
context.require_asset 'common_js'
|
11
|
+
|
12
|
+
data.lines.each do |line|
|
13
|
+
if line =~ /.*require\s*\(\s*[\'\"]([^\)]+)[\'\"]\s*\)/
|
14
|
+
begin
|
15
|
+
context.require_asset($1)
|
16
|
+
rescue Sprockets::FileNotFound
|
17
|
+
context.require_asset("./" + $1)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
data
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/sprockets_cjs/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "sprockets_cjs"
|
6
|
+
s.version = Sprockets::CommonJS::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ["Matt Hodgson"]
|
9
|
+
s.email = ["mhodgson@redbeard-tech.com"]
|
10
|
+
s.homepage = "http://github.com/redbeard-tech/sprockets-cjs"
|
11
|
+
s.summary = "Use CommonJS modules with Sprockets 2"
|
12
|
+
s.description = "A preprocessor and engine for using CommonJS modules with Sprockets 2"
|
13
|
+
|
14
|
+
s.required_rubygems_version = ">= 1.3.6"
|
15
|
+
|
16
|
+
s.add_dependency "sprockets", [">= 2.0.0"]
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.executables = `git ls-files`.split("\n").select{|f| f =~ /^bin/}
|
20
|
+
s.require_path = 'lib'
|
21
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
(function() {
|
2
|
+
if (!this.require) {
|
3
|
+
|
4
|
+
var modules = {},
|
5
|
+
cache = {},
|
6
|
+
require = function(name, root) {
|
7
|
+
var module = cache[name], path = expand(root, name), fn;
|
8
|
+
if (module) {
|
9
|
+
return module;
|
10
|
+
} else if (fn = modules[path] || modules[path = expand(path, './index')]) {
|
11
|
+
module = {id: name, exports: {}};
|
12
|
+
try {
|
13
|
+
cache[name] = module.exports;
|
14
|
+
|
15
|
+
fn(module.exports, function(name) {
|
16
|
+
return require(name, dirname(path));
|
17
|
+
}, module);
|
18
|
+
|
19
|
+
return cache[name] = module.exports;
|
20
|
+
} catch (err) {
|
21
|
+
delete cache[name];
|
22
|
+
throw err;
|
23
|
+
}
|
24
|
+
} else {
|
25
|
+
throw 'module "' + name + '" not found';
|
26
|
+
}
|
27
|
+
},
|
28
|
+
expand = function(root, name) {
|
29
|
+
var results = [], parts, part;
|
30
|
+
if (/^\.\.?(\/|$)/.test(name)) {
|
31
|
+
parts = [root, name].join('/').split('/');
|
32
|
+
} else {
|
33
|
+
parts = name.split('/');
|
34
|
+
}
|
35
|
+
for (var i = 0, length = parts.length; i < length; i++) {
|
36
|
+
part = parts[i];
|
37
|
+
if (part == '..') {
|
38
|
+
results.pop();
|
39
|
+
} else if (part != '.' && part != '') {
|
40
|
+
results.push(part);
|
41
|
+
}
|
42
|
+
}
|
43
|
+
return results.join('/');
|
44
|
+
},
|
45
|
+
dirname = function(path) {
|
46
|
+
return path.split('/').slice(0, -1).join('/');
|
47
|
+
};
|
48
|
+
|
49
|
+
this.require = function(name) {
|
50
|
+
return require(name, '');
|
51
|
+
}
|
52
|
+
|
53
|
+
this.require.define = function(bundle) {
|
54
|
+
for (var key in bundle)
|
55
|
+
modules[key] = bundle[key];
|
56
|
+
};
|
57
|
+
}
|
58
|
+
}).call(this)
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sprockets_cjs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Matt Hodgson
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-09-24 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: sprockets
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 15
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 0
|
33
|
+
- 0
|
34
|
+
version: 2.0.0
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
description: A preprocessor and engine for using CommonJS modules with Sprockets 2
|
38
|
+
email:
|
39
|
+
- mhodgson@redbeard-tech.com
|
40
|
+
executables: []
|
41
|
+
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
extra_rdoc_files: []
|
45
|
+
|
46
|
+
files:
|
47
|
+
- .gitignore
|
48
|
+
- Gemfile
|
49
|
+
- LICENSE
|
50
|
+
- README.markdown
|
51
|
+
- Rakefile
|
52
|
+
- lib/sprockets_cjs.rb
|
53
|
+
- lib/sprockets_cjs/cjs_template.rb
|
54
|
+
- lib/sprockets_cjs/engine.rb
|
55
|
+
- lib/sprockets_cjs/preprocessor.rb
|
56
|
+
- lib/sprockets_cjs/version.rb
|
57
|
+
- sprockets_cjs.gemspec
|
58
|
+
- vendor/assets/javascripts/common_js.js
|
59
|
+
has_rdoc: true
|
60
|
+
homepage: http://github.com/redbeard-tech/sprockets-cjs
|
61
|
+
licenses: []
|
62
|
+
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
hash: 3
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
version: "0"
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
hash: 23
|
83
|
+
segments:
|
84
|
+
- 1
|
85
|
+
- 3
|
86
|
+
- 6
|
87
|
+
version: 1.3.6
|
88
|
+
requirements: []
|
89
|
+
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 1.6.2
|
92
|
+
signing_key:
|
93
|
+
specification_version: 3
|
94
|
+
summary: Use CommonJS modules with Sprockets 2
|
95
|
+
test_files: []
|
96
|
+
|