rails_jskit 4.0.0 → 5.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: 90f67bdb3c2039afcf6dbff34fbf12ce567c7859
4
- data.tar.gz: 38185acfa7fe8000068e0e0ebd2d0b9cbf0b87a4
3
+ metadata.gz: 7cfada1cab937ef9b8502560244c406545178417
4
+ data.tar.gz: 9a1decf703ee7a5d321542c7acf32ad72a674efd
5
5
  SHA512:
6
- metadata.gz: 0043f7fafb6df89815d2c5bbc5d4b47a362bb6464f3ff7e10eb5be9db7ed9583ed3f29efe67826ba1d855f09be7247be8b26c2e12c5e48ebf0e928f6ea58aa2d
7
- data.tar.gz: d6d9c284dec2fadd84afdbffa98a471816ac222bba602aa28442a657f5e0afd8bd685901dd4f5e7336194638864934387ffb2b577c3441fe3b8150922e758799
6
+ metadata.gz: 1cf188610748aa597bd9a46c3655204bab5e37aaf6fb98b5230e9de373184d40c13b6467b51e8f6b76b56931989f7c65fdc7be07fd52083a99de451803c2b760
7
+ data.tar.gz: 1e69b27142a52ab2eca03eeffda2c6d91e555153a2ee3fe86a6e06e1a090eaccf216eb1c010fc20f408f724df4fae322e154534fe8a82deb9b9c81c8bb34171b
data/README.md CHANGED
@@ -1,10 +1,11 @@
1
- rails_jskit
1
+ ![RailsJskit](https://raw.githubusercontent.com/daytonn/rails_jskit/master/logo.png "rails_jskit")
2
2
  ===========
3
3
 
4
4
  [![Gem Version](https://badge.fury.io/rb/rails_jskit.svg)](http://badge.fury.io/rb/rails_jskit)
5
5
 
6
6
  rails_jskit is a gem that let's you seamlessly integrate rails with [JSkit](https://github.com/daytonn/jskit). View the example repo [here](https://github.com/daytonn/rails_jskit-example) or see it in action [here](https://jskit-rails-example.herokuapp.com/)
7
7
 
8
+ [Documentation](http://daytonn.github.io/rails_jskit/documentation.html)
8
9
 
9
10
  ### Dependencies
10
11
  * [lodash](https://lodash.com/) or [underscore](http://underscorejs.org/)
@@ -172,8 +172,10 @@ JSkit.Controller = (function() {
172
172
  var isFunc = _.isFunction;
173
173
  var isObject = _.isObject;
174
174
  var keys = _.keys;
175
+ var last = _.last;
175
176
  var map = _.map;
176
177
  var pairs = _.pairs;
178
+ var reduce = _.reduce;
177
179
  var uniq = _.uniq;
178
180
  var values = _.values;
179
181
 
@@ -276,8 +278,8 @@ JSkit.Controller = (function() {
276
278
  * @param {String} action
277
279
  */
278
280
  function cacheElements(controller, action) {
279
- if (controller.elements[action]) {
280
- each(controller.elements[action], function(selector, name) {
281
+ if (reduceElements(controller.elements, first)[action]) {
282
+ each(reduceElements(controller.elements, first)[action], function(selector, name) {
281
283
  controller["$" + name] = $(selector);
282
284
  }, controller);
283
285
  }
@@ -293,8 +295,8 @@ JSkit.Controller = (function() {
293
295
  * @param {String} action
294
296
  */
295
297
  function registerEvents(controller, action) {
296
- if (controller.events[action]) {
297
- each(controller.events[action], function(eventMap, element) {
298
+ if (reduceElements(controller.elements, last)[action]) {
299
+ each(reduceElements(controller.elements, last)[action], function(eventMap, element) {
298
300
  each(eventMap, function(method, evnt) {
299
301
  var handler = controller[method];
300
302
  var $element = controller["$" + element];
@@ -313,7 +315,7 @@ JSkit.Controller = (function() {
313
315
  * @param {Controller} controller
314
316
  */
315
317
  function registerElementCaching(controller) {
316
- each(controller.elements, function(elements, action) {
318
+ each(reduceElements(controller.elements, first), function(elements, action) {
317
319
  controller.dispatcher.before(actionEventName(controller, action), function() {
318
320
  cacheElements(controller, action);
319
321
  }, controller);
@@ -329,13 +331,35 @@ JSkit.Controller = (function() {
329
331
  * @param {Controller} controller
330
332
  */
331
333
  function registerControllerEvents(controller) {
332
- each(controller.events, function(eventMap, action) {
334
+ each(reduceElements(controller.elements, last), function(eventMap, action) {
333
335
  controller.dispatcher.on(actionEventName(controller, action), function() {
334
336
  registerEvents(controller, action);
335
337
  }, controller);
336
338
  }, controller);
337
339
  }
338
340
 
341
+ /**
342
+ * Reduce the controller's elements object into an object
343
+ * that only contains either the elements to cache or the
344
+ * events to register to that element.
345
+ *
346
+ * @private
347
+ *
348
+ * @method reduceElements
349
+ * @param {Object} controller's elements object
350
+ * @param {Function} function to grab either head or tail (first, last)
351
+ * @return {Object}
352
+ */
353
+ function reduceElements(elements, accessMethod) {
354
+ return reduce(elements, function(memo, value, key) {
355
+ memo[key] = {};
356
+ each(value, function(v, k) {
357
+ memo[key][k] = accessMethod(flatten([v]));
358
+ });
359
+ return memo;
360
+ }, {});
361
+ }
362
+
339
363
  return {
340
364
  /**
341
365
  * Factory function to create fresh controller objects
@@ -409,14 +433,6 @@ JSkit.Controller = (function() {
409
433
  * @type Object
410
434
  * @default {}
411
435
  */
412
- events: {},
413
- /**
414
- * String to seperate event name segments
415
- *
416
- * @property eventSeparator
417
- * @type String
418
- * @default ":"
419
- */
420
436
  eventSeparator: ":",
421
437
  /**
422
438
  * Default implementation that commits no operation
@@ -431,6 +447,7 @@ JSkit.Controller = (function() {
431
447
  });
432
448
  bindAll(controller);
433
449
  controller.actions.unshift("all");
450
+
434
451
  registerElementCaching(controller);
435
452
  registerControllerEvents(controller);
436
453
  registerActions(controller);
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_jskit
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dayton Nolan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-23 00:00:00.000000000 Z
11
+ date: 2015-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: appraisal
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: sqlite3
29
43
  requirement: !ruby/object:Gem::Requirement