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.
- checksums.yaml +7 -0
- data/.gitignore +25 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +85 -0
- data/Rakefile +1 -0
- data/lib/requirejs/action_view/tag_helper.rb +15 -0
- data/lib/requirejs/builds/build.js.erb +8 -0
- data/lib/requirejs/builds/build.rb +18 -0
- data/lib/requirejs/builds/build_config.rb +59 -0
- data/lib/requirejs/builds/optimized_build.rb +57 -0
- data/lib/requirejs/compiler.rb +21 -0
- data/lib/requirejs/config.rb +72 -0
- data/lib/requirejs/engine.rb +40 -0
- data/lib/requirejs/manifest.rb +56 -0
- data/lib/requirejs/runtime/node_runner.js +21 -0
- data/lib/requirejs/runtime/r.js +27617 -0
- data/lib/requirejs/runtime/runtime.rb +59 -0
- data/lib/requirejs/tilt/directive_processor.rb +52 -0
- data/lib/requirejs/tilt/template.rb +37 -0
- data/lib/requirejs/version.rb +5 -0
- data/lib/ruby-requirejs.rb +26 -0
- data/ruby-requirejs.gemspec +24 -0
- data/spec/cases/basic/in/app.js +10 -0
- data/spec/cases/basic/in/application.js +7 -0
- data/spec/cases/basic/out/application.js +6 -0
- data/spec/cases/basic_almond/in/app.js +10 -0
- data/spec/cases/basic_almond/in/application.js +7 -0
- data/spec/cases/basic_almond/out/application.js +447 -0
- data/spec/cases/basic_digested/in/app.js +10 -0
- data/spec/cases/basic_digested/in/application.js +7 -0
- data/spec/cases/basic_digested/out/application.js +14 -0
- data/spec/cases/basic_minimized_almond/in/app.js +10 -0
- data/spec/cases/basic_minimized_almond/in/application.js +7 -0
- data/spec/cases/basic_minimized_almond/out/application.js +7 -0
- data/spec/cases/basic_optimized/in/app.js +10 -0
- data/spec/cases/basic_optimized/in/application.js +7 -0
- data/spec/cases/basic_optimized/out/application.js +21 -0
- data/spec/cases/simple/in/app.js +10 -0
- data/spec/cases/simple/in/application.js +35 -0
- data/spec/rails_spec.rb +80 -0
- data/spec/spec_helper.rb +22 -0
- data/spec/support/helpers.rb +40 -0
- data/vendor/assets/javascripts/almond.js +422 -0
- data/vendor/assets/javascripts/require.js +2072 -0
- metadata +136 -0
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'execjs'
|
2
|
+
|
3
|
+
module Requirejs
|
4
|
+
# Internal: Module responsible for the ExecJS interaction. Besides handling
|
5
|
+
# the compilation execution, this module provide a runtime validation to ensure
|
6
|
+
# that the Node.JS binary is available to use.
|
7
|
+
class Runtime
|
8
|
+
|
9
|
+
# Internal: Module responsible for the ExecJS interaction. Besides handling
|
10
|
+
# the compilation execution, this module provide a runtime validation to ensure
|
11
|
+
# that the Node.JS binary is available to use.
|
12
|
+
def initialize(build_script)
|
13
|
+
@build_script = build_script
|
14
|
+
end
|
15
|
+
|
16
|
+
# Internal: Calls a specific function on the Node.JS context.
|
17
|
+
#
|
18
|
+
# Example
|
19
|
+
# exec('version', 2) # => '2'
|
20
|
+
#
|
21
|
+
# Returns The function returned value.
|
22
|
+
def exec(*arguments)
|
23
|
+
check_availability!
|
24
|
+
context.call('optimize')
|
25
|
+
end
|
26
|
+
|
27
|
+
#private
|
28
|
+
# Internal: Queries the runtime for it's availability and raises a 'RuntimeError'
|
29
|
+
# if the runtime isn't available. Otherwise, this is a noop.
|
30
|
+
def check_availability!
|
31
|
+
unless runtime.available?
|
32
|
+
message = 'The Node.JS runtime is not available to RequireJS.'
|
33
|
+
message << 'Ensure that the "node" (or "nodejs") executable is present in your $PATH.'
|
34
|
+
raise RuntimeError, message
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Internal: Compile the Stylus compilation script into a execution context
|
39
|
+
# to execute functions into.
|
40
|
+
#
|
41
|
+
# Returns the compiled context.
|
42
|
+
def context
|
43
|
+
@context ||= runtime.compile(@build_script)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Internal: Create the ExecJS external runtime with a old runner script that
|
47
|
+
# maintains the state of 'require', so we can use it to load modules like on
|
48
|
+
# any Node.JS program.
|
49
|
+
def runtime
|
50
|
+
#@runtime ||= ExecJS::Runtimes::Node
|
51
|
+
@runtime ||= ExecJS::ExternalRuntime.new(
|
52
|
+
:name => 'Node.js (V8)',
|
53
|
+
:command => %w{nodejs node},
|
54
|
+
:runner_path => File.expand_path('../node_runner.js', __FILE__),
|
55
|
+
:encoding => 'UTF-8'
|
56
|
+
)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'tilt'
|
2
|
+
# Public: A Tilt template to compile Stylus stylesheets.
|
3
|
+
#
|
4
|
+
# Examples
|
5
|
+
#
|
6
|
+
# template = Tilt::StylusTemplate.new { |t| File.read('app.styl') }
|
7
|
+
# template.render # => the compiled CSS from the app.styl file.
|
8
|
+
#
|
9
|
+
# Options should assigned on the template constructor.
|
10
|
+
# template = Tilt::StylusTemplate.new(compress: true) { |t| File.read('app.styl') }
|
11
|
+
# template.render # => the compiled CSS with compression enabled.
|
12
|
+
module Requirejs
|
13
|
+
module Tilt
|
14
|
+
class DirectiveProcessor < ::Sprockets::DirectiveProcessor
|
15
|
+
|
16
|
+
# Internal: Compile the template Stylus using this instance options.
|
17
|
+
# The current 'scope' and given 'locals' are ignored and the output
|
18
|
+
# is cached.
|
19
|
+
#
|
20
|
+
# Returns a String with the compiled stylesheet with CSS syntax.
|
21
|
+
def evaluate(scope, locals, &block)
|
22
|
+
@result = super
|
23
|
+
if process_rjs?
|
24
|
+
Requirejs.config.setup_directories
|
25
|
+
dump_config
|
26
|
+
end
|
27
|
+
@result
|
28
|
+
end
|
29
|
+
|
30
|
+
def dump_config
|
31
|
+
process_include_directive(name)
|
32
|
+
::Requirejs::BuildConfig.new(file).save({ 'include' => @include_modules })
|
33
|
+
end
|
34
|
+
|
35
|
+
protected
|
36
|
+
|
37
|
+
def process_rjs_directive(*args)
|
38
|
+
@rjs_directive_present = directives.any? { |directive| directive[1] == 'rjs' }
|
39
|
+
end
|
40
|
+
|
41
|
+
def process_include_directive(mod)
|
42
|
+
@include_modules ||= []
|
43
|
+
@include_modules << mod
|
44
|
+
end
|
45
|
+
|
46
|
+
def process_rjs?
|
47
|
+
@rjs_directive_present
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'tilt'
|
2
|
+
# Public: A Tilt template to compile Stylus stylesheets.
|
3
|
+
#
|
4
|
+
# Examples
|
5
|
+
#
|
6
|
+
# template = Tilt::StylusTemplate.new { |t| File.read('app.styl') }
|
7
|
+
# template.render # => the compiled CSS from the app.styl file.
|
8
|
+
#
|
9
|
+
# Options should assigned on the template constructor.
|
10
|
+
# template = Tilt::StylusTemplate.new(compress: true) { |t| File.read('app.styl') }
|
11
|
+
# template.render # => the compiled CSS with compression enabled.
|
12
|
+
module Requirejs
|
13
|
+
module Tilt
|
14
|
+
class Template < ::Tilt::Template
|
15
|
+
|
16
|
+
def prepare
|
17
|
+
end
|
18
|
+
|
19
|
+
# Internal: Compile the template Stylus using this instance options.
|
20
|
+
# The current 'scope' and given 'locals' are ignored and the output
|
21
|
+
# is cached.
|
22
|
+
#
|
23
|
+
# Returns a String with the compiled stylesheet with CSS syntax.
|
24
|
+
def evaluate(scope, locals, &block)
|
25
|
+
if ::Requirejs::BuildConfig.new(file).exists?
|
26
|
+
compiler = ::Requirejs::Compiler.new(scope: scope, data: data, file: file)
|
27
|
+
@output ||= compiler.exec
|
28
|
+
else
|
29
|
+
@output ||= data
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
Tilt.register Requirejs::Tilt::Template, 'js'
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'requirejs/version'
|
2
|
+
require 'requirejs/config'
|
3
|
+
require 'requirejs/manifest'
|
4
|
+
require 'requirejs/runtime/runtime'
|
5
|
+
require 'requirejs/builds/build_config'
|
6
|
+
require 'requirejs/builds/build'
|
7
|
+
require 'requirejs/builds/optimized_build'
|
8
|
+
require 'requirejs/compiler'
|
9
|
+
|
10
|
+
if defined?(Rails)
|
11
|
+
require 'requirejs/engine'
|
12
|
+
else
|
13
|
+
Requirejs.config = Requirejs::Config.new
|
14
|
+
end
|
15
|
+
|
16
|
+
# Loading ActionView helpers
|
17
|
+
if defined?(::ActionView)
|
18
|
+
require 'requirejs/action_view/tag_helper'
|
19
|
+
::Requirejs::ActionView.constants.each do |k|
|
20
|
+
klass = ::Requirejs::ActionView.const_get(k)
|
21
|
+
ActionView::Base.send(:include, klass) if klass.is_a?(Module)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module Requirejs
|
26
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'requirejs/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'ruby-requirejs'
|
8
|
+
spec.version = Ruby::Requirejs::VERSION
|
9
|
+
spec.authors = ['Alex Krasinsky']
|
10
|
+
spec.email = ['lyoshakr@gmail.com']
|
11
|
+
spec.summary = %q{Ruby/Rails requirejs compiler}
|
12
|
+
spec.description = %q{Support of requirejs in ruby/rails projects}
|
13
|
+
spec.homepage = 'https://github.com/spilin/ruby-requirejs'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'rails', '>= 4.0.0'
|
22
|
+
|
23
|
+
spec.add_dependency 'execjs'
|
24
|
+
end
|
@@ -0,0 +1,447 @@
|
|
1
|
+
(function () {
|
2
|
+
/**
|
3
|
+
* @license almond 0.2.9 Copyright (c) 2011-2014, The Dojo Foundation All Rights Reserved.
|
4
|
+
* Available via the MIT or new BSD license.
|
5
|
+
* see: http://github.com/jrburke/almond for details
|
6
|
+
*/
|
7
|
+
//Going sloppy to avoid 'use strict' string cost, but strict practices should
|
8
|
+
//be followed.
|
9
|
+
/*jslint sloppy: true */
|
10
|
+
/*global setTimeout: false */
|
11
|
+
|
12
|
+
|
13
|
+
var requirejs, require, define;
|
14
|
+
(function (undef) {
|
15
|
+
var main, req, makeMap, handlers,
|
16
|
+
defined = {},
|
17
|
+
waiting = {},
|
18
|
+
config = {},
|
19
|
+
defining = {},
|
20
|
+
hasOwn = Object.prototype.hasOwnProperty,
|
21
|
+
aps = [].slice,
|
22
|
+
jsSuffixRegExp = /\.js$/;
|
23
|
+
|
24
|
+
function hasProp(obj, prop) {
|
25
|
+
return hasOwn.call(obj, prop);
|
26
|
+
}
|
27
|
+
|
28
|
+
/**
|
29
|
+
* Given a relative module name, like ./something, normalize it to
|
30
|
+
* a real name that can be mapped to a path.
|
31
|
+
* @param {String} name the relative name
|
32
|
+
* @param {String} baseName a real name that the name arg is relative
|
33
|
+
* to.
|
34
|
+
* @returns {String} normalized name
|
35
|
+
*/
|
36
|
+
function normalize(name, baseName) {
|
37
|
+
var nameParts, nameSegment, mapValue, foundMap, lastIndex,
|
38
|
+
foundI, foundStarMap, starI, i, j, part,
|
39
|
+
baseParts = baseName && baseName.split("/"),
|
40
|
+
map = config.map,
|
41
|
+
starMap = (map && map['*']) || {};
|
42
|
+
|
43
|
+
//Adjust any relative paths.
|
44
|
+
if (name && name.charAt(0) === ".") {
|
45
|
+
//If have a base name, try to normalize against it,
|
46
|
+
//otherwise, assume it is a top-level require that will
|
47
|
+
//be relative to baseUrl in the end.
|
48
|
+
if (baseName) {
|
49
|
+
//Convert baseName to array, and lop off the last part,
|
50
|
+
//so that . matches that "directory" and not name of the baseName's
|
51
|
+
//module. For instance, baseName of "one/two/three", maps to
|
52
|
+
//"one/two/three.js", but we want the directory, "one/two" for
|
53
|
+
//this normalization.
|
54
|
+
baseParts = baseParts.slice(0, baseParts.length - 1);
|
55
|
+
name = name.split('/');
|
56
|
+
lastIndex = name.length - 1;
|
57
|
+
|
58
|
+
// Node .js allowance:
|
59
|
+
if (config.nodeIdCompat && jsSuffixRegExp.test(name[lastIndex])) {
|
60
|
+
name[lastIndex] = name[lastIndex].replace(jsSuffixRegExp, '');
|
61
|
+
}
|
62
|
+
|
63
|
+
name = baseParts.concat(name);
|
64
|
+
|
65
|
+
//start trimDots
|
66
|
+
for (i = 0; i < name.length; i += 1) {
|
67
|
+
part = name[i];
|
68
|
+
if (part === ".") {
|
69
|
+
name.splice(i, 1);
|
70
|
+
i -= 1;
|
71
|
+
} else if (part === "..") {
|
72
|
+
if (i === 1 && (name[2] === '..' || name[0] === '..')) {
|
73
|
+
//End of the line. Keep at least one non-dot
|
74
|
+
//path segment at the front so it can be mapped
|
75
|
+
//correctly to disk. Otherwise, there is likely
|
76
|
+
//no path mapping for a path starting with '..'.
|
77
|
+
//This can still fail, but catches the most reasonable
|
78
|
+
//uses of ..
|
79
|
+
break;
|
80
|
+
} else if (i > 0) {
|
81
|
+
name.splice(i - 1, 2);
|
82
|
+
i -= 2;
|
83
|
+
}
|
84
|
+
}
|
85
|
+
}
|
86
|
+
//end trimDots
|
87
|
+
|
88
|
+
name = name.join("/");
|
89
|
+
} else if (name.indexOf('./') === 0) {
|
90
|
+
// No baseName, so this is ID is resolved relative
|
91
|
+
// to baseUrl, pull off the leading dot.
|
92
|
+
name = name.substring(2);
|
93
|
+
}
|
94
|
+
}
|
95
|
+
|
96
|
+
//Apply map config if available.
|
97
|
+
if ((baseParts || starMap) && map) {
|
98
|
+
nameParts = name.split('/');
|
99
|
+
|
100
|
+
for (i = nameParts.length; i > 0; i -= 1) {
|
101
|
+
nameSegment = nameParts.slice(0, i).join("/");
|
102
|
+
|
103
|
+
if (baseParts) {
|
104
|
+
//Find the longest baseName segment match in the config.
|
105
|
+
//So, do joins on the biggest to smallest lengths of baseParts.
|
106
|
+
for (j = baseParts.length; j > 0; j -= 1) {
|
107
|
+
mapValue = map[baseParts.slice(0, j).join('/')];
|
108
|
+
|
109
|
+
//baseName segment has config, find if it has one for
|
110
|
+
//this name.
|
111
|
+
if (mapValue) {
|
112
|
+
mapValue = mapValue[nameSegment];
|
113
|
+
if (mapValue) {
|
114
|
+
//Match, update name to the new value.
|
115
|
+
foundMap = mapValue;
|
116
|
+
foundI = i;
|
117
|
+
break;
|
118
|
+
}
|
119
|
+
}
|
120
|
+
}
|
121
|
+
}
|
122
|
+
|
123
|
+
if (foundMap) {
|
124
|
+
break;
|
125
|
+
}
|
126
|
+
|
127
|
+
//Check for a star map match, but just hold on to it,
|
128
|
+
//if there is a shorter segment match later in a matching
|
129
|
+
//config, then favor over this star map.
|
130
|
+
if (!foundStarMap && starMap && starMap[nameSegment]) {
|
131
|
+
foundStarMap = starMap[nameSegment];
|
132
|
+
starI = i;
|
133
|
+
}
|
134
|
+
}
|
135
|
+
|
136
|
+
if (!foundMap && foundStarMap) {
|
137
|
+
foundMap = foundStarMap;
|
138
|
+
foundI = starI;
|
139
|
+
}
|
140
|
+
|
141
|
+
if (foundMap) {
|
142
|
+
nameParts.splice(0, foundI, foundMap);
|
143
|
+
name = nameParts.join('/');
|
144
|
+
}
|
145
|
+
}
|
146
|
+
|
147
|
+
return name;
|
148
|
+
}
|
149
|
+
|
150
|
+
function makeRequire(relName, forceSync) {
|
151
|
+
return function () {
|
152
|
+
//A version of a require function that passes a moduleName
|
153
|
+
//value for items that may need to
|
154
|
+
//look up paths relative to the moduleName
|
155
|
+
return req.apply(undef, aps.call(arguments, 0).concat([relName, forceSync]));
|
156
|
+
};
|
157
|
+
}
|
158
|
+
|
159
|
+
function makeNormalize(relName) {
|
160
|
+
return function (name) {
|
161
|
+
return normalize(name, relName);
|
162
|
+
};
|
163
|
+
}
|
164
|
+
|
165
|
+
function makeLoad(depName) {
|
166
|
+
return function (value) {
|
167
|
+
defined[depName] = value;
|
168
|
+
};
|
169
|
+
}
|
170
|
+
|
171
|
+
function callDep(name) {
|
172
|
+
if (hasProp(waiting, name)) {
|
173
|
+
var args = waiting[name];
|
174
|
+
delete waiting[name];
|
175
|
+
defining[name] = true;
|
176
|
+
main.apply(undef, args);
|
177
|
+
}
|
178
|
+
|
179
|
+
if (!hasProp(defined, name) && !hasProp(defining, name)) {
|
180
|
+
throw new Error('No ' + name);
|
181
|
+
}
|
182
|
+
return defined[name];
|
183
|
+
}
|
184
|
+
|
185
|
+
//Turns a plugin!resource to [plugin, resource]
|
186
|
+
//with the plugin being undefined if the name
|
187
|
+
//did not have a plugin prefix.
|
188
|
+
function splitPrefix(name) {
|
189
|
+
var prefix,
|
190
|
+
index = name ? name.indexOf('!') : -1;
|
191
|
+
if (index > -1) {
|
192
|
+
prefix = name.substring(0, index);
|
193
|
+
name = name.substring(index + 1, name.length);
|
194
|
+
}
|
195
|
+
return [prefix, name];
|
196
|
+
}
|
197
|
+
|
198
|
+
/**
|
199
|
+
* Makes a name map, normalizing the name, and using a plugin
|
200
|
+
* for normalization if necessary. Grabs a ref to plugin
|
201
|
+
* too, as an optimization.
|
202
|
+
*/
|
203
|
+
makeMap = function (name, relName) {
|
204
|
+
var plugin,
|
205
|
+
parts = splitPrefix(name),
|
206
|
+
prefix = parts[0];
|
207
|
+
|
208
|
+
name = parts[1];
|
209
|
+
|
210
|
+
if (prefix) {
|
211
|
+
prefix = normalize(prefix, relName);
|
212
|
+
plugin = callDep(prefix);
|
213
|
+
}
|
214
|
+
|
215
|
+
//Normalize according
|
216
|
+
if (prefix) {
|
217
|
+
if (plugin && plugin.normalize) {
|
218
|
+
name = plugin.normalize(name, makeNormalize(relName));
|
219
|
+
} else {
|
220
|
+
name = normalize(name, relName);
|
221
|
+
}
|
222
|
+
} else {
|
223
|
+
name = normalize(name, relName);
|
224
|
+
parts = splitPrefix(name);
|
225
|
+
prefix = parts[0];
|
226
|
+
name = parts[1];
|
227
|
+
if (prefix) {
|
228
|
+
plugin = callDep(prefix);
|
229
|
+
}
|
230
|
+
}
|
231
|
+
|
232
|
+
//Using ridiculous property names for space reasons
|
233
|
+
return {
|
234
|
+
f: prefix ? prefix + '!' + name : name, //fullName
|
235
|
+
n: name,
|
236
|
+
pr: prefix,
|
237
|
+
p: plugin
|
238
|
+
};
|
239
|
+
};
|
240
|
+
|
241
|
+
function makeConfig(name) {
|
242
|
+
return function () {
|
243
|
+
return (config && config.config && config.config[name]) || {};
|
244
|
+
};
|
245
|
+
}
|
246
|
+
|
247
|
+
handlers = {
|
248
|
+
require: function (name) {
|
249
|
+
return makeRequire(name);
|
250
|
+
},
|
251
|
+
exports: function (name) {
|
252
|
+
var e = defined[name];
|
253
|
+
if (typeof e !== 'undefined') {
|
254
|
+
return e;
|
255
|
+
} else {
|
256
|
+
return (defined[name] = {});
|
257
|
+
}
|
258
|
+
},
|
259
|
+
module: function (name) {
|
260
|
+
return {
|
261
|
+
id: name,
|
262
|
+
uri: '',
|
263
|
+
exports: defined[name],
|
264
|
+
config: makeConfig(name)
|
265
|
+
};
|
266
|
+
}
|
267
|
+
};
|
268
|
+
|
269
|
+
main = function (name, deps, callback, relName) {
|
270
|
+
var cjsModule, depName, ret, map, i,
|
271
|
+
args = [],
|
272
|
+
callbackType = typeof callback,
|
273
|
+
usingExports;
|
274
|
+
|
275
|
+
//Use name if no relName
|
276
|
+
relName = relName || name;
|
277
|
+
|
278
|
+
//Call the callback to define the module, if necessary.
|
279
|
+
if (callbackType === 'undefined' || callbackType === 'function') {
|
280
|
+
//Pull out the defined dependencies and pass the ordered
|
281
|
+
//values to the callback.
|
282
|
+
//Default to [require, exports, module] if no deps
|
283
|
+
deps = !deps.length && callback.length ? ['require', 'exports', 'module'] : deps;
|
284
|
+
for (i = 0; i < deps.length; i += 1) {
|
285
|
+
map = makeMap(deps[i], relName);
|
286
|
+
depName = map.f;
|
287
|
+
|
288
|
+
//Fast path CommonJS standard dependencies.
|
289
|
+
if (depName === "require") {
|
290
|
+
args[i] = handlers.require(name);
|
291
|
+
} else if (depName === "exports") {
|
292
|
+
//CommonJS module spec 1.1
|
293
|
+
args[i] = handlers.exports(name);
|
294
|
+
usingExports = true;
|
295
|
+
} else if (depName === "module") {
|
296
|
+
//CommonJS module spec 1.1
|
297
|
+
cjsModule = args[i] = handlers.module(name);
|
298
|
+
} else if (hasProp(defined, depName) ||
|
299
|
+
hasProp(waiting, depName) ||
|
300
|
+
hasProp(defining, depName)) {
|
301
|
+
args[i] = callDep(depName);
|
302
|
+
} else if (map.p) {
|
303
|
+
map.p.load(map.n, makeRequire(relName, true), makeLoad(depName), {});
|
304
|
+
args[i] = defined[depName];
|
305
|
+
} else {
|
306
|
+
throw new Error(name + ' missing ' + depName);
|
307
|
+
}
|
308
|
+
}
|
309
|
+
|
310
|
+
ret = callback ? callback.apply(defined[name], args) : undefined;
|
311
|
+
|
312
|
+
if (name) {
|
313
|
+
//If setting exports via "module" is in play,
|
314
|
+
//favor that over return value and exports. After that,
|
315
|
+
//favor a non-undefined return value over exports use.
|
316
|
+
if (cjsModule && cjsModule.exports !== undef &&
|
317
|
+
cjsModule.exports !== defined[name]) {
|
318
|
+
defined[name] = cjsModule.exports;
|
319
|
+
} else if (ret !== undef || !usingExports) {
|
320
|
+
//Use the return value from the function.
|
321
|
+
defined[name] = ret;
|
322
|
+
}
|
323
|
+
}
|
324
|
+
} else if (name) {
|
325
|
+
//May just be an object definition for the module. Only
|
326
|
+
//worry about defining if have a module name.
|
327
|
+
defined[name] = callback;
|
328
|
+
}
|
329
|
+
};
|
330
|
+
|
331
|
+
requirejs = require = req = function (deps, callback, relName, forceSync, alt) {
|
332
|
+
if (typeof deps === "string") {
|
333
|
+
if (handlers[deps]) {
|
334
|
+
//callback in this case is really relName
|
335
|
+
return handlers[deps](callback);
|
336
|
+
}
|
337
|
+
//Just return the module wanted. In this scenario, the
|
338
|
+
//deps arg is the module name, and second arg (if passed)
|
339
|
+
//is just the relName.
|
340
|
+
//Normalize module name, if it contains . or ..
|
341
|
+
return callDep(makeMap(deps, callback).f);
|
342
|
+
} else if (!deps.splice) {
|
343
|
+
//deps is a config object, not an array.
|
344
|
+
config = deps;
|
345
|
+
if (config.deps) {
|
346
|
+
req(config.deps, config.callback);
|
347
|
+
}
|
348
|
+
if (!callback) {
|
349
|
+
return;
|
350
|
+
}
|
351
|
+
|
352
|
+
if (callback.splice) {
|
353
|
+
//callback is an array, which means it is a dependency list.
|
354
|
+
//Adjust args if there are dependencies
|
355
|
+
deps = callback;
|
356
|
+
callback = relName;
|
357
|
+
relName = null;
|
358
|
+
} else {
|
359
|
+
deps = undef;
|
360
|
+
}
|
361
|
+
}
|
362
|
+
|
363
|
+
//Support require(['a'])
|
364
|
+
callback = callback || function () {
|
365
|
+
};
|
366
|
+
|
367
|
+
//If relName is a function, it is an errback handler,
|
368
|
+
//so remove it.
|
369
|
+
if (typeof relName === 'function') {
|
370
|
+
relName = forceSync;
|
371
|
+
forceSync = alt;
|
372
|
+
}
|
373
|
+
|
374
|
+
//Simulate async callback;
|
375
|
+
if (forceSync) {
|
376
|
+
main(undef, deps, callback, relName);
|
377
|
+
} else {
|
378
|
+
//Using a non-zero value because of concern for what old browsers
|
379
|
+
//do, and latest browsers "upgrade" to 4 if lower value is used:
|
380
|
+
//http://www.whatwg.org/specs/web-apps/current-work/multipage/timers.html#dom-windowtimers-settimeout:
|
381
|
+
//If want a value immediately, use require('id') instead -- something
|
382
|
+
//that works in almond on the global level, but not guaranteed and
|
383
|
+
//unlikely to work in other AMD implementations.
|
384
|
+
setTimeout(function () {
|
385
|
+
main(undef, deps, callback, relName);
|
386
|
+
}, 4);
|
387
|
+
}
|
388
|
+
|
389
|
+
return req;
|
390
|
+
};
|
391
|
+
|
392
|
+
/**
|
393
|
+
* Just drops the config on the floor, but returns req in case
|
394
|
+
* the config return value is used.
|
395
|
+
*/
|
396
|
+
req.config = function (cfg) {
|
397
|
+
return req(cfg);
|
398
|
+
};
|
399
|
+
|
400
|
+
/**
|
401
|
+
* Expose module registry for debugging and tooling
|
402
|
+
*/
|
403
|
+
requirejs._defined = defined;
|
404
|
+
|
405
|
+
define = function (name, deps, callback) {
|
406
|
+
|
407
|
+
//This module may not have dependencies
|
408
|
+
if (!deps.splice) {
|
409
|
+
//deps is not an array, so probably means
|
410
|
+
//an object literal or factory function for
|
411
|
+
//the value. Adjust args.
|
412
|
+
callback = deps;
|
413
|
+
deps = [];
|
414
|
+
}
|
415
|
+
|
416
|
+
if (!hasProp(defined, name) && !hasProp(waiting, name)) {
|
417
|
+
waiting[name] = [name, deps, callback];
|
418
|
+
}
|
419
|
+
};
|
420
|
+
|
421
|
+
define.amd = {
|
422
|
+
jQuery: true
|
423
|
+
};
|
424
|
+
}());
|
425
|
+
|
426
|
+
define("almond", function(){});
|
427
|
+
|
428
|
+
define('app',[], function () {
|
429
|
+
|
430
|
+
// initialize Application
|
431
|
+
var initialize = function () {
|
432
|
+
};
|
433
|
+
|
434
|
+
return {
|
435
|
+
initialize: initialize
|
436
|
+
};
|
437
|
+
});
|
438
|
+
|
439
|
+
|
440
|
+
require.config({});
|
441
|
+
|
442
|
+
require(["app"], function (App) {
|
443
|
+
App.initialize();
|
444
|
+
});
|
445
|
+
|
446
|
+
define("application", function(){});
|
447
|
+
}());
|