sprockets-commonjs 0.0.4 → 0.0.5.pre

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/examples/example.js CHANGED
@@ -1,11 +1,73 @@
1
- module.exports = function(){
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(){
2
62
  alert('Long live the Programs!');
3
63
  };
4
- var Program = require('modules/program');
64
+ ;}});
65
+ this.require.define({"modules/user":function(exports, require, module){var Program = require('modules/program');
5
66
 
6
67
  module.exports = function(){
7
68
  alert('Long live the Users');
8
69
  Program();
9
70
  };
71
+ ;}});
10
72
 
11
73
  var self = 'application.js';
@@ -16,13 +16,15 @@ module Sprockets
16
16
  attr_reader :namespace
17
17
 
18
18
  def evaluate(scope, locals, &block)
19
- if scope.pathname.basename.to_s.include?('.module')
20
- path = scope.logical_path.inspect
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
21
23
 
22
24
  scope.require_asset 'sprockets/commonjs'
23
25
 
24
26
  code = ''
25
- code << "#{namespace}.define({#{path}:"
27
+ code << "#{namespace}.define({#{path.inspect}:"
26
28
  code << 'function(exports, require, module){'
27
29
  code << data
28
30
  code << ";}});\n"
@@ -32,6 +34,7 @@ module Sprockets
32
34
  end
33
35
  end
34
36
  end
35
- end
36
37
 
37
- require 'sprockets/engine'
38
+ register_postprocessor 'application/javascript', CommonJS
39
+ append_path File.expand_path('../..', __FILE__)
40
+ 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.4'
6
+ s.version = '0.0.5.pre'
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.1.2"
22
+ s.add_runtime_dependency "sprockets", "~>2.4.0"
23
23
  end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sprockets-commonjs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
5
- prerelease:
4
+ version: 0.0.5.pre
5
+ prerelease: 6
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-29 00:00:00.000000000Z
12
+ date: 2012-05-22 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sprockets
16
- requirement: &70359291282860 !ruby/object:Gem::Requirement
16
+ requirement: &70340791091400 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 2.1.2
21
+ version: 2.4.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70359291282860
24
+ version_requirements: *70340791091400
25
25
  description: Adds CommonJS support to Sprockets
26
26
  email:
27
27
  - info@eribium.org
@@ -38,9 +38,8 @@ files:
38
38
  - examples/index.html
39
39
  - examples/modules/program.module.js
40
40
  - examples/modules/user.module.js
41
- - lib/assets/javascripts/sprockets/commonjs.js
41
+ - lib/sprockets/commonjs.js
42
42
  - lib/sprockets/commonjs.rb
43
- - lib/sprockets/engine.rb
44
43
  - sprockets-commonjs.gemspec
45
44
  homepage: ''
46
45
  licenses: []
@@ -57,9 +56,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
57
56
  required_rubygems_version: !ruby/object:Gem::Requirement
58
57
  none: false
59
58
  requirements:
60
- - - ! '>='
59
+ - - ! '>'
61
60
  - !ruby/object:Gem::Version
62
- version: '0'
61
+ version: 1.3.1
63
62
  requirements: []
64
63
  rubyforge_project: sprockets-commonjs
65
64
  rubygems_version: 1.8.15
@@ -1,9 +0,0 @@
1
- if defined?(Rails)
2
- module Sprockets
3
- class CommonJSEngine < Rails::Engine
4
- initializer :setup_commonjs do |app|
5
- app.assets.register_postprocessor 'application/javascript', CommonJS
6
- end
7
- end
8
- end
9
- end