rails-js-routes 0.2.0 → 0.2.1
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05194101dca7822c43e804d4c23755440cd34f55
|
4
|
+
data.tar.gz: 0f45584f2f67dc61e0dc08a175237fad3a2016d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe87c95f9a8027d253c5dc138c5911ef3945e97c74b6f9a30702ca17287a3c339d93c7d7f0d7a3e725645ee0e142d7e2be7a1ea360996cd8f4ef0424117c3e9a
|
7
|
+
data.tar.gz: 7924a3e4a26b2123becb4f00df5fc51bed87696d62ecc781792025e06630b687f2cb896752875b10c64c66d9f0e80114084e1022540bf02082d15c442de28f5e
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rails-js-routes (0.2.
|
4
|
+
rails-js-routes (0.2.1)
|
5
5
|
rails (~> 4)
|
6
6
|
|
7
7
|
GEM
|
@@ -84,7 +84,7 @@ GEM
|
|
84
84
|
activesupport (= 4.1.8)
|
85
85
|
rake (>= 0.8.7)
|
86
86
|
thor (>= 0.18.1, < 2.0)
|
87
|
-
rake (10.
|
87
|
+
rake (10.4.0)
|
88
88
|
rest-client (1.6.7)
|
89
89
|
mime-types (>= 1.16)
|
90
90
|
simplecov (0.9.1)
|
@@ -97,7 +97,7 @@ GEM
|
|
97
97
|
multi_json (~> 1.0)
|
98
98
|
rack (~> 1.0)
|
99
99
|
tilt (~> 1.1, != 1.3.0)
|
100
|
-
sprockets-rails (2.2.
|
100
|
+
sprockets-rails (2.2.1)
|
101
101
|
actionpack (>= 3.0)
|
102
102
|
activesupport (>= 3.0)
|
103
103
|
sprockets (>= 2.8, < 4.0)
|
data/README.md
CHANGED
@@ -8,8 +8,7 @@ rails-js-routes
|
|
8
8
|
|
9
9
|
[Check out the blog post!](http://finn.heemeyer.net/2014/10/18/rails-js/)
|
10
10
|
|
11
|
-
NOTICE: We decided to rename this gem from ``rails-js`` to ``rails-js-routes`` as it was nearly impossible to find
|
12
|
-
The name may be somewhat long, but for us it describes the functionality appropriate.
|
11
|
+
*NOTICE: We decided to rename this gem from ``rails-js`` to ``rails-js-routes`` as it was nearly impossible to find.*
|
13
12
|
|
14
13
|
|
15
14
|
I worked on several Rails projects and there were many cases when it felt overkill to use a framework like ``Angular`` or ``Ember``, because javascript was only needed in some parts of the application.
|
@@ -16,7 +16,7 @@
|
|
16
16
|
Rails = window.Rails || {};
|
17
17
|
|
18
18
|
/*
|
19
|
-
* For testing. We want to start each test with
|
19
|
+
* For testing. We want to start each test with emptiness.
|
20
20
|
*/
|
21
21
|
Rails.clear = function() {
|
22
22
|
controllers = {};
|
@@ -118,7 +118,7 @@
|
|
118
118
|
/*
|
119
119
|
* Execute beforeAll() hook if defined
|
120
120
|
*/
|
121
|
-
if (beforeAll && typeof(beforeAll)
|
121
|
+
if (beforeAll && typeof(beforeAll) === 'function') {
|
122
122
|
beforeAll();
|
123
123
|
}
|
124
124
|
|
@@ -132,7 +132,7 @@
|
|
132
132
|
* Execute namespace hook if we defined one
|
133
133
|
*/
|
134
134
|
namespaceHook = namespaceHooks[this.config.namespace];
|
135
|
-
if (namespaceHook && typeof(namespaceHook)
|
135
|
+
if (namespaceHook && typeof(namespaceHook) === 'function') {
|
136
136
|
namespaceHook();
|
137
137
|
}
|
138
138
|
}
|
@@ -140,9 +140,9 @@
|
|
140
140
|
/*
|
141
141
|
* Find controller and execute method
|
142
142
|
*/
|
143
|
-
|
143
|
+
controller = controllers[controllerName];
|
144
144
|
if (controller && controller[this.config.action] &&
|
145
|
-
typeof(controller[this.config.action])
|
145
|
+
typeof(controller[this.config.action]) === 'function') {
|
146
146
|
|
147
147
|
controller[this.config.action](controller.helpers);
|
148
148
|
}
|
@@ -177,7 +177,8 @@
|
|
177
177
|
* Also contains global helpers, so to prevent conflicts
|
178
178
|
* we save global variables by using this singleton as a function.
|
179
179
|
*
|
180
|
-
* R(
|
180
|
+
* R() // Gets window.R.data
|
181
|
+
* R('foo'); // Gets window.R.data.foo
|
181
182
|
* R('foo', 'bar'); // Sets window.R.data.foo
|
182
183
|
*/
|
183
184
|
R = function(key, val) {
|
@@ -191,22 +192,22 @@
|
|
191
192
|
* R('foo.bar.baz', 'foo');
|
192
193
|
*
|
193
194
|
*/
|
194
|
-
var steps = key.split('.'),
|
195
|
-
step = data,
|
196
|
-
i;
|
197
|
-
|
198
|
-
if (arguments.length == 2) {
|
199
|
-
for (i = 0; i < steps.length-1; i++) {
|
200
|
-
if (!step[steps[i]]) {
|
201
|
-
step[steps[i]] = {};
|
202
|
-
}
|
203
195
|
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
step[steps[steps.length -1]] = val;
|
196
|
+
var steps,
|
197
|
+
step,
|
198
|
+
i;
|
208
199
|
|
200
|
+
// Prepare arguments for find/set routine
|
201
|
+
// Expose private scoped data attribute, if no arguments provided
|
202
|
+
if (arguments.length) {
|
203
|
+
steps = key.split('.');
|
204
|
+
step = data;
|
209
205
|
} else {
|
206
|
+
return data;
|
207
|
+
}
|
208
|
+
|
209
|
+
// Return value for `key`
|
210
|
+
if (arguments.length === 1) {
|
210
211
|
for (i = 0; i < steps.length; i++) {
|
211
212
|
step = step[steps[i]];
|
212
213
|
if (!step) {
|
@@ -216,6 +217,21 @@
|
|
216
217
|
}
|
217
218
|
return step;
|
218
219
|
}
|
220
|
+
|
221
|
+
// Set value for `key`
|
222
|
+
// NOTE: Currently non-existing steps are created
|
223
|
+
if (arguments.length === 2) {
|
224
|
+
for (i = 0; i < steps.length - 1; i++) {
|
225
|
+
if (!step[steps[i]]) {
|
226
|
+
step[steps[i]] = {};
|
227
|
+
}
|
228
|
+
|
229
|
+
step = step[steps[i]];
|
230
|
+
}
|
231
|
+
|
232
|
+
step[steps[steps.length - 1]] = val;
|
233
|
+
return val;
|
234
|
+
}
|
219
235
|
};
|
220
236
|
|
221
237
|
/*
|
@@ -228,15 +244,15 @@
|
|
228
244
|
*/
|
229
245
|
R.helper = function(controllerName, helperName) {
|
230
246
|
|
231
|
-
var
|
232
|
-
|
247
|
+
var args = Array.prototype.slice.call(arguments, 2),
|
248
|
+
controller,
|
233
249
|
context,
|
234
|
-
|
250
|
+
helper;
|
235
251
|
|
236
252
|
/*
|
237
253
|
* Treat 3rd argument as arguments for helper if it is an Array
|
238
254
|
*/
|
239
|
-
if (args.length
|
255
|
+
if (args.length === 1 && args[0] instanceof Array) {
|
240
256
|
args = args[0];
|
241
257
|
}
|
242
258
|
|
@@ -253,7 +269,7 @@
|
|
253
269
|
/*
|
254
270
|
* Make sure our helper exists
|
255
271
|
*/
|
256
|
-
if (!
|
272
|
+
if (!helper || typeof(helper) !== 'function') {
|
257
273
|
if (controllerName) {
|
258
274
|
throw ['Helper \'', helperName, '\' not defined for controller \'',
|
259
275
|
controllerName, '\''].join('');
|
@@ -313,7 +329,7 @@
|
|
313
329
|
if (!controller) {
|
314
330
|
throw ['Attempting to call action \'', controllerName, '#', actionName,
|
315
331
|
'\', but Controller \'', controllerName, '\' is not defined!'].join('');
|
316
|
-
} else if (!controller[actionName] ||
|
332
|
+
} else if (!controller[actionName] || typeof(controller[actionName]) !== 'function') {
|
317
333
|
throw ['Attempting to call action \'', controllerName, '#', actionName,
|
318
334
|
'\', but Action \'', actionName, '\' is not defined!'].join('');
|
319
335
|
}
|
@@ -6,7 +6,7 @@
|
|
6
6
|
*/
|
7
7
|
|
8
8
|
(function() {
|
9
|
-
describe('rails-
|
9
|
+
describe('rails-js-routes', function() {
|
10
10
|
|
11
11
|
/*
|
12
12
|
* define all functions spied on
|
@@ -73,11 +73,12 @@
|
|
73
73
|
});
|
74
74
|
|
75
75
|
it('must handle global variables', function() {
|
76
|
-
R('a.global.variable', 'foo');
|
76
|
+
expect(R('a.global.variable', 'foo')).toBe('foo');
|
77
77
|
|
78
78
|
expect(R('a')).toBeDefined();
|
79
79
|
expect(R('a.global')).toBeDefined();
|
80
80
|
expect(R('a.global.variable')).toBe('foo');
|
81
|
+
expect(R()).toEqual({foo: 'bar', a: {global: {variable: 'foo'}}});
|
81
82
|
});
|
82
83
|
|
83
84
|
it('must be able to execute global helpers', function() {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-js-routes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Finn-Lenanrt Heemeyer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -144,7 +144,7 @@ files:
|
|
144
144
|
- test/dummy/public/422.html
|
145
145
|
- test/dummy/public/500.html
|
146
146
|
- test/dummy/public/favicon.ico
|
147
|
-
- test/dummy/spec/javascripts/
|
147
|
+
- test/dummy/spec/javascripts/js_routes_spec.js
|
148
148
|
- test/dummy/spec/javascripts/spec_helper.js
|
149
149
|
- test/dummy/spec/teaspoon_env.rb
|
150
150
|
- test/dummy/test/helpers/testing_helper_test.rb
|