sprockets-commonjs 0.0.2 → 0.0.3

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 CHANGED
@@ -2,3 +2,4 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ .DS_Store
data/README.md CHANGED
@@ -29,4 +29,5 @@ One caveat to the approach this library takes, is that dependencies loaded throu
29
29
 
30
30
  1. Add `gem 'sprockets-commonjs'` to your `Gemfile`
31
31
  1. Add `.module.js` to any JavaScript files you want as modules, i.e. `users.module.js`
32
- 1. Require all the modules, e.g.: `//= require_tree ./modules`
32
+ 1. Require all the modules, e.g.: `//= require_tree ./models`
33
+ 1. Or, require individual modules, e.g.: `//= require users.module`
data/examples/example.js CHANGED
@@ -1,74 +1,11 @@
1
- (function() {
2
- var modules = {}, cache = {};
3
-
4
- if (this.require && this.require.modules) {
5
- modules = this.require.modules;
6
- }
7
-
8
- var require = function(name, root) {
9
- var path = expand(root, name), indexPath = expand(path, './index'), module, fn;
10
- module = cache[path] || cache[indexPath];
11
- if (module) {
12
- return module;
13
- } else if (fn = modules[path] || modules[path = indexPath]) {
14
- module = {id: path, exports: {}};
15
- cache[path] = module.exports;
16
- fn(module.exports, function(name) {
17
- return require(name, dirname(path));
18
- }, module);
19
- return cache[path] = module.exports;
20
- } else {
21
- throw 'module ' + name + ' not found';
22
- }
23
- };
24
-
25
- var expand = function(root, name) {
26
- var results = [], parts, part;
27
- // If path is relative
28
- if (/^\.\.?(\/|$)/.test(name)) {
29
- parts = [root, name].join('/').split('/');
30
- } else {
31
- parts = name.split('/');
32
- }
33
- for (var i = 0, length = parts.length; i < length; i++) {
34
- part = parts[i];
35
- if (part == '..') {
36
- results.pop();
37
- } else if (part != '.' && part != '') {
38
- results.push(part);
39
- }
40
- }
41
- return results.join('/');
42
- };
43
-
44
- var dirname = function(path) {
45
- return path.split('/').slice(0, -1).join('/');
46
- };
47
-
48
- this.require = function(name) {
49
- return require(name, '');
50
- };
51
-
52
- this.require.define = function(bundle) {
53
- for (var key in bundle) {
54
- modules[key] = bundle[key];
55
- }
56
- };
57
-
58
- this.require.modules = modules;
59
- this.require.cache = cache;
60
- return this.require;
61
- }).call(this);
62
- this.require.define({"modules/program.module":function(exports, require, module){module.exports = function(){
1
+ module.exports = function(){
63
2
  alert('Long live the Programs!');
64
3
  };
65
- ;}});
66
- this.require.define({"modules/user.module":function(exports, require, module){var Program = require('modules/program');
4
+ var Program = require('modules/program');
67
5
 
68
6
  module.exports = function(){
69
7
  alert('Long live the Users');
70
8
  Program();
71
9
  };
72
- ;}});
73
10
 
74
11
  var self = 'application.js';
@@ -16,10 +16,8 @@ module Sprockets
16
16
  attr_reader :namespace
17
17
 
18
18
  def evaluate(scope, locals, &block)
19
- if File.extname(scope.logical_path) == '.module'
20
- path = scope.logical_path
21
- path = File.join(File.dirname(path), File.basename(path, '.module'))
22
- path = path.inspect
19
+ if scope.pathname.basename.to_s.include?('.module')
20
+ path = scope.logical_path.inspect
23
21
 
24
22
  scope.require_asset 'sprockets/commonjs'
25
23
 
@@ -34,7 +32,6 @@ module Sprockets
34
32
  end
35
33
  end
36
34
  end
37
-
38
- register_postprocessor 'application/javascript', CommonJS
39
- append_path File.expand_path('../..', __FILE__)
40
35
  end
36
+
37
+ require 'sprockets/engine'
@@ -0,0 +1,10 @@
1
+ if defined?(Rails)
2
+ module Sprockets
3
+ class CommonJSEngine < Rails::Engine
4
+ config.after_initialize do
5
+ Rails.application.assets.register_postprocessor 'application/javascript', CommonJS
6
+ Rails.application.assets.append_path File.expand_path('../..', __FILE__)
7
+ end
8
+ end
9
+ end
10
+ 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.2'
6
+ s.version = '0.0.3'
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.4.0"
22
+ s.add_runtime_dependency "sprockets", "~>2.1.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.2
4
+ version: 0.0.3
5
5
  prerelease:
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: 2012-03-27 00:00:00.000000000Z
12
+ date: 2012-04-22 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sprockets
16
- requirement: &70172867486660 !ruby/object:Gem::Requirement
16
+ requirement: &70210125726500 !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.2
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70172867486660
24
+ version_requirements: *70210125726500
25
25
  description: Adds CommonJS support to Sprockets
26
26
  email:
27
27
  - info@eribium.org
@@ -40,6 +40,7 @@ files:
40
40
  - examples/modules/user.module.js
41
41
  - lib/sprockets/commonjs.js
42
42
  - lib/sprockets/commonjs.rb
43
+ - lib/sprockets/engine.rb
43
44
  - sprockets-commonjs.gemspec
44
45
  homepage: ''
45
46
  licenses: []