almond-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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6777747540c835110b93e4ab0e66126ac64355c9
4
- data.tar.gz: 199a76d54725cf60f0f6be5b01bd936130832b70
3
+ metadata.gz: b4f8cfd22a57efabaf31598b2fcb7c812e13b19d
4
+ data.tar.gz: 4b0b91ad63ff6bba708026d2ace6c16e996aef62
5
5
  SHA512:
6
- metadata.gz: c94f2b0b529affaa07e3bb289b24578c8df095c517cfc56d10c0346330ee36bd645c12d4414928e0755a2fb89a20dcab70d9bb86d32188f8f109fca34bd98109
7
- data.tar.gz: f6f7d2fbf1c76b00359704fa54cfcf3d8425337776278312eb0777e48e2ceb992913207bf310f3d6caca400d4b315ea9381a8808c2ebb4890b3f95f9c738820a
6
+ metadata.gz: adcd649c928089c5cbcf911bdf12f6970cca090fd63fdd62def69a6995ab813ca02a8ed58681cf9aace01b427ccf87430923cfed819a359da0c102a1188b9d63
7
+ data.tar.gz: 35547051cae96ff326483d68e536a98742f207bcfcf15b22bac7e832161e0a556a8642ddf67c46ef831022629ff10b05b534749d4433d9b87a5f9637c21ad446
data/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ ##########################################################################
2
+ # Copyright 2016 Justin Coyne
3
+ # Additional copyright may be held by others, as reflected in the commit log
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
data/README.md CHANGED
@@ -1,3 +1,21 @@
1
- = AlmondRails
1
+ # Almond for Rails
2
2
 
3
- This project rocks and uses MIT-LICENSE.
3
+ ## Usage
4
+ In your Gemfile:
5
+
6
+ ```ruby
7
+ gem 'almond-rails'
8
+ ```
9
+
10
+ Then add to `app/assets/javascripts/application.js`:
11
+
12
+ ```javascript
13
+ //= require almond
14
+ ```
15
+
16
+ Then you can use the `require` method in your es6 javascript:
17
+
18
+ ```javascript
19
+ var module = require('path/to/module/my_class')
20
+ new module.MyClass()
21
+ ```
@@ -1,3 +1,3 @@
1
1
  module AlmondRails
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,426 @@
1
+ /**
2
+ * @license almond 0.3.2 Copyright jQuery Foundation and other contributors.
3
+ * Released under MIT license, http://github.com/requirejs/almond/LICENSE
4
+ */
5
+ //Going sloppy to avoid 'use strict' string cost, but strict practices should
6
+ //be followed.
7
+ /*global setTimeout: false */
8
+
9
+ var requirejs, require, define;
10
+ (function (undef) {
11
+ var main, req, makeMap, handlers,
12
+ defined = {},
13
+ waiting = {},
14
+ config = {},
15
+ defining = {},
16
+ hasOwn = Object.prototype.hasOwnProperty,
17
+ aps = [].slice,
18
+ jsSuffixRegExp = /\.js$/;
19
+
20
+ function hasProp(obj, prop) {
21
+ return hasOwn.call(obj, prop);
22
+ }
23
+
24
+ /**
25
+ * Given a relative module name, like ./something, normalize it to
26
+ * a real name that can be mapped to a path.
27
+ * @param {String} name the relative name
28
+ * @param {String} baseName a real name that the name arg is relative
29
+ * to.
30
+ * @returns {String} normalized name
31
+ */
32
+ function normalize(name, baseName) {
33
+ var nameParts, nameSegment, mapValue, foundMap, lastIndex,
34
+ foundI, foundStarMap, starI, i, j, part, normalizedBaseParts,
35
+ baseParts = baseName && baseName.split("/"),
36
+ map = config.map,
37
+ starMap = (map && map['*']) || {};
38
+
39
+ //Adjust any relative paths.
40
+ if (name) {
41
+ name = name.split('/');
42
+ lastIndex = name.length - 1;
43
+
44
+ // If wanting node ID compatibility, strip .js from end
45
+ // of IDs. Have to do this here, and not in nameToUrl
46
+ // because node allows either .js or non .js to map
47
+ // to same file.
48
+ if (config.nodeIdCompat && jsSuffixRegExp.test(name[lastIndex])) {
49
+ name[lastIndex] = name[lastIndex].replace(jsSuffixRegExp, '');
50
+ }
51
+
52
+ // Starts with a '.' so need the baseName
53
+ if (name[0].charAt(0) === '.' && baseParts) {
54
+ //Convert baseName to array, and lop off the last part,
55
+ //so that . matches that 'directory' and not name of the baseName's
56
+ //module. For instance, baseName of 'one/two/three', maps to
57
+ //'one/two/three.js', but we want the directory, 'one/two' for
58
+ //this normalization.
59
+ normalizedBaseParts = baseParts.slice(0, baseParts.length - 1);
60
+ name = normalizedBaseParts.concat(name);
61
+ }
62
+
63
+ //start trimDots
64
+ for (i = 0; i < name.length; i++) {
65
+ part = name[i];
66
+ if (part === '.') {
67
+ name.splice(i, 1);
68
+ i -= 1;
69
+ } else if (part === '..') {
70
+ // If at the start, or previous value is still ..,
71
+ // keep them so that when converted to a path it may
72
+ // still work when converted to a path, even though
73
+ // as an ID it is less than ideal. In larger point
74
+ // releases, may be better to just kick out an error.
75
+ if (i === 0 || (i === 1 && name[2] === '..') || name[i - 1] === '..') {
76
+ continue;
77
+ } else if (i > 0) {
78
+ name.splice(i - 1, 2);
79
+ i -= 2;
80
+ }
81
+ }
82
+ }
83
+ //end trimDots
84
+
85
+ name = name.join('/');
86
+ }
87
+
88
+ //Apply map config if available.
89
+ if ((baseParts || starMap) && map) {
90
+ nameParts = name.split('/');
91
+
92
+ for (i = nameParts.length; i > 0; i -= 1) {
93
+ nameSegment = nameParts.slice(0, i).join("/");
94
+
95
+ if (baseParts) {
96
+ //Find the longest baseName segment match in the config.
97
+ //So, do joins on the biggest to smallest lengths of baseParts.
98
+ for (j = baseParts.length; j > 0; j -= 1) {
99
+ mapValue = map[baseParts.slice(0, j).join('/')];
100
+
101
+ //baseName segment has config, find if it has one for
102
+ //this name.
103
+ if (mapValue) {
104
+ mapValue = mapValue[nameSegment];
105
+ if (mapValue) {
106
+ //Match, update name to the new value.
107
+ foundMap = mapValue;
108
+ foundI = i;
109
+ break;
110
+ }
111
+ }
112
+ }
113
+ }
114
+
115
+ if (foundMap) {
116
+ break;
117
+ }
118
+
119
+ //Check for a star map match, but just hold on to it,
120
+ //if there is a shorter segment match later in a matching
121
+ //config, then favor over this star map.
122
+ if (!foundStarMap && starMap && starMap[nameSegment]) {
123
+ foundStarMap = starMap[nameSegment];
124
+ starI = i;
125
+ }
126
+ }
127
+
128
+ if (!foundMap && foundStarMap) {
129
+ foundMap = foundStarMap;
130
+ foundI = starI;
131
+ }
132
+
133
+ if (foundMap) {
134
+ nameParts.splice(0, foundI, foundMap);
135
+ name = nameParts.join('/');
136
+ }
137
+ }
138
+
139
+ return name;
140
+ }
141
+
142
+ function makeRequire(relName, forceSync) {
143
+ return function () {
144
+ //A version of a require function that passes a moduleName
145
+ //value for items that may need to
146
+ //look up paths relative to the moduleName
147
+ var args = aps.call(arguments, 0);
148
+
149
+ //If first arg is not require('string'), and there is only
150
+ //one arg, it is the array form without a callback. Insert
151
+ //a null so that the following concat is correct.
152
+ if (typeof args[0] !== 'string' && args.length === 1) {
153
+ args.push(null);
154
+ }
155
+ return req.apply(undef, args.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
+ //If relName is a function, it is an errback handler,
367
+ //so remove it.
368
+ if (typeof relName === 'function') {
369
+ relName = forceSync;
370
+ forceSync = alt;
371
+ }
372
+
373
+ //Simulate async callback;
374
+ if (forceSync) {
375
+ main(undef, deps, callback, relName);
376
+ } else {
377
+ //Using a non-zero value because of concern for what old browsers
378
+ //do, and latest browsers "upgrade" to 4 if lower value is used:
379
+ //http://www.whatwg.org/specs/web-apps/current-work/multipage/timers.html#dom-windowtimers-settimeout:
380
+ //If want a value immediately, use require('id') instead -- something
381
+ //that works in almond on the global level, but not guaranteed and
382
+ //unlikely to work in other AMD implementations.
383
+ setTimeout(function () {
384
+ main(undef, deps, callback, relName);
385
+ }, 4);
386
+ }
387
+
388
+ return req;
389
+ };
390
+
391
+ /**
392
+ * Just drops the config on the floor, but returns req in case
393
+ * the config return value is used.
394
+ */
395
+ req.config = function (cfg) {
396
+ return req(cfg);
397
+ };
398
+
399
+ /**
400
+ * Expose module registry for debugging and tooling
401
+ */
402
+ requirejs._defined = defined;
403
+
404
+ define = function (name, deps, callback) {
405
+ if (typeof name !== 'string') {
406
+ throw new Error('See almond README: incorrect module build, no module name');
407
+ }
408
+
409
+ //This module may not have dependencies
410
+ if (!deps.splice) {
411
+ //deps is not an array, so probably means
412
+ //an object literal or factory function for
413
+ //the value. Adjust args.
414
+ callback = deps;
415
+ deps = [];
416
+ }
417
+
418
+ if (!hasProp(defined, name) && !hasProp(waiting, name)) {
419
+ waiting[name] = [name, deps, callback];
420
+ }
421
+ };
422
+
423
+ define.amd = {
424
+ jQuery: true
425
+ };
426
+ }());
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: almond-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Coyne
@@ -45,6 +45,7 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
+ - LICENSE
48
49
  - README.md
49
50
  - Rakefile
50
51
  - lib/almond-rails.rb
@@ -86,6 +87,7 @@ files:
86
87
  - test/dummy/public/500.html
87
88
  - test/dummy/public/favicon.ico
88
89
  - test/test_helper.rb
90
+ - vendor/assets/javascripts/almond.js
89
91
  homepage: https://github.com/jcoyne/almond_rails
90
92
  licenses:
91
93
  - APACHE2