jskit_rails 3.1.0 → 3.2.0
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 +4 -4
- data/app/assets/javascripts/jskit.js +95 -33
- data/app/assets/javascripts/jskit.min.js +3 -3
- data/app/assets/javascripts/jskit/application.js.es6 +10 -10
- data/app/assets/javascripts/jskit/controller.js.es6 +33 -9
- data/app/assets/javascripts/jskit/string.js.es6 +12 -7
- data/app/assets/javascripts/jskit/test_dispatcher.js.es6 +39 -12
- data/app/assets/javascripts/jskit_rails.js.erb +1 -1
- data/app/assets/javascripts/jskit_rails_min.js.erb +1 -1
- data/app/assets/javascripts/jskit_rails_standalone.js.erb +3 -0
- data/app/assets/javascripts/jskit_standalone.js +95 -33
- metadata +3 -2
@@ -2,11 +2,22 @@
|
|
2
2
|
import _ from "lodash";
|
3
3
|
import Events from "backbone-events-standalone";
|
4
4
|
|
5
|
+
var clone = _.clone;
|
6
|
+
var contains = _.contains;
|
7
|
+
var each = _.each;
|
8
|
+
var first = _.first;
|
9
|
+
var functions = _.functions;
|
10
|
+
var isString = _.isString;
|
11
|
+
var keys = _.keys;
|
12
|
+
var toArray = _.toArray;
|
13
|
+
var values = _.values;
|
14
|
+
var map = _.map;
|
15
|
+
var rest = _.rest;
|
16
|
+
|
5
17
|
function spyOn(handler) {
|
6
18
|
handler.called = false;
|
7
19
|
handler.callCount = 0;
|
8
20
|
handler.calls = [];
|
9
|
-
|
10
21
|
return handler;
|
11
22
|
}
|
12
23
|
|
@@ -14,49 +25,67 @@ function mapAction(action) {
|
|
14
25
|
var name;
|
15
26
|
var method;
|
16
27
|
|
17
|
-
name =
|
18
|
-
method =
|
28
|
+
name = isString(action) ? action : first(keys(action));
|
29
|
+
method = isString(action) ? action : first(values(action));
|
19
30
|
|
20
31
|
return { name: name, method: method };
|
21
32
|
}
|
22
33
|
|
23
34
|
function actionName(action) {
|
24
35
|
var actionMap = mapAction(action);
|
25
|
-
return
|
36
|
+
return isString(action) ? `"${action}"` : `{ ${actionMap.name}: "${actionMap.method}" }`;
|
26
37
|
}
|
27
38
|
|
28
|
-
class TestDispatcher {
|
39
|
+
export default class TestDispatcher {
|
29
40
|
constructor() {
|
41
|
+
this.listeners = [];
|
30
42
|
this.events = {};
|
31
|
-
this.shadowDispatcher =
|
43
|
+
this.shadowDispatcher = clone(Events);
|
32
44
|
}
|
33
45
|
|
34
46
|
on(eventName, handler, controller) {
|
47
|
+
if (!contains(this.listeners, controller)) this.spyOnControllerMethods(controller);
|
35
48
|
var spy = spyOn(handler);
|
36
49
|
|
37
50
|
this.events[eventName] = this.events[eventName] || [];
|
38
51
|
this.events[eventName].push(spy);
|
39
52
|
|
40
53
|
this.shadowDispatcher.on(eventName, function() {
|
41
|
-
this.trackSpy(spy);
|
54
|
+
this.trackSpy(spy, arguments);
|
55
|
+
}, this);
|
56
|
+
}
|
57
|
+
|
58
|
+
spyOnControllerMethods(controller) {
|
59
|
+
var actionNames = map(controller.actions, (action) => { return actionName(action); });
|
60
|
+
var _this = this;
|
61
|
+
each(functions(controller), (method) => {
|
62
|
+
if (!contains(actionNames, method)) {
|
63
|
+
var unboundMethod = controller[method];
|
64
|
+
controller[method] = function() {
|
65
|
+
_this.trackSpy(controller[method], arguments);
|
66
|
+
return unboundMethod.apply(controller, arguments);
|
67
|
+
};
|
68
|
+
spyOn(controller[method]);
|
69
|
+
}
|
42
70
|
}, this);
|
71
|
+
this.listeners.push(controller);
|
43
72
|
}
|
44
73
|
|
45
74
|
trigger(eventName, handler, context) {
|
46
75
|
this.shadowDispatcher.trigger(eventName, handler, context);
|
47
76
|
}
|
48
77
|
|
49
|
-
trackSpy(spy) {
|
78
|
+
trackSpy(spy, args) {
|
50
79
|
spy.callCount += 1;
|
51
80
|
spy.called = true;
|
52
|
-
spy.calls.push({ args:
|
81
|
+
spy.calls.push({ args: toArray(args) });
|
53
82
|
}
|
54
83
|
|
55
84
|
hasAction(controller, action) {
|
56
85
|
var actionExists = false;
|
57
86
|
|
58
87
|
controller.actions.forEach((a) => {
|
59
|
-
if (actionName(a) === actionName(
|
88
|
+
if (actionName(a) === actionName(action)) actionExists = true;
|
60
89
|
});
|
61
90
|
|
62
91
|
if (!actionExists) return false;
|
@@ -74,5 +103,3 @@ class TestDispatcher {
|
|
74
103
|
|
75
104
|
off() {}
|
76
105
|
}
|
77
|
-
|
78
|
-
export default TestDispatcher;
|
@@ -8482,32 +8482,32 @@ var Events = ($__backbone_45_events_45_standalone__ = require("backbone-events-s
|
|
8482
8482
|
var _ = ($__lodash__ = require("lodash"), $__lodash__ && $__lodash__.__esModule && $__lodash__ || {default: $__lodash__}).default;
|
8483
8483
|
var s = ($__string__ = require("./string"), $__string__ && $__string__.__esModule && $__string__ || {default: $__string__}).default;
|
8484
8484
|
var BaseController = ($__controller__ = require("./controller"), $__controller__ && $__controller__.__esModule && $__controller__ || {default: $__controller__}).default;
|
8485
|
+
var clone = _.clone;
|
8486
|
+
var extend = _.extend;
|
8487
|
+
var first = _.first;
|
8485
8488
|
var Application = function Application() {
|
8486
8489
|
this.Controllers = {};
|
8487
|
-
this.Dispatcher =
|
8490
|
+
this.Dispatcher = clone(Events);
|
8488
8491
|
};
|
8489
8492
|
($traceurRuntime.createClass)(Application, {createController: function(name) {
|
8490
|
-
var $__6;
|
8491
8493
|
for (var attrs = [],
|
8492
8494
|
$__5 = 1; $__5 < arguments.length; $__5++)
|
8493
8495
|
attrs[$__5 - 1] = arguments[$__5];
|
8494
|
-
var
|
8495
|
-
|
8496
|
-
})).flatten().compact().value();
|
8497
|
-
attrs = ($__6 = _).extend.apply($__6, $traceurRuntime.spread(attrs, [{actions: allActions}]));
|
8496
|
+
var mixins = attrs.length > 2 ? attrs.slice(0, attrs.length - 1) : [];
|
8497
|
+
attrs = first(attrs.slice(attrs.length - 1)) || {};
|
8498
8498
|
var dispatcher = attrs.dispatcher || this.Dispatcher;
|
8499
8499
|
if (attrs.dispatcher)
|
8500
8500
|
delete attrs.dispatcher;
|
8501
8501
|
name = s.constantize(name);
|
8502
|
-
|
8502
|
+
extend(attrs, {name: name});
|
8503
8503
|
var Controller = function Controller() {
|
8504
8504
|
$traceurRuntime.defaultSuperCall(this, $Controller.prototype, arguments);
|
8505
8505
|
};
|
8506
8506
|
var $Controller = Controller;
|
8507
8507
|
($traceurRuntime.createClass)(Controller, {}, {}, BaseController);
|
8508
|
-
|
8508
|
+
extend(Controller.prototype, attrs);
|
8509
8509
|
this[(attrs.name + "Controller")] = Controller;
|
8510
|
-
this.Controllers[name] = new Controller(dispatcher);
|
8510
|
+
this.Controllers[name] = new (Function.prototype.bind.apply(Controller, $traceurRuntime.spread([null, dispatcher], mixins)))();
|
8511
8511
|
return this.Controllers[name];
|
8512
8512
|
}}, {});
|
8513
8513
|
var $__default = Application;
|
@@ -8526,14 +8526,26 @@ var $__lodash__,
|
|
8526
8526
|
$__string__;
|
8527
8527
|
var _ = ($__lodash__ = require("lodash"), $__lodash__ && $__lodash__.__esModule && $__lodash__ || {default: $__lodash__}).default;
|
8528
8528
|
var s = ($__string__ = require("./string"), $__string__ && $__string__.__esModule && $__string__ || {default: $__string__}).default;
|
8529
|
+
var bindAll = _.bindAll;
|
8530
|
+
var compact = _.compact;
|
8531
|
+
var defaults = _.defaults;
|
8532
|
+
var each = _.each;
|
8533
|
+
var extend = _.extend;
|
8534
|
+
var first = _.first;
|
8535
|
+
var functions = _.functions;
|
8536
|
+
var isFunction = _.isFunction;
|
8537
|
+
var isObject = _.isObject;
|
8538
|
+
var keys = _.keys;
|
8539
|
+
var uniq = _.uniq;
|
8540
|
+
var values = _.values;
|
8529
8541
|
function ensureActionIsDefined(actionMap) {
|
8530
|
-
if (!
|
8542
|
+
if (!isFunction(this[actionMap.method]))
|
8531
8543
|
throw new Error((this.className + " action \"" + actionMap.name + this.eventSeperator + actionMap.method + "\" method is undefined"));
|
8532
8544
|
}
|
8533
8545
|
function mapAction(action) {
|
8534
|
-
var isMappedAction =
|
8535
|
-
var method = isMappedAction ?
|
8536
|
-
var name = isMappedAction ?
|
8546
|
+
var isMappedAction = isObject(action);
|
8547
|
+
var method = isMappedAction ? first(values(action)) : action;
|
8548
|
+
var name = isMappedAction ? first(keys(action)) : action;
|
8537
8549
|
return {
|
8538
8550
|
name: name,
|
8539
8551
|
method: method
|
@@ -8541,7 +8553,7 @@ function mapAction(action) {
|
|
8541
8553
|
}
|
8542
8554
|
function registerActions(dispatcher) {
|
8543
8555
|
var $__2 = this;
|
8544
|
-
|
8556
|
+
each(this.actions, (function(action) {
|
8545
8557
|
var actionMap = mapAction(action);
|
8546
8558
|
ensureActionIsDefined.call($__2, actionMap);
|
8547
8559
|
$__2.dispatcher.on($__2.actionEventName(actionMap.name), $__2[actionMap.method], $__2);
|
@@ -8549,7 +8561,7 @@ function registerActions(dispatcher) {
|
|
8549
8561
|
}
|
8550
8562
|
function setControllerDefaults() {
|
8551
8563
|
this.name = this.name || "Anonymous";
|
8552
|
-
|
8564
|
+
defaults(this, {
|
8553
8565
|
eventSeperator: ":",
|
8554
8566
|
actions: [],
|
8555
8567
|
channel: "controller",
|
@@ -8557,11 +8569,26 @@ function setControllerDefaults() {
|
|
8557
8569
|
controllerEventName: s.underscore(this.name)
|
8558
8570
|
});
|
8559
8571
|
}
|
8572
|
+
function addMixins(mixins) {
|
8573
|
+
var $__2 = this;
|
8574
|
+
each(mixins, (function(mixin) {
|
8575
|
+
if (mixin.actions) {
|
8576
|
+
$__2.actions = uniq($__2.actions.concat(mixin.actions));
|
8577
|
+
delete mixin.actions;
|
8578
|
+
}
|
8579
|
+
extend($__2, mixin, $__2);
|
8580
|
+
}), this);
|
8581
|
+
}
|
8560
8582
|
var Controller = function Controller(dispatcher) {
|
8583
|
+
for (var mixins = [],
|
8584
|
+
$__4 = 1; $__4 < arguments.length; $__4++)
|
8585
|
+
mixins[$__4 - 1] = arguments[$__4];
|
8561
8586
|
if (!dispatcher)
|
8562
8587
|
throw new Error((this.className + ": dispatcher is undefined"));
|
8588
|
+
if (mixins)
|
8589
|
+
addMixins.call(this, mixins);
|
8563
8590
|
this.dispatcher = dispatcher;
|
8564
|
-
|
8591
|
+
bindAll.apply(this, [this].concat(functions(this)));
|
8565
8592
|
setControllerDefaults.call(this);
|
8566
8593
|
this.actions.unshift("all");
|
8567
8594
|
registerActions.call(this);
|
@@ -8571,7 +8598,7 @@ var Controller = function Controller(dispatcher) {
|
|
8571
8598
|
initialize: function() {},
|
8572
8599
|
all: function() {},
|
8573
8600
|
actionEventName: function(action) {
|
8574
|
-
return
|
8601
|
+
return compact([this.namespace, this.channel, this.controllerEventName, action]).join(this.eventSeperator);
|
8575
8602
|
}
|
8576
8603
|
}, {});
|
8577
8604
|
var $__default = Controller;
|
@@ -8594,7 +8621,7 @@ var Controller = ($__controller__ = require("./controller"), $__controller__ &&
|
|
8594
8621
|
}
|
8595
8622
|
};
|
8596
8623
|
|
8597
|
-
}).call(this,require("oMfpAn"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/
|
8624
|
+
}).call(this,require("oMfpAn"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/fake_2c584872.js","/")
|
8598
8625
|
},{"./application":8,"./controller":9,"./test_dispatcher":12,"buffer":3,"oMfpAn":6}],11:[function(require,module,exports){
|
8599
8626
|
(function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){
|
8600
8627
|
"use strict";
|
@@ -8606,10 +8633,14 @@ Object.defineProperties(exports, {
|
|
8606
8633
|
});
|
8607
8634
|
var $__lodash__;
|
8608
8635
|
var _ = ($__lodash__ = require("lodash"), $__lodash__ && $__lodash__.__esModule && $__lodash__ || {default: $__lodash__}).default;
|
8636
|
+
var contains = _.contains;
|
8637
|
+
var map = _.map;
|
8638
|
+
var toArray = _.toArray;
|
8639
|
+
var unescape = _.unescape;
|
8609
8640
|
var $__default = {
|
8610
8641
|
camelize: function() {
|
8611
8642
|
var string = arguments[0] !== (void 0) ? arguments[0] : "";
|
8612
|
-
return
|
8643
|
+
return map(string.split(/_|-|\s/g), function(part, i) {
|
8613
8644
|
return (i > 0) ? part.charAt(0).toUpperCase() + part.slice(1) : part.toLowerCase();
|
8614
8645
|
}).join("");
|
8615
8646
|
},
|
@@ -8629,7 +8660,7 @@ var $__default = {
|
|
8629
8660
|
constantize: function() {
|
8630
8661
|
var string = arguments[0] !== (void 0) ? arguments[0] : "";
|
8631
8662
|
if (string.match(/_|-|\s/)) {
|
8632
|
-
var s =
|
8663
|
+
var s = map(string.split(/_|-|\s/g), function(part, i) {
|
8633
8664
|
return (i > 0) ? part.charAt(0).toUpperCase() + part.slice(1) : part.toLowerCase();
|
8634
8665
|
}).join("");
|
8635
8666
|
string = s;
|
@@ -8691,13 +8722,13 @@ var $__default = {
|
|
8691
8722
|
},
|
8692
8723
|
titleCase: function() {
|
8693
8724
|
var string = arguments[0] !== (void 0) ? arguments[0] : "";
|
8694
|
-
return
|
8725
|
+
return map(string.replace(/([A-Z])/g, " $1").replace(/-|_/g, " ").split(/\s/), function(s) {
|
8695
8726
|
return s.charAt(0).toUpperCase() + s.slice(1);
|
8696
8727
|
}).join(" ");
|
8697
8728
|
},
|
8698
8729
|
titleize: function() {
|
8699
8730
|
var string = arguments[0] !== (void 0) ? arguments[0] : "";
|
8700
|
-
return
|
8731
|
+
return map(string.replace(/([A-Z])/g, " $1").replace(/-|_/g, " ").split(/\s/), function(s) {
|
8701
8732
|
return s.charAt(0).toUpperCase() + s.slice(1);
|
8702
8733
|
}).join(" ");
|
8703
8734
|
},
|
@@ -8705,9 +8736,9 @@ var $__default = {
|
|
8705
8736
|
var string = arguments[0] !== (void 0) ? arguments[0] : "";
|
8706
8737
|
var truthyStrings = ["true", "yes", "on", "y"];
|
8707
8738
|
var falseyStrings = ["false", "no", "off", "n"];
|
8708
|
-
if (
|
8739
|
+
if (contains(truthyStrings, string.toLowerCase())) {
|
8709
8740
|
return true;
|
8710
|
-
} else if (
|
8741
|
+
} else if (contains(falseyStrings, string.toLowerCase())) {
|
8711
8742
|
return false;
|
8712
8743
|
} else {
|
8713
8744
|
return string.length > 0 ? true : false;
|
@@ -8731,7 +8762,7 @@ var $__default = {
|
|
8731
8762
|
},
|
8732
8763
|
unescape: function() {
|
8733
8764
|
var string = arguments[0] !== (void 0) ? arguments[0] : "";
|
8734
|
-
return
|
8765
|
+
return unescape.apply(this, [this].concat(toArray(arguments)));
|
8735
8766
|
},
|
8736
8767
|
unwrap: function(string, wrapper) {
|
8737
8768
|
string = string || "";
|
@@ -8764,6 +8795,17 @@ var $__lodash__,
|
|
8764
8795
|
$__backbone_45_events_45_standalone__;
|
8765
8796
|
var _ = ($__lodash__ = require("lodash"), $__lodash__ && $__lodash__.__esModule && $__lodash__ || {default: $__lodash__}).default;
|
8766
8797
|
var Events = ($__backbone_45_events_45_standalone__ = require("backbone-events-standalone"), $__backbone_45_events_45_standalone__ && $__backbone_45_events_45_standalone__.__esModule && $__backbone_45_events_45_standalone__ || {default: $__backbone_45_events_45_standalone__}).default;
|
8798
|
+
var clone = _.clone;
|
8799
|
+
var contains = _.contains;
|
8800
|
+
var each = _.each;
|
8801
|
+
var first = _.first;
|
8802
|
+
var functions = _.functions;
|
8803
|
+
var isString = _.isString;
|
8804
|
+
var keys = _.keys;
|
8805
|
+
var toArray = _.toArray;
|
8806
|
+
var values = _.values;
|
8807
|
+
var map = _.map;
|
8808
|
+
var rest = _.rest;
|
8767
8809
|
function spyOn(handler) {
|
8768
8810
|
handler.called = false;
|
8769
8811
|
handler.callCount = 0;
|
@@ -8773,8 +8815,8 @@ function spyOn(handler) {
|
|
8773
8815
|
function mapAction(action) {
|
8774
8816
|
var name;
|
8775
8817
|
var method;
|
8776
|
-
name =
|
8777
|
-
method =
|
8818
|
+
name = isString(action) ? action : first(keys(action));
|
8819
|
+
method = isString(action) ? action : first(values(action));
|
8778
8820
|
return {
|
8779
8821
|
name: name,
|
8780
8822
|
method: method
|
@@ -8782,33 +8824,53 @@ function mapAction(action) {
|
|
8782
8824
|
}
|
8783
8825
|
function actionName(action) {
|
8784
8826
|
var actionMap = mapAction(action);
|
8785
|
-
return
|
8827
|
+
return isString(action) ? ("\"" + action + "\"") : ("{ " + actionMap.name + ": \"" + actionMap.method + "\" }");
|
8786
8828
|
}
|
8787
8829
|
var TestDispatcher = function TestDispatcher() {
|
8830
|
+
this.listeners = [];
|
8788
8831
|
this.events = {};
|
8789
|
-
this.shadowDispatcher =
|
8832
|
+
this.shadowDispatcher = clone(Events);
|
8790
8833
|
};
|
8791
8834
|
($traceurRuntime.createClass)(TestDispatcher, {
|
8792
8835
|
on: function(eventName, handler, controller) {
|
8836
|
+
if (!contains(this.listeners, controller))
|
8837
|
+
this.spyOnControllerMethods(controller);
|
8793
8838
|
var spy = spyOn(handler);
|
8794
8839
|
this.events[eventName] = this.events[eventName] || [];
|
8795
8840
|
this.events[eventName].push(spy);
|
8796
8841
|
this.shadowDispatcher.on(eventName, function() {
|
8797
|
-
this.trackSpy(spy);
|
8842
|
+
this.trackSpy(spy, arguments);
|
8798
8843
|
}, this);
|
8799
8844
|
},
|
8845
|
+
spyOnControllerMethods: function(controller) {
|
8846
|
+
var actionNames = map(controller.actions, (function(action) {
|
8847
|
+
return actionName(action);
|
8848
|
+
}));
|
8849
|
+
var _this = this;
|
8850
|
+
each(functions(controller), (function(method) {
|
8851
|
+
if (!contains(actionNames, method)) {
|
8852
|
+
var unboundMethod = controller[method];
|
8853
|
+
controller[method] = function() {
|
8854
|
+
_this.trackSpy(controller[method], arguments);
|
8855
|
+
return unboundMethod.apply(controller, arguments);
|
8856
|
+
};
|
8857
|
+
spyOn(controller[method]);
|
8858
|
+
}
|
8859
|
+
}), this);
|
8860
|
+
this.listeners.push(controller);
|
8861
|
+
},
|
8800
8862
|
trigger: function(eventName, handler, context) {
|
8801
8863
|
this.shadowDispatcher.trigger(eventName, handler, context);
|
8802
8864
|
},
|
8803
|
-
trackSpy: function(spy) {
|
8865
|
+
trackSpy: function(spy, args) {
|
8804
8866
|
spy.callCount += 1;
|
8805
8867
|
spy.called = true;
|
8806
|
-
spy.calls.push({args:
|
8868
|
+
spy.calls.push({args: toArray(args)});
|
8807
8869
|
},
|
8808
8870
|
hasAction: function(controller, action) {
|
8809
8871
|
var actionExists = false;
|
8810
8872
|
controller.actions.forEach((function(a) {
|
8811
|
-
if (actionName(a) === actionName(
|
8873
|
+
if (actionName(a) === actionName(action))
|
8812
8874
|
actionExists = true;
|
8813
8875
|
}));
|
8814
8876
|
if (!actionExists)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jskit_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.2.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: 2014-12-
|
11
|
+
date: 2014-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -127,6 +127,7 @@ files:
|
|
127
127
|
- app/assets/javascripts/jskit/test_dispatcher.js.es6
|
128
128
|
- app/assets/javascripts/jskit_rails.js.erb
|
129
129
|
- app/assets/javascripts/jskit_rails_min.js.erb
|
130
|
+
- app/assets/javascripts/jskit_rails_standalone.js.erb
|
130
131
|
- app/assets/javascripts/jskit_standalone.js
|
131
132
|
- app/assets/stylesheets/jskit_rails/application.css
|
132
133
|
- app/decorators/controllers/jskit_rails/application_controller_decorator.rb
|