requirejs-rails 0.0.1 → 0.0.2

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/Gemfile CHANGED
@@ -5,8 +5,13 @@ source "http://rubygems.org"
5
5
  # development dependencies will be added by default to the :development group.
6
6
  gemspec
7
7
 
8
- # jquery-rails is used by the dummy application
9
- gem "jquery-rails"
8
+ group :development, :test do
9
+ # jquery-rails is used by the dummy application
10
+ gem "jquery-rails"
11
+
12
+ # ExecJS is used by our tests
13
+ gem "execjs"
14
+ end
10
15
 
11
16
  # Declare any dependencies that are still in development here instead of in
12
17
  # your gemspec. These might include edge Rails or gems from your path or
data/Gemfile.lock CHANGED
@@ -1,46 +1,48 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- requirejs-rails (0.0.1)
5
- rails (~> 3.1.1)
4
+ requirejs-rails (0.0.2)
5
+ railties (~> 3.1.1)
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
- actionmailer (3.1.1)
11
- actionpack (= 3.1.1)
10
+ actionmailer (3.1.3)
11
+ actionpack (= 3.1.3)
12
12
  mail (~> 2.3.0)
13
- actionpack (3.1.1)
14
- activemodel (= 3.1.1)
15
- activesupport (= 3.1.1)
13
+ actionpack (3.1.3)
14
+ activemodel (= 3.1.3)
15
+ activesupport (= 3.1.3)
16
16
  builder (~> 3.0.0)
17
17
  erubis (~> 2.7.0)
18
18
  i18n (~> 0.6)
19
- rack (~> 1.3.2)
19
+ rack (~> 1.3.5)
20
20
  rack-cache (~> 1.1)
21
21
  rack-mount (~> 0.8.2)
22
22
  rack-test (~> 0.6.1)
23
- sprockets (~> 2.0.2)
24
- activemodel (3.1.1)
25
- activesupport (= 3.1.1)
23
+ sprockets (~> 2.0.3)
24
+ activemodel (3.1.3)
25
+ activesupport (= 3.1.3)
26
26
  builder (~> 3.0.0)
27
27
  i18n (~> 0.6)
28
- activerecord (3.1.1)
29
- activemodel (= 3.1.1)
30
- activesupport (= 3.1.1)
28
+ activerecord (3.1.3)
29
+ activemodel (= 3.1.3)
30
+ activesupport (= 3.1.3)
31
31
  arel (~> 2.2.1)
32
32
  tzinfo (~> 0.3.29)
33
- activeresource (3.1.1)
34
- activemodel (= 3.1.1)
35
- activesupport (= 3.1.1)
36
- activesupport (3.1.1)
33
+ activeresource (3.1.3)
34
+ activemodel (= 3.1.3)
35
+ activesupport (= 3.1.3)
36
+ activesupport (3.1.3)
37
37
  multi_json (~> 1.0)
38
38
  arel (2.2.1)
39
39
  builder (3.0.0)
40
40
  erubis (2.7.0)
41
+ execjs (1.2.9)
42
+ multi_json (~> 1.0)
41
43
  hike (1.2.1)
42
44
  i18n (0.6.0)
43
- jquery-rails (1.0.17)
45
+ jquery-rails (1.0.18)
44
46
  railties (~> 3.0)
45
47
  thor (~> 0.14)
46
48
  json (1.6.1)
@@ -60,17 +62,17 @@ GEM
60
62
  rack
61
63
  rack-test (0.6.1)
62
64
  rack (>= 1.0)
63
- rails (3.1.1)
64
- actionmailer (= 3.1.1)
65
- actionpack (= 3.1.1)
66
- activerecord (= 3.1.1)
67
- activeresource (= 3.1.1)
68
- activesupport (= 3.1.1)
65
+ rails (3.1.3)
66
+ actionmailer (= 3.1.3)
67
+ actionpack (= 3.1.3)
68
+ activerecord (= 3.1.3)
69
+ activeresource (= 3.1.3)
70
+ activesupport (= 3.1.3)
69
71
  bundler (~> 1.0)
70
- railties (= 3.1.1)
71
- railties (3.1.1)
72
- actionpack (= 3.1.1)
73
- activesupport (= 3.1.1)
72
+ railties (= 3.1.3)
73
+ railties (3.1.3)
74
+ actionpack (= 3.1.3)
75
+ activesupport (= 3.1.3)
74
76
  rack-ssl (~> 1.3.2)
75
77
  rake (>= 0.8.7)
76
78
  rdoc (~> 3.4)
@@ -94,6 +96,8 @@ PLATFORMS
94
96
  ruby
95
97
 
96
98
  DEPENDENCIES
99
+ execjs
97
100
  jquery-rails
101
+ rails (~> 3.1.1)
98
102
  requirejs-rails!
99
103
  sqlite3
data/README.md CHANGED
@@ -4,11 +4,15 @@ Integrates [RequireJS](http://requirejs.org/) into the Rails 3 Asset Pipeline.
4
4
 
5
5
  ## Usage
6
6
 
7
- 1. `gem install requirejs-rails`
7
+ 1. Add this to your Rails app's `Gemfile`:
8
+
9
+ ```
10
+ gem 'requirejs-rails'
11
+ ```
8
12
 
9
13
  2. Your `application.js` file should contain just this snippet. The rest of your JavaScript or CoffeeScript code should be pulled in via RequireJS, including jQuery.
10
14
 
11
- ```
15
+ ```javascript
12
16
  //= require require
13
17
 
14
18
  require.config({
@@ -16,7 +20,57 @@ Integrates [RequireJS](http://requirejs.org/) into the Rails 3 Asset Pipeline.
16
20
  });
17
21
  ```
18
22
 
19
- 3. Add any additional config directives you need to the above code, e.g. `paths`.
23
+ 3. Add any additional [config options](http://requirejs.org/docs/api.html#config) you need to the above code, e.g. `paths`.
24
+
25
+ 4. Organize your JavaScript or CoffeeScript code into modules using `define()`:
26
+
27
+ ```coffeescript
28
+ # app/assets/javascripts/views/tweet_view.js.coffee
29
+
30
+ define ['backbone'], (Backbone) ->
31
+ class TweetView extends Backbone.View
32
+ # ...
33
+ ```
34
+
35
+ 5. Instantiate your app using `require()` from a top-level script such as `application.js` or a controller-specific file ala `mycontroller.js.coffee`:
36
+
37
+ ```coffeescript
38
+ # app/assets/javascripts/mycontroller.js.coffee
39
+
40
+ require ['jquery', 'backbone', 'TheApp'], ($, Backbone, TheApp) ->
41
+
42
+ # Start up the app once the DOM is ready
43
+ $ ->
44
+ window.App = new TheApp()
45
+ Backbone.history.start
46
+ pushState: true
47
+ window.App.start()
48
+ ```
49
+
50
+
51
+ ## Using AMD libraries
52
+
53
+ I currently recommend placing your AMD libraries into `vendor/assets/javascripts`. The needs of a few specific libraries are discussed below.
54
+
55
+ ### jQuery
56
+
57
+ jQuery users must use jQuery 1.7 or later (`jquery-rails >= 1.0.17`) to use it as an [AMD module](http://wiki.commonjs.org/wiki/Modules/AsynchronousDefinition) with RequireJS. The boilerplate in `application.js` remains unchanged. To use jQuery in a module:
58
+
59
+ ```coffeescript
60
+ # app/assets/javascripts/hello.js
61
+
62
+ define ['jquery'], ($) ->
63
+ (id) ->
64
+ $(id).append('<div>hello!</div>')
65
+ ```
66
+
67
+ ### Backbone.js
68
+
69
+ Backbone AMD support is underway in documentcloud/backbone#710. In the meantime, you can download [Backbone 0.5.3 with AMD support](https://github.com/jrburke/backbone/raw/optamd3/backbone.js) from [jrburke's optamd3 branch](https://github.com/jrburke/backbone/tree/optamd3). Backbone's module name is `backbone`.
70
+
71
+ ### Underscore.js
72
+
73
+ Underscore version 1.2.2 or later has integrated AMD support. Get it from [Underscore.js' homepage](http://documentcloud.github.com/underscore/). Underscore's module name is `underscore`.
20
74
 
21
75
  ## Changes
22
76
 
@@ -25,7 +79,7 @@ See [the Changelog](CHANGELOG.md) for recent updates
25
79
  ## TODOs
26
80
 
27
81
  - Sample app, including jQuery usage
28
- - Support RequireJS precompilation via r.js
82
+ - Support RequireJS precompilation via r.js (see issue #1)
29
83
  - Generator and/or template support.. ?
30
84
 
31
85
  ----
@@ -1,4 +1 @@
1
- module Requirejs
2
- module Rails
3
- end
4
- end
1
+ require 'requirejs/rails'
@@ -0,0 +1,5 @@
1
+ module Requirejs
2
+ module Rails
3
+ require 'requirejs/rails/engine'
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ module Requirejs
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -1,5 +1,5 @@
1
1
  module Requirejs
2
2
  module Rails
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -18,8 +18,9 @@ Gem::Specification.new do |s|
18
18
  s.files = git_files
19
19
  s.require_path = 'lib'
20
20
 
21
- s.add_dependency "rails", "~> 3.1.1"
22
- s.requirements << "If needed, jQuery should be v1.7 or greater (jquery-rails >= 1.0.17)."
23
-
21
+ s.add_dependency "railties", "~> 3.1.1"
22
+ s.add_development_dependency "rails", "~> 3.1.1"
24
23
  s.add_development_dependency "sqlite3"
24
+
25
+ s.requirements << "If needed, jQuery should be v1.7 or greater (jquery-rails >= 1.0.17)."
25
26
  end
data/test/dummy/.rvmrc ADDED
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
7
+ environment_id="ruby-1.9.3-p0@requirejs-rails"
8
+
9
+ #
10
+ # Uncomment following line if you want options to be set only for given project.
11
+ #
12
+ # PROJECT_JRUBY_OPTS=( --1.9 )
13
+
14
+ #
15
+ # First we attempt to load the desired environment directly from the environment
16
+ # file. This is very fast and efficient compared to running through the entire
17
+ # CLI and selector. If you want feedback on which environment was used then
18
+ # insert the word 'use' after --create as this triggers verbose mode.
19
+ #
20
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
21
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
22
+ then
23
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
24
+
25
+ if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
26
+ then
27
+ . "${rvm_path:-$HOME/.rvm}/hooks/after_use"
28
+ fi
29
+ else
30
+ # If the environment file has not yet been created, use the RVM CLI to select.
31
+ if ! rvm --create use "$environment_id"
32
+ then
33
+ echo "Failed to create RVM environment '${environment_id}'."
34
+ return 1
35
+ fi
36
+ fi
37
+
38
+ #
39
+ # If you use an RVM gemset file to install a list of gems (*.gems), you can have
40
+ # it be automatically loaded. Uncomment the following and adjust the filename if
41
+ # necessary.
42
+ #
43
+ # filename=".gems"
44
+ # if [[ -s "$filename" ]]
45
+ # then
46
+ # rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
47
+ # fi
48
+
49
+ # If you use bundler, this might be useful to you:
50
+ # if command -v bundle && [[ -s Gemfile ]]
51
+ # then
52
+ # bundle install
53
+ # fi
54
+
55
+
@@ -1,8 +1,18 @@
1
1
  require 'test_helper'
2
2
 
3
+ require 'execjs'
4
+ require 'pathname'
5
+
3
6
  class RequirejsRailsTest < ActiveSupport::TestCase
4
7
  test "truth" do
5
8
  assert_kind_of Module, Requirejs
6
9
  assert_kind_of Module, Requirejs::Rails
10
+ assert_kind_of Class, Requirejs::Rails::Engine
11
+ end
12
+
13
+ test "require.js version" do
14
+ require_js = Pathname.new(__FILE__+'/../../vendor/assets/javascripts/require.js').cleanpath.read
15
+ context = ExecJS.compile(require_js)
16
+ assert_equal "1.0.2", context.eval("require.version")
7
17
  end
8
18
  end
@@ -1,5 +1,5 @@
1
1
  /** vim: et:ts=4:sw=4:sts=4
2
- * @license RequireJS 1.0.1 Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
2
+ * @license RequireJS 1.0.2 Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
3
3
  * Available via the MIT or new BSD license.
4
4
  * see: http://github.com/jrburke/requirejs for details
5
5
  */
@@ -11,7 +11,7 @@
11
11
  var requirejs, require, define;
12
12
  (function () {
13
13
  //Change this version number for each release.
14
- var version = "1.0.1",
14
+ var version = "1.0.2",
15
15
  commentRegExp = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg,
16
16
  cjsRequireRegExp = /require\(\s*["']([^'"\s]+)["']\s*\)/g,
17
17
  currDirRegExp = /^\.\//,
@@ -268,6 +268,10 @@ var requirejs, require, define;
268
268
  if (pkgConfig && name === pkgName + '/' + pkgConfig.main) {
269
269
  name = pkgName;
270
270
  }
271
+ } else if (name.indexOf("./") === 0) {
272
+ // No baseName, so this is ID is resolved relative
273
+ // to baseUrl, pull off the leading dot.
274
+ name = name.substring(2);
271
275
  }
272
276
  }
273
277
  return name;
@@ -407,7 +411,8 @@ var requirejs, require, define;
407
411
  map = manager.map,
408
412
  fullName = map.fullName,
409
413
  args = manager.deps,
410
- listeners = manager.listeners;
414
+ listeners = manager.listeners,
415
+ cjsModule;
411
416
 
412
417
  //Call the callback to define the module, if necessary.
413
418
  if (cb && isFunction(cb)) {
@@ -425,7 +430,11 @@ var requirejs, require, define;
425
430
  //If setting exports via "module" is in play,
426
431
  //favor that over return value and exports. After that,
427
432
  //favor a non-undefined return value over exports use.
428
- if (manager.cjsModule && manager.cjsModule.exports !== undefined) {
433
+ cjsModule = manager.cjsModule;
434
+ if (cjsModule &&
435
+ cjsModule.exports !== undefined &&
436
+ //Make sure it is not already the exports value
437
+ cjsModule.exports !== defined[fullName]) {
429
438
  ret = defined[fullName] = manager.cjsModule.exports;
430
439
  } else if (ret === undefined && manager.usingExports) {
431
440
  //exports already set the defined value.
@@ -1048,7 +1057,16 @@ var requirejs, require, define;
1048
1057
  //Regular dependency.
1049
1058
  if (!urlFetched[url] && !loaded[fullName]) {
1050
1059
  req.load(context, fullName, url);
1051
- urlFetched[url] = true;
1060
+
1061
+ //Mark the URL as fetched, but only if it is
1062
+ //not an empty: URL, used by the optimizer.
1063
+ //In that case we need to be sure to call
1064
+ //load() for each module that is mapped to
1065
+ //empty: so that dependencies are satisfied
1066
+ //correctly.
1067
+ if (url.indexOf('empty:') !== 0) {
1068
+ urlFetched[url] = true;
1069
+ }
1052
1070
  }
1053
1071
  }
1054
1072
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: requirejs-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-17 00:00:00.000000000 Z
12
+ date: 2011-11-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: rails
16
- requirement: &70111022200320 !ruby/object:Gem::Requirement
15
+ name: railties
16
+ requirement: &70199933410040 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,21 @@ dependencies:
21
21
  version: 3.1.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70111022200320
24
+ version_requirements: *70199933410040
25
+ - !ruby/object:Gem::Dependency
26
+ name: rails
27
+ requirement: &70199933409200 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 3.1.1
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70199933409200
25
36
  - !ruby/object:Gem::Dependency
26
37
  name: sqlite3
27
- requirement: &70111022199640 !ruby/object:Gem::Requirement
38
+ requirement: &70199933408160 !ruby/object:Gem::Requirement
28
39
  none: false
29
40
  requirements:
30
41
  - - ! '>='
@@ -32,7 +43,7 @@ dependencies:
32
43
  version: '0'
33
44
  type: :development
34
45
  prerelease: false
35
- version_requirements: *70111022199640
46
+ version_requirements: *70199933408160
36
47
  description: This gem provides RequireJS support for your Rails 3 application.
37
48
  email:
38
49
  - whitley@bangpath.org
@@ -49,11 +60,14 @@ files:
49
60
  - README.md
50
61
  - Rakefile
51
62
  - lib/requirejs-rails.rb
63
+ - lib/requirejs/rails.rb
64
+ - lib/requirejs/rails/engine.rb
52
65
  - lib/requirejs/rails/version.rb
53
66
  - lib/tasks/requirejs-rails_tasks.rake
54
67
  - requirejs-rails.gemspec
55
68
  - vendor/assets/javascripts/order.js
56
69
  - vendor/assets/javascripts/require.js
70
+ - test/dummy/.rvmrc
57
71
  - test/dummy/Rakefile
58
72
  - test/dummy/app/assets/javascripts/application.js
59
73
  - test/dummy/app/assets/stylesheets/application.css
@@ -101,7 +115,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
101
115
  version: '0'
102
116
  segments:
103
117
  - 0
104
- hash: 1237549975689155325
118
+ hash: 2678184901028172103
105
119
  required_rubygems_version: !ruby/object:Gem::Requirement
106
120
  none: false
107
121
  requirements:
@@ -110,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
124
  version: '0'
111
125
  segments:
112
126
  - 0
113
- hash: 1237549975689155325
127
+ hash: 2678184901028172103
114
128
  requirements:
115
129
  - If needed, jQuery should be v1.7 or greater (jquery-rails >= 1.0.17).
116
130
  rubyforge_project:
@@ -119,6 +133,7 @@ signing_key:
119
133
  specification_version: 3
120
134
  summary: Use RequireJS with the Rails 3 Asset Pipeline
121
135
  test_files:
136
+ - test/dummy/.rvmrc
122
137
  - test/dummy/Rakefile
123
138
  - test/dummy/app/assets/javascripts/application.js
124
139
  - test/dummy/app/assets/stylesheets/application.css