modulejs-rails 1.5.0.0 → 1.9.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4e0e5bb749994c8a1d21de5e0f1d5d98c6671dfd
4
- data.tar.gz: d71d082bc7962ee6f17b794a1ce4956361cf2819
3
+ metadata.gz: 680453523ff2c13c73f0fc272511f74ebdbcd048
4
+ data.tar.gz: 73747c46addda75bea1f231fd20404b03825a70a
5
5
  SHA512:
6
- metadata.gz: bc1d431f32b6261cfbc37ba79807e046504397fcf8a0765a2b2eec0998f93059daf9a2d506092d4d0f696063950d630bb19634a88a6401d2942d042e7a91a186
7
- data.tar.gz: 60011a834c36d08f720b8a26e9280c95767811bdd4c45cefae67a0aeb2d321063af1ff4816827caeb0541f6db8a0290561e7ecc33e0a516ae41511fe6a771cff
6
+ metadata.gz: b1aedf2e6c47437b868c8744b09f3f439ffb62bd35fd17c0bdbd44af19c4cedfc507798847eebb5e6ae0e586fd733653294c132b28c5e8c5cfc5a8dc9ed903e7
7
+ data.tar.gz: e38233c68f9161c56fca77310911ba248f5843f942b5089723905f1af19599725515d8e47fc28e5ca4685e8f45024bd34e7c657ea2b3a02a3398a68046ec48b5
@@ -1,5 +1,5 @@
1
1
  module Modulejs
2
2
  module Rails
3
- VERSION = "1.5.0.0"
3
+ VERSION = "1.9.0.0"
4
4
  end
5
5
  end
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
- require 'lib/modulejs/rails/version'
2
+ require_relative 'lib/modulejs/rails/version'
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = "modulejs-rails"
@@ -9,7 +9,7 @@ Lightweight JavaScript module system.
9
9
  ## License
10
10
  The MIT License (MIT)
11
11
 
12
- Copyright (c) 2014 Lars Jung (http://larsjung.de)
12
+ Copyright (c) 2015 Lars Jung (http://larsjung.de)
13
13
 
14
14
  Permission is hereby granted, free of charge, to any person obtaining a copy
15
15
  of this software and associated documentation files (the "Software"), to deal
@@ -34,8 +34,8 @@ THE SOFTWARE.
34
34
  [github]: https://github.com/lrsjng/modulejs
35
35
  [travis]: https://travis-ci.org/lrsjng/modulejs
36
36
 
37
- [license-img]: http://img.shields.io/badge/license-MIT-a0a060.svg?style=flat-square
38
- [web-img]: http://img.shields.io/badge/web-larsjung.de/modulejs-a0a060.svg?style=flat-square
39
- [github-img]: http://img.shields.io/badge/github-lrsjng/modulejs-a0a060.svg?style=flat-square
40
- [bower-img]: http://img.shields.io/badge/bower-lrsjng/modulejs-a0a060.svg?style=flat-square
41
- [travis-img]: http://img.shields.io/travis/lrsjng/modulejs.svg?style=flat-square
37
+ [license-img]: https://img.shields.io/badge/license-MIT-a0a060.svg?style=flat-square
38
+ [web-img]: https://img.shields.io/badge/web-larsjung.de/modulejs-a0a060.svg?style=flat-square
39
+ [github-img]: https://img.shields.io/badge/github-lrsjng/modulejs-a0a060.svg?style=flat-square
40
+ [bower-img]: https://img.shields.io/badge/bower-lrsjng/modulejs-a0a060.svg?style=flat-square
41
+ [travis-img]: https://img.shields.io/travis/lrsjng/modulejs.svg?style=flat-square
@@ -1,283 +1,244 @@
1
- /* modulejs 1.5.0 - http://larsjung.de/modulejs/ */
2
- (function (factory) {
3
-
4
- this.modulejs = factory();
5
-
6
- }(function () {
1
+ (function (root, factory) {
7
2
  'use strict';
8
3
 
9
- // # Util
10
-
11
- // References.
12
- var objectPrototype = Object.prototype;
13
- var arrayForEach = Array.prototype.forEach;
14
-
15
- // Returns a function that returns `true` if `arg` is of the correct `type`, otherwise `false`.
16
- function createIsTypeFn(type) {
17
-
18
- return function (arg) {
19
-
20
- return objectPrototype.toString.call(arg) === '[object ' + type + ']';
21
- };
4
+ // istanbul ignore else
5
+ if (typeof exports === 'object') {
6
+ module.exports = factory();
7
+ } else {
8
+ root.modulejs = factory();
22
9
  }
23
10
 
24
- // ## isString
25
- // Returns `true` if argument is a string, otherwise `false`.
26
- var isString = createIsTypeFn('String');
27
-
28
- // ## isFunction
29
- // Returns `true` if argument is a function, otherwise `false`.
30
- var isFunction = createIsTypeFn('Function');
31
-
32
- // ## isArray
33
- // Returns `true` if argument is an array, otherwise `false`.
34
- var isArray = Array.isArray || createIsTypeFn('Array');
11
+ }(this, function () {
12
+ 'use strict';
35
13
 
36
- // ## isObject
37
- // Returns `true` if argument is an object, otherwise `false`.
38
- function isObject(arg) {
14
+ var OBJ_PROTO = Object.prototype;
39
15
 
40
- return arg === new Object(arg);
41
- }
16
+ // Returns a function that returns `true` if `x` is of the correct
17
+ // `type`, otherwise `false`.
18
+ function _create_is_x_fn(type) {
19
+ return function (x) {
20
+ return OBJ_PROTO.toString.call(x) === '[object ' + type + ']';
21
+ };
22
+ }
42
23
 
43
- // ## has
44
- // Short cut for `hasOwnProperty`.
45
- function has(arg, id) {
24
+ // Type checking functions.
25
+ var isArray = _create_is_x_fn('Array');
26
+ var isFunction = _create_is_x_fn('Function');
27
+ var isString = _create_is_x_fn('String');
46
28
 
47
- return objectPrototype.hasOwnProperty.call(arg, id);
48
- }
49
-
50
- // ## each
51
- // Iterates over all elements af an array or all own keys of an object.
52
- function each(obj, iterator, context) {
29
+ // Short cut for `hasOwnProperty`.
30
+ function has(x, id) {
31
+ return x !== undefined && x !== null && OBJ_PROTO.hasOwnProperty.call(x, id);
32
+ }
53
33
 
54
- if (arrayForEach && obj.forEach === arrayForEach) {
55
- obj.forEach(iterator, context);
56
- } else if (obj.length === +obj.length) {
57
- for (var i = 0, l = obj.length; i < l; i += 1) {
58
- iterator.call(context, obj[i], i, obj);
59
- }
60
- } else {
61
- for (var key in obj) {
62
- if (has(obj, key)) {
63
- iterator.call(context, obj[key], key, obj);
34
+ // Iterates over all elements af an array or all own keys of an object.
35
+ function each(x, fn) {
36
+ if (x && x.length) {
37
+ for (var i = 0, l = x.length; i < l; i += 1) {
38
+ fn(x[i], i, x);
39
+ }
40
+ } else {
41
+ for (var k in x) {
42
+ if (has(x, k)) {
43
+ fn(x[k], k, x);
44
+ }
64
45
  }
65
46
  }
66
47
  }
67
- }
68
-
69
- // ## contains
70
- // Returns `true` if array contains element, otherwise `false`.
71
- function contains(array, element) {
72
48
 
73
- for (var i = 0, l = array.length; i < l; i += 1) {
74
- if (array[i] === element) {
75
- return true;
49
+ // Returns `true` if `x` contains `val`, otherwise `false`.
50
+ function contains(x, val) {
51
+ if (x && x.length) {
52
+ for (var i = 0, l = x.length; i < l; i += 1) {
53
+ if (x[i] === val) {
54
+ return true;
55
+ }
56
+ }
76
57
  }
58
+ return false;
77
59
  }
78
- return false;
79
- }
80
-
81
- // ## uniq
82
- // Returns an new array containing no duplicates. Preserves first occurence and order.
83
- function uniq(array) {
84
-
85
- var elements = {};
86
- var result = [];
87
60
 
88
- each(array, function (el) {
61
+ // Returns an new array containing no duplicates. Preserves first
62
+ // occurence and order.
63
+ function uniq(x) {
64
+ var result = [];
65
+ each(x, function (val) {
66
+ if (!contains(result, val)) {
67
+ result.push(val);
68
+ }
69
+ });
70
+ return result;
71
+ }
89
72
 
90
- if (!has(elements, el)) {
91
- result.push(el);
92
- elements[el] = 1;
73
+ // Throws an error if `expression` is falsy.
74
+ function assert(expression, message) {
75
+ if (!expression) {
76
+ throw new Error('[modulejs] ' + message);
93
77
  }
94
- });
95
-
96
- return result;
97
- }
98
-
99
- // ## err
100
- // Throws an error if `condition` is `true`.
101
- function err(condition, code, message) {
102
-
103
- if (condition) {
104
- var e = new Error('[modulejs-' + code + '] ' + message);
105
- e.code = code;
106
- throw e;
107
78
  }
108
- }
109
-
110
79
 
80
+ function create() {
81
+ // Module definitions.
82
+ var definitions = {};
111
83
 
112
- // # Private
84
+ // Module instances.
85
+ var instances = {};
113
86
 
114
- // ## definitions
115
- // Module definitions.
116
- var definitions = {};
87
+ // Resolves `id` to an object. If `mixed` is `true` only returns
88
+ // dependency-IDs. If `mixed` is an object it is used instead of the
89
+ // already memorized `instances` to allow mock-dependencies. `stack`
90
+ // is used internal to check for circular dependencies.
91
+ function resolve(id, mixed, stack) {
117
92
 
118
- // ## instances
119
- // Module instances.
120
- var instances = {};
93
+ // check arguments
94
+ assert(isString(id), 'id must be string: ' + id);
95
+ var onlyDepIds = mixed === true;
96
+ var resolvedInstances = (onlyDepIds ? undefined : mixed) || instances;
121
97
 
122
- // ## resolve
123
- // Resolves an `id` to an object, or if `onlyDepIds` is `true` only returns dependency-ids.
124
- // `stack` is used internal to check for circular dependencies.
125
- function resolve(id, onlyDepIds, stack) {
98
+ // if a module is required that was already created return that
99
+ // object
100
+ if (!onlyDepIds && has(resolvedInstances, id)) {
101
+ return resolvedInstances[id];
102
+ }
126
103
 
127
- // check arguments
128
- err(!isString(id), 31, 'id must be a string "' + id + '"');
104
+ // check if `id` is defined
105
+ var def = definitions[id];
106
+ assert(def, 'id not defined: ' + id);
129
107
 
130
- // if a module is required that was already created return that object
131
- if (!onlyDepIds && has(instances, id)) {
132
- return instances[id];
133
- }
108
+ // copy resolve stack and add this `id`
109
+ stack = (stack || []).slice();
110
+ stack.push(id);
134
111
 
135
- // check if `id` is defined
136
- var def = definitions[id];
137
- err(!def, 32, 'id not defined "' + id + '"');
112
+ // if `onlyDepIds` this will hold the dependency-IDs, otherwise it
113
+ // will hold the dependency-objects
114
+ var deps = [];
138
115
 
139
- // copy resolve stack and add this `id`
140
- stack = (stack || []).slice(0);
141
- stack.push(id);
116
+ each(def.deps, function (depId) {
142
117
 
143
- // if onlyDepIds this will hold the dependency-ids, otherwise it will hold the dependency-objects
144
- var deps = [];
118
+ // check for circular dependencies
119
+ assert(!contains(stack, depId), 'circular dependencies: ' + depId + ' in ' + stack);
145
120
 
146
- each(def.deps, function (depId) {
121
+ if (onlyDepIds) {
122
+ deps = deps.concat(resolve(depId, mixed, stack));
123
+ deps.push(depId);
124
+ } else {
125
+ deps.push(resolve(depId, mixed, stack));
126
+ }
127
+ });
147
128
 
148
- // check for circular dependencies
149
- err(contains(stack, depId), 33, 'circular dependencies: ' + stack + ' & ' + depId);
129
+ // if `onlyDepIds` return only dependency-ids in right order
130
+ if (onlyDepIds) {
131
+ return uniq(deps);
132
+ }
150
133
 
151
- if (onlyDepIds) {
152
- deps = deps.concat(resolve(depId, onlyDepIds, stack));
153
- deps.push(depId);
154
- } else {
155
- deps.push(resolve(depId, onlyDepIds, stack));
134
+ // create, memorize and return object
135
+ var obj = def.fn.apply(undefined, deps);
136
+ resolvedInstances[id] = obj;
137
+ return obj;
156
138
  }
157
- });
158
-
159
- // if `onlyDepIds` return only dependency-ids in right order
160
- if (onlyDepIds) {
161
- return uniq(deps);
162
- }
163
-
164
- // create, memorize and return object
165
- var obj = def.fn.apply(undefined, deps);
166
- instances[id] = obj;
167
- return obj;
168
- }
169
-
170
-
171
-
172
- // # Public
173
-
174
- // ## define
175
- // Defines a module for `id: String`, optional `deps: Array[String]`,
176
- // `arg: Object/function`.
177
- function define(id, deps, arg) {
178
-
179
- // sort arguments
180
- if (arg === undefined) {
181
- arg = deps;
182
- deps = [];
183
- }
184
- // check arguments
185
- err(!isString(id), 11, 'id must be a string "' + id + '"');
186
- err(definitions[id], 12, 'id already defined "' + id + '"');
187
- err(!isArray(deps), 13, 'dependencies for "' + id + '" must be an array "' + deps + '"');
188
- err(!isObject(arg) && !isFunction(arg), 14, 'arg for "' + id + '" must be object or function "' + arg + '"');
189
-
190
- // accept definition
191
- definitions[id] = {
192
- id: id,
193
- deps: deps,
194
- fn: isFunction(arg) ? arg : function () { return arg; }
195
- };
196
- }
197
139
 
198
- // ## require
199
- // Returns an instance for `id`.
200
- function require(id) {
140
+ // Defines a module for `id: String`, optional `deps: Array[String]`,
141
+ // `def: mixed`.
142
+ function define(id, deps, def) {
201
143
 
202
- return resolve(id);
203
- }
144
+ // sort arguments
145
+ if (arguments.length < 3) {
146
+ def = deps;
147
+ deps = [];
148
+ }
149
+ // check arguments
150
+ assert(isString(id), 'id must be string: ' + id);
151
+ assert(!has(definitions, id), 'id already defined: ' + id);
152
+ assert(isArray(deps), 'deps must be array: ' + id);
153
+
154
+ // accept definition
155
+ definitions[id] = {
156
+ id: id,
157
+ deps: deps,
158
+ fn: isFunction(def) ? def : function () { return def; }
159
+ };
160
+ }
204
161
 
205
- // ## state
206
- // Returns an object that holds infos about the current definitions and dependencies.
207
- function state() {
162
+ // Returns an instance for `id`. If a `mocks` object is given, it is
163
+ // used to resolve the dependencies.
164
+ function require(id, mocks) {
208
165
 
209
- var res = {};
166
+ return resolve(id, mocks);
167
+ }
210
168
 
211
- each(definitions, function (def, id) {
169
+ // Returns an object that holds infos about the current definitions
170
+ // and dependencies.
171
+ function state() {
212
172
 
213
- res[id] = {
173
+ var res = {};
214
174
 
215
- // direct dependencies
216
- deps: def.deps.slice(0),
175
+ each(definitions, function (def, id) {
217
176
 
218
- // transitive dependencies
219
- reqs: resolve(id, true),
177
+ res[id] = {
220
178
 
221
- // already initiated/required
222
- init: has(instances, id)
223
- };
224
- });
179
+ // direct dependencies
180
+ deps: def.deps.slice(),
225
181
 
226
- each(definitions, function (def, id) {
182
+ // transitive dependencies
183
+ reqs: resolve(id, true),
227
184
 
228
- var inv = [];
229
- each(definitions, function (def2, id2) {
185
+ // already initiated/required
186
+ init: has(instances, id)
187
+ };
188
+ });
230
189
 
231
- if (contains(res[id2].reqs, id)) {
232
- inv.push(id2);
233
- }
234
- });
190
+ each(definitions, function (def, id) {
235
191
 
236
- // all inverse dependencies
237
- res[id].reqd = inv;
238
- });
192
+ var inv = [];
193
+ each(definitions, function (def2, id2) {
239
194
 
240
- return res;
241
- }
195
+ if (contains(res[id2].reqs, id)) {
196
+ inv.push(id2);
197
+ }
198
+ });
242
199
 
243
- // ## log
244
- // Returns a string that displays module dependencies.
245
- function log(inv) {
200
+ // all inverse dependencies
201
+ res[id].reqd = inv;
202
+ });
246
203
 
247
- var out = '\n';
204
+ return res;
205
+ }
248
206
 
249
- each(state(), function (st, id) {
207
+ // Returns a string that displays module dependencies.
208
+ function log(inv) {
250
209
 
251
- var list = inv ? st.reqd : st.reqs;
252
- out += (st.init ? '* ' : ' ') + id + ' -> [ ' + list.join(', ') + ' ]\n';
253
- });
210
+ var out = '\n';
254
211
 
255
- return out;
256
- }
212
+ each(state(), function (st, id) {
257
213
 
214
+ var list = inv ? st.reqd : st.reqs;
215
+ out += (st.init ? '* ' : ' ') + id + ' -> [ ' + list.join(', ') + ' ]\n';
216
+ });
258
217
 
218
+ return out;
219
+ }
259
220
 
260
- // # Publish
261
-
262
- return {
263
- define: define,
264
- require: require,
265
- state: state,
266
- log: log,
267
- _private: {
268
- isString: isString,
269
- isFunction: isFunction,
270
- isArray: isArray,
271
- isObject: isObject,
272
- has: has,
273
- each: each,
274
- contains: contains,
275
- uniq: uniq,
276
- err: err,
277
- definitions: definitions,
278
- instances: instances,
279
- resolve: resolve
221
+ return {
222
+ create: create,
223
+ define: define,
224
+ log: log,
225
+ require: require,
226
+ state: state,
227
+ _private: {
228
+ assert: assert,
229
+ contains: contains,
230
+ definitions: definitions,
231
+ each: each,
232
+ has: has,
233
+ instances: instances,
234
+ isArray: isArray,
235
+ isFunction: isFunction,
236
+ isString: isString,
237
+ resolve: resolve,
238
+ uniq: uniq
239
+ }
240
+ };
280
241
  }
281
- };
282
242
 
243
+ return create();
283
244
  }));
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: modulejs-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0.0
4
+ version: 1.9.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ales Vilchytski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-25 00:00:00.000000000 Z
11
+ date: 2015-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -69,7 +69,7 @@ files:
69
69
  - lib/modulejs/rails/engine.rb
70
70
  - lib/modulejs/rails/version.rb
71
71
  - modulejs-rails.gemspec
72
- - vendor/assets/javascripts/README-1.5.0.md
72
+ - vendor/assets/javascripts/README-1.9.0.md
73
73
  - vendor/assets/javascripts/modulejs.js
74
74
  homepage: https://github.com/ales-vilchytski/modulejs-rails
75
75
  licenses: