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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 680453523ff2c13c73f0fc272511f74ebdbcd048
|
4
|
+
data.tar.gz: 73747c46addda75bea1f231fd20404b03825a70a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1aedf2e6c47437b868c8744b09f3f439ffb62bd35fd17c0bdbd44af19c4cedfc507798847eebb5e6ae0e586fd733653294c132b28c5e8c5cfc5a8dc9ed903e7
|
7
|
+
data.tar.gz: e38233c68f9161c56fca77310911ba248f5843f942b5089723905f1af19599725515d8e47fc28e5ca4685e8f45024bd34e7c657ea2b3a02a3398a68046ec48b5
|
data/modulejs-rails.gemspec
CHANGED
@@ -9,7 +9,7 @@ Lightweight JavaScript module system.
|
|
9
9
|
## License
|
10
10
|
The MIT License (MIT)
|
11
11
|
|
12
|
-
Copyright (c)
|
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]:
|
38
|
-
[web-img]:
|
39
|
-
[github-img]:
|
40
|
-
[bower-img]:
|
41
|
-
[travis-img]:
|
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
|
-
|
2
|
-
(function (factory) {
|
3
|
-
|
4
|
-
this.modulejs = factory();
|
5
|
-
|
6
|
-
}(function () {
|
1
|
+
(function (root, factory) {
|
7
2
|
'use strict';
|
8
3
|
|
9
|
-
//
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
25
|
-
|
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
|
-
|
37
|
-
// Returns `true` if argument is an object, otherwise `false`.
|
38
|
-
function isObject(arg) {
|
14
|
+
var OBJ_PROTO = Object.prototype;
|
39
15
|
|
40
|
-
|
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
|
-
//
|
44
|
-
|
45
|
-
|
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
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
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
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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
|
-
|
74
|
-
|
75
|
-
|
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
|
-
|
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
|
-
|
91
|
-
|
92
|
-
|
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
|
-
//
|
84
|
+
// Module instances.
|
85
|
+
var instances = {};
|
113
86
|
|
114
|
-
//
|
115
|
-
//
|
116
|
-
|
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
|
-
//
|
119
|
-
|
120
|
-
var
|
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
|
-
//
|
123
|
-
//
|
124
|
-
|
125
|
-
|
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
|
-
|
128
|
-
|
104
|
+
// check if `id` is defined
|
105
|
+
var def = definitions[id];
|
106
|
+
assert(def, 'id not defined: ' + id);
|
129
107
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
}
|
108
|
+
// copy resolve stack and add this `id`
|
109
|
+
stack = (stack || []).slice();
|
110
|
+
stack.push(id);
|
134
111
|
|
135
|
-
|
136
|
-
|
137
|
-
|
112
|
+
// if `onlyDepIds` this will hold the dependency-IDs, otherwise it
|
113
|
+
// will hold the dependency-objects
|
114
|
+
var deps = [];
|
138
115
|
|
139
|
-
|
140
|
-
stack = (stack || []).slice(0);
|
141
|
-
stack.push(id);
|
116
|
+
each(def.deps, function (depId) {
|
142
117
|
|
143
|
-
|
144
|
-
|
118
|
+
// check for circular dependencies
|
119
|
+
assert(!contains(stack, depId), 'circular dependencies: ' + depId + ' in ' + stack);
|
145
120
|
|
146
|
-
|
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
|
-
|
149
|
-
|
129
|
+
// if `onlyDepIds` return only dependency-ids in right order
|
130
|
+
if (onlyDepIds) {
|
131
|
+
return uniq(deps);
|
132
|
+
}
|
150
133
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
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
|
-
//
|
199
|
-
//
|
200
|
-
function
|
140
|
+
// Defines a module for `id: String`, optional `deps: Array[String]`,
|
141
|
+
// `def: mixed`.
|
142
|
+
function define(id, deps, def) {
|
201
143
|
|
202
|
-
|
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
|
-
//
|
206
|
-
//
|
207
|
-
function
|
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
|
-
|
166
|
+
return resolve(id, mocks);
|
167
|
+
}
|
210
168
|
|
211
|
-
|
169
|
+
// Returns an object that holds infos about the current definitions
|
170
|
+
// and dependencies.
|
171
|
+
function state() {
|
212
172
|
|
213
|
-
|
173
|
+
var res = {};
|
214
174
|
|
215
|
-
|
216
|
-
deps: def.deps.slice(0),
|
175
|
+
each(definitions, function (def, id) {
|
217
176
|
|
218
|
-
|
219
|
-
reqs: resolve(id, true),
|
177
|
+
res[id] = {
|
220
178
|
|
221
|
-
|
222
|
-
|
223
|
-
};
|
224
|
-
});
|
179
|
+
// direct dependencies
|
180
|
+
deps: def.deps.slice(),
|
225
181
|
|
226
|
-
|
182
|
+
// transitive dependencies
|
183
|
+
reqs: resolve(id, true),
|
227
184
|
|
228
|
-
|
229
|
-
|
185
|
+
// already initiated/required
|
186
|
+
init: has(instances, id)
|
187
|
+
};
|
188
|
+
});
|
230
189
|
|
231
|
-
|
232
|
-
inv.push(id2);
|
233
|
-
}
|
234
|
-
});
|
190
|
+
each(definitions, function (def, id) {
|
235
191
|
|
236
|
-
|
237
|
-
|
238
|
-
});
|
192
|
+
var inv = [];
|
193
|
+
each(definitions, function (def2, id2) {
|
239
194
|
|
240
|
-
|
241
|
-
|
195
|
+
if (contains(res[id2].reqs, id)) {
|
196
|
+
inv.push(id2);
|
197
|
+
}
|
198
|
+
});
|
242
199
|
|
243
|
-
//
|
244
|
-
|
245
|
-
|
200
|
+
// all inverse dependencies
|
201
|
+
res[id].reqd = inv;
|
202
|
+
});
|
246
203
|
|
247
|
-
|
204
|
+
return res;
|
205
|
+
}
|
248
206
|
|
249
|
-
|
207
|
+
// Returns a string that displays module dependencies.
|
208
|
+
function log(inv) {
|
250
209
|
|
251
|
-
|
252
|
-
out += (st.init ? '* ' : ' ') + id + ' -> [ ' + list.join(', ') + ' ]\n';
|
253
|
-
});
|
210
|
+
var out = '\n';
|
254
211
|
|
255
|
-
|
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
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
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.
|
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:
|
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.
|
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:
|