jskit_rails 3.3.0 → 3.3.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 +4 -4
- data/README.md +4 -0
- data/app/assets/javascripts/jskit/legacy/application.js.es6 +47 -0
- data/app/assets/javascripts/jskit/legacy/controller.js.es6 +12 -0
- data/app/assets/javascripts/jskit/legacy/jskit.js.es6 +7 -0
- data/app/assets/javascripts/jskit/legacy/string.js.es6 +177 -0
- data/app/assets/javascripts/jskit/legacy/test_dispatcher.js.es6 +104 -0
- data/app/assets/javascripts/jskit.js +1 -1
- data/app/assets/javascripts/jskit.min.js +1 -1
- data/app/assets/javascripts/jskit_legacy.js +8876 -0
- data/app/assets/javascripts/jskit_legacy.min.js +2 -0
- data/app/assets/javascripts/jskit_rails_legacy.js.erb +3 -0
- data/app/assets/javascripts/jskit_rails_legacy_min.js.erb +3 -0
- data/app/assets/javascripts/jskit_rails_standalone_min.js.erb +1 -1
- data/app/assets/javascripts/jskit_standalone.js +1 -1
- data/app/assets/javascripts/jskit_standalone.min.js +1 -1
- metadata +11 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f433dd81fd6f9875133b4a26443a753421bfc09b
|
4
|
+
data.tar.gz: 0d1451f8957a41e0edbfb3b70ee1a888247904ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7d0c310296d7546e3fba92c86b9da3b751ce73b27ee543e2d2a9460ff5519a1e3d16e5044bb313e70dbbdea3b7d2b4b12ac0523535bae5ff968636b2c213df9
|
7
|
+
data.tar.gz: 107538142113619b92404ecb4e9b9498a99f48cf5725bc3e13a0d936cecfec151303b57c21d0299163c74ea7085995fb0fbeb962bb1f2381bd44f4b3cac7a9ed
|
data/README.md
CHANGED
@@ -193,6 +193,10 @@ end
|
|
193
193
|
|
194
194
|
This should be everything you need to design and test basic client-side interactions with JSKit. If you'd like to see a working example check out [this repo](https://github.com/daytonn/jskit_rails-example).
|
195
195
|
|
196
|
+
JSKit Builds
|
197
|
+
------------
|
198
|
+
|
199
|
+
|
196
200
|
Traceur Compiler
|
197
201
|
----------------
|
198
202
|
|
@@ -0,0 +1,47 @@
|
|
1
|
+
var _ = require("lodash");
|
2
|
+
var BaseController = require("./controller");
|
3
|
+
var Dispatcher = require("backbone-events-standalone");
|
4
|
+
|
5
|
+
function Application() {
|
6
|
+
this.Controllers = {};
|
7
|
+
this.Dispatcher = Dispatcher;
|
8
|
+
}
|
9
|
+
|
10
|
+
function createControllerInstance(attributes, name) {
|
11
|
+
function Controller() { BaseController.call(this); }
|
12
|
+
Controller.prototype = Object.create(BaseController.prototype);
|
13
|
+
Controller.prototype.constructor = Controller;
|
14
|
+
_.extend(Controller.prototype, attributes);
|
15
|
+
this[name + "Controller"] = Controller;
|
16
|
+
return new Controller;
|
17
|
+
}
|
18
|
+
|
19
|
+
function registerControllerActions(controller, actions, name, namespace) {
|
20
|
+
_(actions).each(function(action) {
|
21
|
+
if (!controller[action] || !_.isFunction(controller[action])) {
|
22
|
+
throw new Error("'" + name + "' Controller has an action '" + action + "' defined with no corresponding method");
|
23
|
+
}
|
24
|
+
|
25
|
+
var eventName = _([namespace, "controller", underscoreName(name), action]).compact().join(":");
|
26
|
+
this.Dispatcher.on(eventName, controller[action], controller);
|
27
|
+
}, this);
|
28
|
+
}
|
29
|
+
|
30
|
+
function underscoreName(name) {
|
31
|
+
return name.replace(/([A-Z])/g, " $1").replace(/^\s?/, "").replace(/-|\s/g, "_").toLowerCase();
|
32
|
+
}
|
33
|
+
|
34
|
+
function registerApplicationControllerActions(controller, namespace) {
|
35
|
+
if (!controller.init) throw new Error("'Application' Controller: init is undefined");
|
36
|
+
var eventName = _([namespace, "controller", "all"]).compact().join(":");
|
37
|
+
this.Dispatcher.on(eventName, controller.init, controller);
|
38
|
+
}
|
39
|
+
|
40
|
+
Application.prototype.createController = function(name, attributes) {
|
41
|
+
var controller = createControllerInstance.call(this, attributes, name);
|
42
|
+
registerControllerActions.call(this, controller, attributes.actions, name, attributes.namespace);
|
43
|
+
if (name.match(/^Application$/i)) registerApplicationControllerActions.call(this, controller, attributes.namespace);
|
44
|
+
return this.Controllers[name] = controller;
|
45
|
+
};
|
46
|
+
|
47
|
+
module.exports = Application;
|
@@ -0,0 +1,12 @@
|
|
1
|
+
var _ = require("lodash");
|
2
|
+
|
3
|
+
function Controller() {
|
4
|
+
this.initialize();
|
5
|
+
_.bindAll.apply(this, [this].concat(_.functions(this)));
|
6
|
+
}
|
7
|
+
|
8
|
+
Controller.prototype.initialize = function() {};
|
9
|
+
|
10
|
+
Controller.prototype.actions = [];
|
11
|
+
|
12
|
+
module.exports = Controller;
|
@@ -0,0 +1,177 @@
|
|
1
|
+
var _ require("lodash");
|
2
|
+
|
3
|
+
var contains = _.contains;
|
4
|
+
var map = _.map;
|
5
|
+
var toArray = _.toArray;
|
6
|
+
var unescape = _.unescape;
|
7
|
+
|
8
|
+
module.exports = {
|
9
|
+
camelize: function(string) {
|
10
|
+
string = string || "";
|
11
|
+
return map(string.split(/_|-|\s/g), function(part, i) {
|
12
|
+
return (i > 0) ? part.charAt(0).toUpperCase() + part.slice(1) : part.toLowerCase();
|
13
|
+
}).join("");
|
14
|
+
},
|
15
|
+
|
16
|
+
capitalize: function(string) {
|
17
|
+
string = string || "";
|
18
|
+
return string.charAt(0).toUpperCase() + string.slice(1);
|
19
|
+
},
|
20
|
+
|
21
|
+
chunk: function(string, chunkSize) {
|
22
|
+
string = string || "";
|
23
|
+
chunkSize = chunkSize ? chunkSize : string.length;
|
24
|
+
return string.match(new RegExp(".{1," + chunkSize + "}", "g"));
|
25
|
+
},
|
26
|
+
|
27
|
+
compact: function(string) {
|
28
|
+
string = string || "";
|
29
|
+
return string.replace(/\s/g, "");
|
30
|
+
},
|
31
|
+
|
32
|
+
constantize: function(string) {
|
33
|
+
string = string || "";
|
34
|
+
if (string.match(/_|-|\s/)) {
|
35
|
+
var s = map(string.split(/_|-|\s/g), function(part, i) {
|
36
|
+
return (i > 0) ? part.charAt(0).toUpperCase() + part.slice(1) : part.toLowerCase();
|
37
|
+
}).join("");
|
38
|
+
string = s;
|
39
|
+
} else {
|
40
|
+
string = string.toString();
|
41
|
+
}
|
42
|
+
return string.charAt(0).toUpperCase() + string.slice(1);
|
43
|
+
},
|
44
|
+
|
45
|
+
dasherize: function(string) {
|
46
|
+
string = string || "";
|
47
|
+
return string.replace(/_/g, "-").toLowerCase();
|
48
|
+
},
|
49
|
+
|
50
|
+
humanize: function(string) {
|
51
|
+
string = string || "";
|
52
|
+
var s = string.replace(/_/g, " ").replace(/^\s?/, "").toLowerCase();
|
53
|
+
return s.charAt(0).toUpperCase() + s.slice(1);
|
54
|
+
},
|
55
|
+
|
56
|
+
hyphenate: function(string) {
|
57
|
+
string = string || "";
|
58
|
+
return string.replace(/([A-Z])/g, " $1").toLowerCase().replace(/\s|_/g, "-").toLowerCase();
|
59
|
+
},
|
60
|
+
|
61
|
+
isBlank: function(string) {
|
62
|
+
string = string || "";
|
63
|
+
return (/^(\s?)+$/).test(this);
|
64
|
+
},
|
65
|
+
|
66
|
+
isEmpty: function(string) {
|
67
|
+
string = string || "";
|
68
|
+
return string.length === 0;
|
69
|
+
},
|
70
|
+
|
71
|
+
isNotEmpty: function(string) {
|
72
|
+
string = string || "";
|
73
|
+
return string.length > 0;
|
74
|
+
},
|
75
|
+
|
76
|
+
isPresent: function(string) {
|
77
|
+
string = string || "";
|
78
|
+
return !(/^(\s?)+$/).test(this);
|
79
|
+
},
|
80
|
+
|
81
|
+
lstrip: function(string) {
|
82
|
+
string = string || "";
|
83
|
+
return string.replace(/^\s+/, "");
|
84
|
+
},
|
85
|
+
|
86
|
+
ltrim: function(string) {
|
87
|
+
string = string || "";
|
88
|
+
return string.replace(/^\s+/, "");
|
89
|
+
},
|
90
|
+
|
91
|
+
stripTags: function(string) {
|
92
|
+
string = string || "";
|
93
|
+
return string.replace(/<\w+(\s+("[^"]*"|"[^"]*"|[^>])+)?>|<\/\w+>/gi, "");
|
94
|
+
},
|
95
|
+
|
96
|
+
strip: function(string) {
|
97
|
+
string = string || "";
|
98
|
+
return string.replace(/^\s+(.+)\s+$/, "$1");
|
99
|
+
},
|
100
|
+
|
101
|
+
swapCase: function(string) {
|
102
|
+
string = string || "";
|
103
|
+
return string.replace(/[A-Za-z]/g, function(s) {
|
104
|
+
return (/[A-Z]/).test(s) ? s.toLowerCase() : s.toUpperCase();
|
105
|
+
});
|
106
|
+
},
|
107
|
+
|
108
|
+
titleCase: function(string) {
|
109
|
+
string = string || "";
|
110
|
+
return map(string.replace(/([A-Z])/g, " $1").replace(/-|_/g, " ").split(/\s/), function(s) {
|
111
|
+
return s.charAt(0).toUpperCase() + s.slice(1);
|
112
|
+
}).join(" ");
|
113
|
+
},
|
114
|
+
|
115
|
+
titleize: function(string) {
|
116
|
+
string = string || "";
|
117
|
+
return map(string.replace(/([A-Z])/g, " $1").replace(/-|_/g, " ").split(/\s/), function(s) {
|
118
|
+
return s.charAt(0).toUpperCase() + s.slice(1);
|
119
|
+
}).join(" ");
|
120
|
+
},
|
121
|
+
|
122
|
+
toBoolean: function(string) {
|
123
|
+
string = string || "";
|
124
|
+
var truthyStrings = ["true", "yes", "on", "y"];
|
125
|
+
var falseyStrings = ["false", "no", "off", "n"];
|
126
|
+
if (contains(truthyStrings, string.toLowerCase())) {
|
127
|
+
return true;
|
128
|
+
} else if (contains(falseyStrings, string.toLowerCase())) {
|
129
|
+
return false;
|
130
|
+
} else {
|
131
|
+
return string.length > 0 ? true : false;
|
132
|
+
}
|
133
|
+
},
|
134
|
+
|
135
|
+
toNumber: function(string) {
|
136
|
+
string = string || "";
|
137
|
+
return this * 1 || 0;
|
138
|
+
},
|
139
|
+
|
140
|
+
trim: function(string) {
|
141
|
+
string = string || "";
|
142
|
+
return string.replace(/^\s+(.+)\s+$/, "$1");
|
143
|
+
},
|
144
|
+
|
145
|
+
truncate: function(string, length) {
|
146
|
+
string = string || "";
|
147
|
+
return (string.length > length) ? string.substring(0, length) + "..." : this;
|
148
|
+
},
|
149
|
+
|
150
|
+
underscore: function(string) {
|
151
|
+
string = string || "";
|
152
|
+
return string.replace(/([A-Z])/g, " $1").replace(/^\s?/, "").replace(/-|\s/g, "_").toLowerCase();
|
153
|
+
},
|
154
|
+
|
155
|
+
unescape: function(string) {
|
156
|
+
string = string || "";
|
157
|
+
return unescape.apply(this, [this].concat(toArray(arguments)));
|
158
|
+
},
|
159
|
+
|
160
|
+
unwrap: function(string, wrapper) {
|
161
|
+
string = string || "";
|
162
|
+
return string.replace(new RegExp("^" + wrapper + "(.+)" + wrapper + "$"), "$1");
|
163
|
+
},
|
164
|
+
|
165
|
+
wordCount: function(string, word) {
|
166
|
+
string = string || "";
|
167
|
+
var matches;
|
168
|
+
string = string.stripTags();
|
169
|
+
matches = (word) ? string.match(new RegExp(word, "g")) : string.match(/\b[A-Za-z_]+\b/g);
|
170
|
+
return matches ? matches.length : 0;
|
171
|
+
},
|
172
|
+
|
173
|
+
wrap: function(string, wrapper) {
|
174
|
+
string = string || "";
|
175
|
+
return wrapper.concat(this, wrapper);
|
176
|
+
}
|
177
|
+
};
|
@@ -0,0 +1,104 @@
|
|
1
|
+
var _ = require("lodash");
|
2
|
+
var Events = require("backbone-events-standalone");
|
3
|
+
|
4
|
+
var clone = _.clone;
|
5
|
+
var contains = _.contains;
|
6
|
+
var each = _.each;
|
7
|
+
var first = _.first;
|
8
|
+
var functions = _.functions;
|
9
|
+
var isString = _.isString;
|
10
|
+
var keys = _.keys;
|
11
|
+
var toArray = _.toArray;
|
12
|
+
var values = _.values;
|
13
|
+
var map = _.map;
|
14
|
+
var rest = _.rest;
|
15
|
+
|
16
|
+
function spyOn(handler) {
|
17
|
+
handler.called = false;
|
18
|
+
handler.callCount = 0;
|
19
|
+
handler.calls = [];
|
20
|
+
return handler;
|
21
|
+
}
|
22
|
+
|
23
|
+
function mapAction(action) {
|
24
|
+
var name;
|
25
|
+
var method;
|
26
|
+
|
27
|
+
name = isString(action) ? action : first(keys(action));
|
28
|
+
method = isString(action) ? action : first(values(action));
|
29
|
+
|
30
|
+
return { name: name, method: method };
|
31
|
+
}
|
32
|
+
|
33
|
+
function actionName(action) {
|
34
|
+
var actionMap = mapAction(action);
|
35
|
+
return isString(action) ? '"' + action + '"' : '{ ' + actionMap.name + ': "' + actionMap.method + '" }';
|
36
|
+
}
|
37
|
+
|
38
|
+
function TestDispatcher() {
|
39
|
+
this.listeners = [];
|
40
|
+
this.events = {};
|
41
|
+
this.shadowDispatcher = clone(Events);
|
42
|
+
}
|
43
|
+
|
44
|
+
TestDispatcher.prototype.on = function(eventName, handler, controller) {
|
45
|
+
if (!contains(this.listeners, controller)) this.spyOnControllerMethods(controller);
|
46
|
+
var spy = spyOn(handler);
|
47
|
+
|
48
|
+
this.events[eventName] = this.events[eventName] || [];
|
49
|
+
this.events[eventName].push(spy);
|
50
|
+
|
51
|
+
this.shadowDispatcher.on(eventName, function() {
|
52
|
+
this.trackSpy(spy, arguments);
|
53
|
+
}, this);
|
54
|
+
};
|
55
|
+
|
56
|
+
TestDispatcher.prototype.spyOnControllerMethods = function(controller) {
|
57
|
+
var actionNames = map(controller.actions, function(action) { return actionName(action); });
|
58
|
+
var _this = this;
|
59
|
+
each(functions(controller), function(method) {
|
60
|
+
if (!contains(actionNames, method)) {
|
61
|
+
var unboundMethod = controller[method];
|
62
|
+
controller[method] = function() {
|
63
|
+
_this.trackSpy(controller[method], arguments);
|
64
|
+
return unboundMethod.apply(controller, arguments);
|
65
|
+
};
|
66
|
+
spyOn(controller[method]);
|
67
|
+
}
|
68
|
+
}, this);
|
69
|
+
this.listeners.push(controller);
|
70
|
+
};
|
71
|
+
|
72
|
+
TestDispatcher.prototype.trigger = function(eventName, handler, context) {
|
73
|
+
this.shadowDispatcher.trigger(eventName, handler, context);
|
74
|
+
};
|
75
|
+
|
76
|
+
TestDispatcher.prototype.trackSpy = function(spy, args) {
|
77
|
+
spy.callCount += 1;
|
78
|
+
spy.called = true;
|
79
|
+
spy.calls.push({ args: toArray(args) });
|
80
|
+
};
|
81
|
+
|
82
|
+
TestDispatcher.prototype.hasAction = function(controller, action) {
|
83
|
+
var actionExists = false;
|
84
|
+
|
85
|
+
controller.actions.forEach(function(a) {
|
86
|
+
if (actionName(a) === actionName(action)) actionExists = true;
|
87
|
+
});
|
88
|
+
|
89
|
+
if (!actionExists) return false;
|
90
|
+
|
91
|
+
var actionMap = mapAction(action);
|
92
|
+
var handler = controller[actionMap.method];
|
93
|
+
|
94
|
+
var eventName = controller.actionEventName(actionMap.name);
|
95
|
+
var cachedCount = handler.callCount;
|
96
|
+
|
97
|
+
controller.dispatcher.trigger(eventName);
|
98
|
+
|
99
|
+
return handler.callCount > cachedCount;
|
100
|
+
};
|
101
|
+
|
102
|
+
TestDispatcher.prototype.off = function() {};
|
103
|
+
|
104
|
+
module.exports = TestDispatcher;
|
@@ -11046,7 +11046,7 @@ var Controller = ($__controller__ = require("./controller"), $__controller__ &&
|
|
11046
11046
|
}
|
11047
11047
|
};
|
11048
11048
|
|
11049
|
-
}).call(this,require("oMfpAn"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/
|
11049
|
+
}).call(this,require("oMfpAn"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/fake_84388df4.js","/")
|
11050
11050
|
},{"./application":8,"./controller":9,"./test_dispatcher":12,"buffer":3,"oMfpAn":6}],11:[function(require,module,exports){
|
11051
11051
|
(function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){
|
11052
11052
|
"use strict";
|