ruby-requirejs 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.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +25 -0
  3. data/Gemfile +6 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +85 -0
  6. data/Rakefile +1 -0
  7. data/lib/requirejs/action_view/tag_helper.rb +15 -0
  8. data/lib/requirejs/builds/build.js.erb +8 -0
  9. data/lib/requirejs/builds/build.rb +18 -0
  10. data/lib/requirejs/builds/build_config.rb +59 -0
  11. data/lib/requirejs/builds/optimized_build.rb +57 -0
  12. data/lib/requirejs/compiler.rb +21 -0
  13. data/lib/requirejs/config.rb +72 -0
  14. data/lib/requirejs/engine.rb +40 -0
  15. data/lib/requirejs/manifest.rb +56 -0
  16. data/lib/requirejs/runtime/node_runner.js +21 -0
  17. data/lib/requirejs/runtime/r.js +27617 -0
  18. data/lib/requirejs/runtime/runtime.rb +59 -0
  19. data/lib/requirejs/tilt/directive_processor.rb +52 -0
  20. data/lib/requirejs/tilt/template.rb +37 -0
  21. data/lib/requirejs/version.rb +5 -0
  22. data/lib/ruby-requirejs.rb +26 -0
  23. data/ruby-requirejs.gemspec +24 -0
  24. data/spec/cases/basic/in/app.js +10 -0
  25. data/spec/cases/basic/in/application.js +7 -0
  26. data/spec/cases/basic/out/application.js +6 -0
  27. data/spec/cases/basic_almond/in/app.js +10 -0
  28. data/spec/cases/basic_almond/in/application.js +7 -0
  29. data/spec/cases/basic_almond/out/application.js +447 -0
  30. data/spec/cases/basic_digested/in/app.js +10 -0
  31. data/spec/cases/basic_digested/in/application.js +7 -0
  32. data/spec/cases/basic_digested/out/application.js +14 -0
  33. data/spec/cases/basic_minimized_almond/in/app.js +10 -0
  34. data/spec/cases/basic_minimized_almond/in/application.js +7 -0
  35. data/spec/cases/basic_minimized_almond/out/application.js +7 -0
  36. data/spec/cases/basic_optimized/in/app.js +10 -0
  37. data/spec/cases/basic_optimized/in/application.js +7 -0
  38. data/spec/cases/basic_optimized/out/application.js +21 -0
  39. data/spec/cases/simple/in/app.js +10 -0
  40. data/spec/cases/simple/in/application.js +35 -0
  41. data/spec/rails_spec.rb +80 -0
  42. data/spec/spec_helper.rb +22 -0
  43. data/spec/support/helpers.rb +40 -0
  44. data/vendor/assets/javascripts/almond.js +422 -0
  45. data/vendor/assets/javascripts/require.js +2072 -0
  46. metadata +136 -0
@@ -0,0 +1,10 @@
1
+ define([], function () {
2
+
3
+ // initialize Application
4
+ var initialize = function () {
5
+ };
6
+
7
+ return {
8
+ initialize: initialize
9
+ };
10
+ });
@@ -0,0 +1,7 @@
1
+ //= rjs
2
+
3
+ require.config({});
4
+
5
+ require(["app"], function (App) {
6
+ App.initialize();
7
+ });
@@ -0,0 +1,14 @@
1
+ require.config({
2
+ paths: {
3
+ "almond": "/assets/almond-598c5f5bd57e4cef3a47fd1eb57b42f0",
4
+ "require": "/assets/require-98f98918193401dc83b22bb7fe50bd4a",
5
+ "app": "/assets/app-e7983d1a4757650fe064cf673ac7d7e6"
6
+ }
7
+ });
8
+
9
+ require.config({});
10
+
11
+ require(["app"], function (App) {
12
+ App.initialize();
13
+ });
14
+
@@ -0,0 +1,10 @@
1
+ define([], function () {
2
+
3
+ // initialize Application
4
+ var initialize = function () {
5
+ };
6
+
7
+ return {
8
+ initialize: initialize
9
+ };
10
+ });
@@ -0,0 +1,7 @@
1
+ //= rjs
2
+
3
+ require.config({});
4
+
5
+ require(["app"], function (App) {
6
+ App.initialize();
7
+ });
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @license almond 0.2.9 Copyright (c) 2011-2014, The Dojo Foundation All Rights Reserved.
3
+ * Available via the MIT or new BSD license.
4
+ * see: http://github.com/jrburke/almond for details
5
+ */
6
+
7
+ (function(){var e,t,n;(function(r){function v(e,t){return h.call(e,t)}function m(e,t){var n,r,i,s,o,u,a,f,c,h,p,v=t&&t.split("/"),m=l.map,g=m&&m["*"]||{};if(e&&e.charAt(0)===".")if(t){v=v.slice(0,v.length-1),e=e.split("/"),o=e.length-1,l.nodeIdCompat&&d.test(e[o])&&(e[o]=e[o].replace(d,"")),e=v.concat(e);for(c=0;c<e.length;c+=1){p=e[c];if(p===".")e.splice(c,1),c-=1;else if(p===".."){if(c===1&&(e[2]===".."||e[0]===".."))break;c>0&&(e.splice(c-1,2),c-=2)}}e=e.join("/")}else e.indexOf("./")===0&&(e=e.substring(2));if((v||g)&&m){n=e.split("/");for(c=n.length;c>0;c-=1){r=n.slice(0,c).join("/");if(v)for(h=v.length;h>0;h-=1){i=m[v.slice(0,h).join("/")];if(i){i=i[r];if(i){s=i,u=c;break}}}if(s)break;!a&&g&&g[r]&&(a=g[r],f=c)}!s&&a&&(s=a,u=f),s&&(n.splice(0,u,s),e=n.join("/"))}return e}function g(e,t){return function(){return s.apply(r,p.call(arguments,0).concat([e,t]))}}function y(e){return function(t){return m(t,e)}}function b(e){return function(t){a[e]=t}}function w(e){if(v(f,e)){var t=f[e];delete f[e],c[e]=!0,i.apply(r,t)}if(!v(a,e)&&!v(c,e))throw new Error("No "+e);return a[e]}function E(e){var t,n=e?e.indexOf("!"):-1;return n>-1&&(t=e.substring(0,n),e=e.substring(n+1,e.length)),[t,e]}function S(e){return function(){return l&&l.config&&l.config[e]||{}}}var i,s,o,u,a={},f={},l={},c={},h=Object.prototype.hasOwnProperty,p=[].slice,d=/\.js$/;o=function(e,t){var n,r=E(e),i=r[0];return e=r[1],i&&(i=m(i,t),n=w(i)),i?n&&n.normalize?e=n.normalize(e,y(t)):e=m(e,t):(e=m(e,t),r=E(e),i=r[0],e=r[1],i&&(n=w(i))),{f:i?i+"!"+e:e,n:e,pr:i,p:n}},u={require:function(e){return g(e)},exports:function(e){var t=a[e];return typeof t!="undefined"?t:a[e]={}},module:function(e){return{id:e,uri:"",exports:a[e],config:S(e)}}},i=function(e,t,n,i){var s,l,h,p,d,m=[],y=typeof n,E;i=i||e;if(y==="undefined"||y==="function"){t=!t.length&&n.length?["require","exports","module"]:t;for(d=0;d<t.length;d+=1){p=o(t[d],i),l=p.f;if(l==="require")m[d]=u.require(e);else if(l==="exports")m[d]=u.exports(e),E=!0;else if(l==="module")s=m[d]=u.module(e);else if(v(a,l)||v(f,l)||v(c,l))m[d]=w(l);else{if(!p.p)throw new Error(e+" missing "+l);p.p.load(p.n,g(i,!0),b(l),{}),m[d]=a[l]}}h=n?n.apply(a[e],m):undefined;if(e)if(s&&s.exports!==r&&s.exports!==a[e])a[e]=s.exports;else if(h!==r||!E)a[e]=h}else e&&(a[e]=n)},e=t=s=function(e,t,n,a,f){if(typeof e=="string")return u[e]?u[e](t):w(o(e,t).f);if(!e.splice){l=e,l.deps&&s(l.deps,l.callback);if(!t)return;t.splice?(e=t,t=n,n=null):e=r}return t=t||function(){},typeof n=="function"&&(n=a,a=f),a?i(r,e,t,n):setTimeout(function(){i(r,e,t,n)},4),s},s.config=function(e){return s(e)},e._defined=a,n=function(e,t,n){t.splice||(n=t,t=[]),!v(a,e)&&!v(f,e)&&(f[e]=[e,t,n])},n.amd={jQuery:!0}})(),n("almond",function(){}),n("app",[],function(){var e=function(){};return{initialize:e}}),t.config({}),t(["app"],function(e){e.initialize()}),n("application",function(){})})();
@@ -0,0 +1,10 @@
1
+ define([], function () {
2
+
3
+ // initialize Application
4
+ var initialize = function () {
5
+ };
6
+
7
+ return {
8
+ initialize: initialize
9
+ };
10
+ });
@@ -0,0 +1,7 @@
1
+ //= rjs
2
+
3
+ require.config({});
4
+
5
+ require(["app"], function (App) {
6
+ App.initialize();
7
+ });
@@ -0,0 +1,21 @@
1
+ (function () {
2
+ define('app',[], function () {
3
+
4
+ // initialize Application
5
+ var initialize = function () {
6
+ };
7
+
8
+ return {
9
+ initialize: initialize
10
+ };
11
+ });
12
+
13
+
14
+ require.config({});
15
+
16
+ require(["app"], function (App) {
17
+ App.initialize();
18
+ });
19
+
20
+ define("application", function(){});
21
+ }());
@@ -0,0 +1,10 @@
1
+ define([], function () {
2
+
3
+ // initialize Application
4
+ var initialize = function () {
5
+ };
6
+
7
+ return {
8
+ initialize: initialize
9
+ };
10
+ });
@@ -0,0 +1,35 @@
1
+ //= rjs
2
+
3
+ require.config({
4
+ shim:{
5
+ "jquery":{
6
+ exports:"$"
7
+ },
8
+ "turbolinks":{
9
+ exports:"Turbolinks"
10
+ },
11
+ "jquery_ujs":["jquery"],
12
+ "app":{
13
+ deps:[
14
+ "jquery",
15
+ "jquery_ujs",
16
+ "turbolinks"
17
+ ]
18
+ }
19
+ },
20
+
21
+ waitSeconds: 10,
22
+ catchError:false
23
+ });
24
+
25
+ require.onError = function (err) {
26
+ if (err.requireType === 'timeout') {
27
+ console.log("RequireJS: timeout");
28
+ } else {
29
+ console.log("RequireJS: error " + err.message);
30
+ }
31
+ };
32
+
33
+ require(["jquery", "turbolinks", "jquery_ujs", "app"], function ($, Turbolinks, uJS, App) {
34
+ App.initialize();
35
+ });
@@ -0,0 +1,80 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Rails' do
4
+
5
+ describe 'configuration' do
6
+ it 'sets Rails.config.requirejs' do
7
+ create_app
8
+ ::Rails.configuration.requirejs.should be_a(::Requirejs::Config)
9
+ end
10
+
11
+ it 'sets cache_location' do
12
+ create_app
13
+ Requirejs.config.cache_location.should == ::Rails.root.join('tmp', 'ruby-requirejs')
14
+ end
15
+
16
+ it 'sets js_compressor no "none" as default' do
17
+ create_app
18
+ Requirejs.config.js_compressor.should == :none
19
+ end
20
+
21
+ it 'sets js_compressor to "uglify" when this config.assets.js_compressor set to :uglifier' do
22
+ create_app(:js_compressor => :uglifier)
23
+ Requirejs.config.js_compressor.should == :uglify
24
+ end
25
+
26
+ it 'disables default asset pipeline' do
27
+ create_app
28
+ ::Rails.configuration.assets.js_compressor.should be_nil
29
+ end
30
+
31
+ end
32
+
33
+ describe 'compilation' do
34
+ after { Requirejs.config.cleanup_cache_dir }
35
+
36
+ describe 'not minified almond setup' do
37
+ it 'compresses to one file' do
38
+ app = create_app(assets_path: fixtures_path('basic_almond'))
39
+ app.config.requirejs.loader = :almond
40
+ asset = app.assets['application']
41
+ asset.to_s.should == compiled_asset('basic_almond', 'application.js').to_s
42
+ end
43
+ end
44
+
45
+ describe 'minified almond setup' do
46
+ it 'compresses to one minified file' do
47
+ app = create_app(assets_path: fixtures_path('basic_minimized_almond'), :js_compressor => :uglifier)
48
+ app.config.requirejs.loader = :almond
49
+ asset = app.assets['application']
50
+ asset.to_s.should == compiled_asset('basic_minimized_almond', 'application.js').to_s
51
+ end
52
+ end
53
+
54
+ describe 'unoptimized requirejs setup' do
55
+ it 'compresses to one file' do
56
+ app = create_app(assets_path: fixtures_path('basic'))
57
+ asset = app.assets['application']
58
+ asset.to_s.should == compiled_asset('basic', 'application.js').to_s
59
+ end
60
+ end
61
+
62
+ describe 'unoptimized requirejs setup with digested assets' do
63
+ it 'compresses to one file' do
64
+ app = create_app(assets_path: fixtures_path('basic_digested'), digest: true)
65
+ asset = app.assets['application']
66
+ asset.to_s.should == compiled_asset('basic_digested', 'application.js').to_s
67
+ end
68
+ end
69
+
70
+ describe 'optimized requirejs setup' do
71
+ it 'compresses to one file' do
72
+ app = create_app(assets_path: fixtures_path('basic_optimized'))
73
+ app.config.requirejs.optimize = true
74
+ asset = app.assets['application']
75
+ asset.to_s.should == compiled_asset('basic_optimized', 'application.js').to_s
76
+ end
77
+ end
78
+ end
79
+
80
+ end
@@ -0,0 +1,22 @@
1
+ require 'rails'
2
+ require 'sprockets/rails'
3
+
4
+ require 'ruby-requirejs'
5
+
6
+
7
+ require 'support/helpers'
8
+
9
+ RSpec.configure do |config|
10
+ config.treat_symbols_as_metadata_keys_with_true_values = true
11
+ config.run_all_when_everything_filtered = true
12
+ config.filter_run :focus
13
+
14
+ # Run specs in random order to surface order dependencies. If you find an
15
+ # order dependency and want to debug it, you can fix the order by providing
16
+ # the seed, which is printed after each run.
17
+ # --seed 1234
18
+ config.order = 'random'
19
+
20
+ config.include Helpers
21
+
22
+ end
@@ -0,0 +1,40 @@
1
+ module Helpers
2
+
3
+ def create_app(options = {})
4
+ Rails.application = nil
5
+
6
+ Class.new(Rails::Application).tap do |app|
7
+ app.assets.cache = ActiveSupport::Cache.lookup_store(:null_store)
8
+ config = app.config.assets
9
+
10
+ config.js_compressor = options[:js_compressor]
11
+ config.digest = options[:digest]
12
+ config.debug = options[:debug]
13
+ config.paths = []
14
+ config.paths << options[:assets_path] if options[:assets_path]
15
+ yield(app) if block_given?
16
+
17
+ app.config.eager_load = false
18
+ app.config.active_support.deprecation = :log
19
+ app.initialize!
20
+ end
21
+ end
22
+
23
+ def fixtures_path(name)
24
+ File.join(File.dirname(File.expand_path('../..', __FILE__)), 'spec', 'cases', name, 'in')
25
+ end
26
+
27
+ def compiled_asset_path(name)
28
+ File.join(File.dirname(File.expand_path('../..', __FILE__)), 'spec', 'cases', name, 'out')
29
+ end
30
+
31
+ def compiled_asset(name, file_name)
32
+ File.read(File.join(compiled_asset_path(name), file_name))
33
+ end
34
+
35
+ def dump_asset(asset)
36
+ File.open File.expand_path('../../cases/tmp.js', __FILE__), 'w+' do |f|
37
+ f.write asset.to_s
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,422 @@
1
+ /**
2
+ * @license almond 0.2.9 Copyright (c) 2011-2014, The Dojo Foundation All Rights Reserved.
3
+ * Available via the MIT or new BSD license.
4
+ * see: http://github.com/jrburke/almond for details
5
+ */
6
+ //Going sloppy to avoid 'use strict' string cost, but strict practices should
7
+ //be followed.
8
+ /*jslint sloppy: true */
9
+ /*global setTimeout: false */
10
+
11
+ var requirejs, require, define;
12
+ (function (undef) {
13
+ var main, req, makeMap, handlers,
14
+ defined = {},
15
+ waiting = {},
16
+ config = {},
17
+ defining = {},
18
+ hasOwn = Object.prototype.hasOwnProperty,
19
+ aps = [].slice,
20
+ jsSuffixRegExp = /\.js$/;
21
+
22
+ function hasProp(obj, prop) {
23
+ return hasOwn.call(obj, prop);
24
+ }
25
+
26
+ /**
27
+ * Given a relative module name, like ./something, normalize it to
28
+ * a real name that can be mapped to a path.
29
+ * @param {String} name the relative name
30
+ * @param {String} baseName a real name that the name arg is relative
31
+ * to.
32
+ * @returns {String} normalized name
33
+ */
34
+ function normalize(name, baseName) {
35
+ var nameParts, nameSegment, mapValue, foundMap, lastIndex,
36
+ foundI, foundStarMap, starI, i, j, part,
37
+ baseParts = baseName && baseName.split("/"),
38
+ map = config.map,
39
+ starMap = (map && map['*']) || {};
40
+
41
+ //Adjust any relative paths.
42
+ if (name && name.charAt(0) === ".") {
43
+ //If have a base name, try to normalize against it,
44
+ //otherwise, assume it is a top-level require that will
45
+ //be relative to baseUrl in the end.
46
+ if (baseName) {
47
+ //Convert baseName to array, and lop off the last part,
48
+ //so that . matches that "directory" and not name of the baseName's
49
+ //module. For instance, baseName of "one/two/three", maps to
50
+ //"one/two/three.js", but we want the directory, "one/two" for
51
+ //this normalization.
52
+ baseParts = baseParts.slice(0, baseParts.length - 1);
53
+ name = name.split('/');
54
+ lastIndex = name.length - 1;
55
+
56
+ // Node .js allowance:
57
+ if (config.nodeIdCompat && jsSuffixRegExp.test(name[lastIndex])) {
58
+ name[lastIndex] = name[lastIndex].replace(jsSuffixRegExp, '');
59
+ }
60
+
61
+ name = baseParts.concat(name);
62
+
63
+ //start trimDots
64
+ for (i = 0; i < name.length; i += 1) {
65
+ part = name[i];
66
+ if (part === ".") {
67
+ name.splice(i, 1);
68
+ i -= 1;
69
+ } else if (part === "..") {
70
+ if (i === 1 && (name[2] === '..' || name[0] === '..')) {
71
+ //End of the line. Keep at least one non-dot
72
+ //path segment at the front so it can be mapped
73
+ //correctly to disk. Otherwise, there is likely
74
+ //no path mapping for a path starting with '..'.
75
+ //This can still fail, but catches the most reasonable
76
+ //uses of ..
77
+ break;
78
+ } else if (i > 0) {
79
+ name.splice(i - 1, 2);
80
+ i -= 2;
81
+ }
82
+ }
83
+ }
84
+ //end trimDots
85
+
86
+ name = name.join("/");
87
+ } else if (name.indexOf('./') === 0) {
88
+ // No baseName, so this is ID is resolved relative
89
+ // to baseUrl, pull off the leading dot.
90
+ name = name.substring(2);
91
+ }
92
+ }
93
+
94
+ //Apply map config if available.
95
+ if ((baseParts || starMap) && map) {
96
+ nameParts = name.split('/');
97
+
98
+ for (i = nameParts.length; i > 0; i -= 1) {
99
+ nameSegment = nameParts.slice(0, i).join("/");
100
+
101
+ if (baseParts) {
102
+ //Find the longest baseName segment match in the config.
103
+ //So, do joins on the biggest to smallest lengths of baseParts.
104
+ for (j = baseParts.length; j > 0; j -= 1) {
105
+ mapValue = map[baseParts.slice(0, j).join('/')];
106
+
107
+ //baseName segment has config, find if it has one for
108
+ //this name.
109
+ if (mapValue) {
110
+ mapValue = mapValue[nameSegment];
111
+ if (mapValue) {
112
+ //Match, update name to the new value.
113
+ foundMap = mapValue;
114
+ foundI = i;
115
+ break;
116
+ }
117
+ }
118
+ }
119
+ }
120
+
121
+ if (foundMap) {
122
+ break;
123
+ }
124
+
125
+ //Check for a star map match, but just hold on to it,
126
+ //if there is a shorter segment match later in a matching
127
+ //config, then favor over this star map.
128
+ if (!foundStarMap && starMap && starMap[nameSegment]) {
129
+ foundStarMap = starMap[nameSegment];
130
+ starI = i;
131
+ }
132
+ }
133
+
134
+ if (!foundMap && foundStarMap) {
135
+ foundMap = foundStarMap;
136
+ foundI = starI;
137
+ }
138
+
139
+ if (foundMap) {
140
+ nameParts.splice(0, foundI, foundMap);
141
+ name = nameParts.join('/');
142
+ }
143
+ }
144
+
145
+ return name;
146
+ }
147
+
148
+ function makeRequire(relName, forceSync) {
149
+ return function () {
150
+ //A version of a require function that passes a moduleName
151
+ //value for items that may need to
152
+ //look up paths relative to the moduleName
153
+ return req.apply(undef, aps.call(arguments, 0).concat([relName, forceSync]));
154
+ };
155
+ }
156
+
157
+ function makeNormalize(relName) {
158
+ return function (name) {
159
+ return normalize(name, relName);
160
+ };
161
+ }
162
+
163
+ function makeLoad(depName) {
164
+ return function (value) {
165
+ defined[depName] = value;
166
+ };
167
+ }
168
+
169
+ function callDep(name) {
170
+ if (hasProp(waiting, name)) {
171
+ var args = waiting[name];
172
+ delete waiting[name];
173
+ defining[name] = true;
174
+ main.apply(undef, args);
175
+ }
176
+
177
+ if (!hasProp(defined, name) && !hasProp(defining, name)) {
178
+ throw new Error('No ' + name);
179
+ }
180
+ return defined[name];
181
+ }
182
+
183
+ //Turns a plugin!resource to [plugin, resource]
184
+ //with the plugin being undefined if the name
185
+ //did not have a plugin prefix.
186
+ function splitPrefix(name) {
187
+ var prefix,
188
+ index = name ? name.indexOf('!') : -1;
189
+ if (index > -1) {
190
+ prefix = name.substring(0, index);
191
+ name = name.substring(index + 1, name.length);
192
+ }
193
+ return [prefix, name];
194
+ }
195
+
196
+ /**
197
+ * Makes a name map, normalizing the name, and using a plugin
198
+ * for normalization if necessary. Grabs a ref to plugin
199
+ * too, as an optimization.
200
+ */
201
+ makeMap = function (name, relName) {
202
+ var plugin,
203
+ parts = splitPrefix(name),
204
+ prefix = parts[0];
205
+
206
+ name = parts[1];
207
+
208
+ if (prefix) {
209
+ prefix = normalize(prefix, relName);
210
+ plugin = callDep(prefix);
211
+ }
212
+
213
+ //Normalize according
214
+ if (prefix) {
215
+ if (plugin && plugin.normalize) {
216
+ name = plugin.normalize(name, makeNormalize(relName));
217
+ } else {
218
+ name = normalize(name, relName);
219
+ }
220
+ } else {
221
+ name = normalize(name, relName);
222
+ parts = splitPrefix(name);
223
+ prefix = parts[0];
224
+ name = parts[1];
225
+ if (prefix) {
226
+ plugin = callDep(prefix);
227
+ }
228
+ }
229
+
230
+ //Using ridiculous property names for space reasons
231
+ return {
232
+ f: prefix ? prefix + '!' + name : name, //fullName
233
+ n: name,
234
+ pr: prefix,
235
+ p: plugin
236
+ };
237
+ };
238
+
239
+ function makeConfig(name) {
240
+ return function () {
241
+ return (config && config.config && config.config[name]) || {};
242
+ };
243
+ }
244
+
245
+ handlers = {
246
+ require: function (name) {
247
+ return makeRequire(name);
248
+ },
249
+ exports: function (name) {
250
+ var e = defined[name];
251
+ if (typeof e !== 'undefined') {
252
+ return e;
253
+ } else {
254
+ return (defined[name] = {});
255
+ }
256
+ },
257
+ module: function (name) {
258
+ return {
259
+ id: name,
260
+ uri: '',
261
+ exports: defined[name],
262
+ config: makeConfig(name)
263
+ };
264
+ }
265
+ };
266
+
267
+ main = function (name, deps, callback, relName) {
268
+ var cjsModule, depName, ret, map, i,
269
+ args = [],
270
+ callbackType = typeof callback,
271
+ usingExports;
272
+
273
+ //Use name if no relName
274
+ relName = relName || name;
275
+
276
+ //Call the callback to define the module, if necessary.
277
+ if (callbackType === 'undefined' || callbackType === 'function') {
278
+ //Pull out the defined dependencies and pass the ordered
279
+ //values to the callback.
280
+ //Default to [require, exports, module] if no deps
281
+ deps = !deps.length && callback.length ? ['require', 'exports', 'module'] : deps;
282
+ for (i = 0; i < deps.length; i += 1) {
283
+ map = makeMap(deps[i], relName);
284
+ depName = map.f;
285
+
286
+ //Fast path CommonJS standard dependencies.
287
+ if (depName === "require") {
288
+ args[i] = handlers.require(name);
289
+ } else if (depName === "exports") {
290
+ //CommonJS module spec 1.1
291
+ args[i] = handlers.exports(name);
292
+ usingExports = true;
293
+ } else if (depName === "module") {
294
+ //CommonJS module spec 1.1
295
+ cjsModule = args[i] = handlers.module(name);
296
+ } else if (hasProp(defined, depName) ||
297
+ hasProp(waiting, depName) ||
298
+ hasProp(defining, depName)) {
299
+ args[i] = callDep(depName);
300
+ } else if (map.p) {
301
+ map.p.load(map.n, makeRequire(relName, true), makeLoad(depName), {});
302
+ args[i] = defined[depName];
303
+ } else {
304
+ throw new Error(name + ' missing ' + depName);
305
+ }
306
+ }
307
+
308
+ ret = callback ? callback.apply(defined[name], args) : undefined;
309
+
310
+ if (name) {
311
+ //If setting exports via "module" is in play,
312
+ //favor that over return value and exports. After that,
313
+ //favor a non-undefined return value over exports use.
314
+ if (cjsModule && cjsModule.exports !== undef &&
315
+ cjsModule.exports !== defined[name]) {
316
+ defined[name] = cjsModule.exports;
317
+ } else if (ret !== undef || !usingExports) {
318
+ //Use the return value from the function.
319
+ defined[name] = ret;
320
+ }
321
+ }
322
+ } else if (name) {
323
+ //May just be an object definition for the module. Only
324
+ //worry about defining if have a module name.
325
+ defined[name] = callback;
326
+ }
327
+ };
328
+
329
+ requirejs = require = req = function (deps, callback, relName, forceSync, alt) {
330
+ if (typeof deps === "string") {
331
+ if (handlers[deps]) {
332
+ //callback in this case is really relName
333
+ return handlers[deps](callback);
334
+ }
335
+ //Just return the module wanted. In this scenario, the
336
+ //deps arg is the module name, and second arg (if passed)
337
+ //is just the relName.
338
+ //Normalize module name, if it contains . or ..
339
+ return callDep(makeMap(deps, callback).f);
340
+ } else if (!deps.splice) {
341
+ //deps is a config object, not an array.
342
+ config = deps;
343
+ if (config.deps) {
344
+ req(config.deps, config.callback);
345
+ }
346
+ if (!callback) {
347
+ return;
348
+ }
349
+
350
+ if (callback.splice) {
351
+ //callback is an array, which means it is a dependency list.
352
+ //Adjust args if there are dependencies
353
+ deps = callback;
354
+ callback = relName;
355
+ relName = null;
356
+ } else {
357
+ deps = undef;
358
+ }
359
+ }
360
+
361
+ //Support require(['a'])
362
+ callback = callback || function () {
363
+ };
364
+
365
+ //If relName is a function, it is an errback handler,
366
+ //so remove it.
367
+ if (typeof relName === 'function') {
368
+ relName = forceSync;
369
+ forceSync = alt;
370
+ }
371
+
372
+ //Simulate async callback;
373
+ if (forceSync) {
374
+ main(undef, deps, callback, relName);
375
+ } else {
376
+ //Using a non-zero value because of concern for what old browsers
377
+ //do, and latest browsers "upgrade" to 4 if lower value is used:
378
+ //http://www.whatwg.org/specs/web-apps/current-work/multipage/timers.html#dom-windowtimers-settimeout:
379
+ //If want a value immediately, use require('id') instead -- something
380
+ //that works in almond on the global level, but not guaranteed and
381
+ //unlikely to work in other AMD implementations.
382
+ setTimeout(function () {
383
+ main(undef, deps, callback, relName);
384
+ }, 4);
385
+ }
386
+
387
+ return req;
388
+ };
389
+
390
+ /**
391
+ * Just drops the config on the floor, but returns req in case
392
+ * the config return value is used.
393
+ */
394
+ req.config = function (cfg) {
395
+ return req(cfg);
396
+ };
397
+
398
+ /**
399
+ * Expose module registry for debugging and tooling
400
+ */
401
+ requirejs._defined = defined;
402
+
403
+ define = function (name, deps, callback) {
404
+
405
+ //This module may not have dependencies
406
+ if (!deps.splice) {
407
+ //deps is not an array, so probably means
408
+ //an object literal or factory function for
409
+ //the value. Adjust args.
410
+ callback = deps;
411
+ deps = [];
412
+ }
413
+
414
+ if (!hasProp(defined, name) && !hasProp(waiting, name)) {
415
+ waiting[name] = [name, deps, callback];
416
+ }
417
+ };
418
+
419
+ define.amd = {
420
+ jQuery: true
421
+ };
422
+ }());