extjs-mvc 0.4.0.f → 0.4.0.g

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. data/Rakefile +2 -2
  2. data/VERSION +1 -1
  3. data/bin/extjs-mvc +0 -3
  4. data/lib/extjs-mvc.rb +10 -6
  5. data/lib/extjs-mvc/api.rb +0 -1
  6. metadata +8 -84
  7. data/lib/src/App.js +0 -219
  8. data/lib/src/MVC.js +0 -260
  9. data/lib/src/Presenter.js +0 -52
  10. data/lib/src/README.rdoc +0 -69
  11. data/lib/src/controller/Controller.js +0 -278
  12. data/lib/src/controller/CrudController.js +0 -460
  13. data/lib/src/lib/Array.js +0 -26
  14. data/lib/src/lib/Booter.js +0 -416
  15. data/lib/src/lib/ClassManager.js +0 -191
  16. data/lib/src/lib/ControllerClassManager.js +0 -95
  17. data/lib/src/lib/Dependencies.js +0 -44
  18. data/lib/src/lib/DispatchMatcher.js +0 -98
  19. data/lib/src/lib/Dispatcher.js +0 -129
  20. data/lib/src/lib/Environment.js +0 -43
  21. data/lib/src/lib/Inflector.js +0 -155
  22. data/lib/src/lib/ModelClassManager.js +0 -19
  23. data/lib/src/lib/Route.js +0 -139
  24. data/lib/src/lib/Router.js +0 -282
  25. data/lib/src/lib/String.js +0 -94
  26. data/lib/src/lib/ViewClassManager.js +0 -229
  27. data/lib/src/lib/notes.txt +0 -32
  28. data/lib/src/model/AdapterManager.js +0 -30
  29. data/lib/src/model/Association.js +0 -26
  30. data/lib/src/model/Base.js +0 -63
  31. data/lib/src/model/BelongsToAssociation.js +0 -116
  32. data/lib/src/model/Cache.js +0 -131
  33. data/lib/src/model/HasManyAssociation.js +0 -160
  34. data/lib/src/model/Model.js +0 -331
  35. data/lib/src/model/UrlBuilder.js +0 -106
  36. data/lib/src/model/adapters/AbstractAdapter.js +0 -296
  37. data/lib/src/model/adapters/MemoryAdapter.js +0 -103
  38. data/lib/src/model/adapters/RESTAdapter.js +0 -345
  39. data/lib/src/model/adapters/RESTJSONAdapter.js +0 -68
  40. data/lib/src/model/adapters/notes.txt +0 -42
  41. data/lib/src/model/associations/Association.js +0 -192
  42. data/lib/src/model/associations/notes.txt +0 -87
  43. data/lib/src/model/validations/Errors.js +0 -136
  44. data/lib/src/model/validations/Plugin.js +0 -139
  45. data/lib/src/model/validations/Validations.js +0 -276
  46. data/lib/src/notes/Charts.graffle +0 -0
  47. data/lib/src/overrides/Ext.Component.js +0 -21
  48. data/lib/src/overrides/Ext.extend.js +0 -142
  49. data/lib/src/spec/Array.spec.js +0 -15
  50. data/lib/src/spec/ExtMVC.spec.js +0 -65
  51. data/lib/src/spec/Model.spec.js +0 -370
  52. data/lib/src/spec/OS.spec.js +0 -83
  53. data/lib/src/spec/Router.spec.js +0 -99
  54. data/lib/src/spec/SpecHelper.js +0 -106
  55. data/lib/src/spec/String.spec.js +0 -83
  56. data/lib/src/spec/model/AbstractAdapter.spec.js +0 -49
  57. data/lib/src/spec/model/Associations.spec.js +0 -99
  58. data/lib/src/spec/model/Cache.spec.js +0 -5
  59. data/lib/src/spec/model/RESTAdapter.spec.js +0 -19
  60. data/lib/src/spec/model/ValidationErrors.spec.js +0 -64
  61. data/lib/src/spec/model/Validations.spec.js +0 -166
  62. data/lib/src/spec/model/ValidationsPlugin.spec.js +0 -108
  63. data/lib/src/spec/suite.html +0 -60
  64. data/lib/src/specs-old/JSSpec.css +0 -216
  65. data/lib/src/specs-old/JSSpec.js +0 -1512
  66. data/lib/src/specs-old/all.html +0 -66
  67. data/lib/src/specs-old/base.js +0 -14
  68. data/lib/src/specs-old/controller.js +0 -17
  69. data/lib/src/specs-old/diff_match_patch.js +0 -1
  70. data/lib/src/specs-old/model.js +0 -70
  71. data/lib/src/specs-old/route.js +0 -38
  72. data/lib/src/specs-old/router.js +0 -59
  73. data/lib/src/specs-old/string.js +0 -22
  74. data/lib/src/testrunner/JSpecFormatter.js +0 -111
  75. data/lib/src/testrunner/TestClient.js +0 -181
  76. data/lib/src/testrunner/TestGrid.js +0 -351
  77. data/lib/src/testrunner/TestRunner.js +0 -110
  78. data/lib/src/testrunner/TestViewport.js +0 -94
  79. data/lib/src/vendor.yml +0 -29
  80. data/lib/src/vendor/ext-3.1.1/vendor.yml +0 -16
  81. data/lib/src/view/FormWindow.js +0 -184
  82. data/lib/src/view/HasManyEditorGridPanel.js +0 -211
  83. data/lib/src/view/scaffold/Edit.js +0 -46
  84. data/lib/src/view/scaffold/Index.js +0 -561
  85. data/lib/src/view/scaffold/New.js +0 -20
  86. data/lib/src/view/scaffold/ScaffoldFormPanel.js +0 -255
@@ -1,19 +0,0 @@
1
- /**
2
- * @class ExtMVC.lib.ModelClassManager
3
- * @extends ExtMVC.lib.ClassManager
4
- * Specialised class manager for managing models
5
- */
6
- ExtMVC.lib.ModelClassManager = Ext.extend(ExtMVC.lib.ClassManager, {
7
- //usual model definition stuff to go here
8
- define: function(name) {
9
- var overrides = this.getRegistered(name);
10
-
11
- if (overrides == undefined) {
12
- throw new Ext.Error(String.format("The {0} model has not been registered yet", name));
13
- }
14
-
15
- return this.constructors[name] = ExtMVC.model.define(name, overrides);
16
- }
17
- });
18
-
19
- ExtMVC.registerClassManager('model', new ExtMVC.lib.ModelClassManager());
@@ -1,139 +0,0 @@
1
- /**
2
- * @class ExtMVC.router.Route
3
- * @extends Object
4
- * TODO: [DOCS] Rewrite this horrible nonsense
5
- */
6
- ExtMVC.router.Route = function(mappingString, options) {
7
- this.mappingString = mappingString;
8
- this.options = options || {};
9
-
10
- //The regular expression we use to match a segment of a route mapping
11
- //this will recognise segments starting with a colon,
12
- //e.g. on 'namespace/:controller/:action', :controller and :action will be recognised
13
- this.paramMatchingRegex = new RegExp(/:([0-9A-Za-z\_]*)/g);
14
-
15
- /**
16
- * Converts a route string into an array of symbols starting with a colon. e.g.
17
- * ":controller/:action/:id" => [':controller', ':action', ':id']
18
- */
19
- this.paramsInMatchString = this.mappingString.match(this.paramMatchingRegex) || [];
20
- this.paramsInStringWithOptions = [];
21
-
22
- /**1
23
- * Store and remove any route conditions specified
24
- */
25
- this.conditions = this.options.conditions || {};
26
- if (this.options.conditions) { delete this.options.conditions; }
27
-
28
- for (var i=0; i < this.paramsInMatchString.length; i++) {
29
- this.paramsInStringWithOptions.push(this.paramsInMatchString[i]);
30
- };
31
-
32
- for (var o in options) {
33
- this.paramsInStringWithOptions.push(":" + o);
34
- }
35
-
36
- this.matcherRegex = this.convertToUsableRegex(mappingString);
37
- };
38
-
39
- ExtMVC.router.Route.prototype = {
40
- /**
41
- * @param {url} The url we want to match against this route to see if it matches
42
- * @return {boolean} Returns true if this route matches the url
43
- */
44
- recognises: function(url) {
45
- return this.matcherRegex.test(url);
46
- },
47
-
48
- /**
49
- * @param {url} The url we want to provide matches for
50
- * @return {Object} Object of all matches for this url, as well as additional params as defined in the route
51
- */
52
- matchesFor: function(url) {
53
- if (!this.recognises(url)) {return false;};
54
-
55
- var parameters = {};
56
-
57
- var keys = this.paramsInMatchString;
58
- var values = url.match(this.matcherRegex);
59
- values.shift(); //first value is the entire match so reject
60
-
61
- for (var i = keys.length - 1; i >= 0; i--){
62
- parameters[keys[i].replace(":", "")] = values[i];
63
- };
64
-
65
- //add any additional parameter options specified in the route definition
66
- for (option in this.options) {
67
- parameters[option] = this.options[option];
68
- }
69
-
70
- return parameters;
71
- },
72
-
73
- urlForNamed: function(options) {
74
- var options = options || {};
75
-
76
- return this.urlFor(Ext.applyIf(options, this.options));
77
- },
78
-
79
- /**
80
- * Attempts to build a url with this route, swapping the placeholders with properties of the options hash
81
- */
82
- urlFor: function(options) {
83
- var url = this.mappingString;
84
-
85
- for (var o in options) {
86
- //values in options must match this.options - e.g. this.options.action must be the same as options.action
87
- if (options[o] && this.options[o] && options[o] != this.options[o]) { return false; }
88
- }
89
-
90
-
91
- //TODO: Tidy this up. All of it
92
-
93
- var paramsInOptions = [];
94
- for (var o in options) {
95
- paramsInOptions.push(":" + o);
96
- }
97
-
98
- paramsInOptions = paramsInOptions.sort();
99
- var paramsInStringWithOptions = this.paramsInStringWithOptions.sort();
100
-
101
- //make sure that all match elements in the url string are included. If not, return false
102
- if (paramsInStringWithOptions.length != paramsInOptions.length) { return false; }
103
- for (var i=0; i < paramsInOptions.length; i++) {
104
- if (paramsInOptions[i] != paramsInStringWithOptions[i]) {
105
- return false;
106
- }
107
- };
108
-
109
- for (var o in options) {
110
- url = url.replace(":" + o, options[o]);
111
- }
112
-
113
- return url;
114
- },
115
-
116
- /**
117
- * Private: For a given string, replaces all substrings starting with a colon into
118
- * a regex string that can match a url segment.
119
- * e.g. :controller/:action => '^([a-zA-Z0-9\_]+)/([a-zA-Z0-9\_]+)$'
120
- * If any conditions have been specified on this route, their regular expressions are used instead:
121
- * :controller/:action/:id => '^([a-zA-Z0-9\_]+)/([a-zA-Z0-9\_]+)/([0-9]+)$'
122
- * if conditions was set to {":id" =>/[0-9]+]/}
123
- * @param {String} regex_string The string we want to turn into a matchable regex
124
- * @return {String} The replaced string
125
- */
126
- convertToUsableRegex: function(regex_string) {
127
- var p = this.paramsInMatchString;
128
-
129
- for (var i = p.length - 1; i >= 0; i--){
130
- var cond = this.conditions[p[i]];
131
- var matcher = String.format("({0})", cond || "[a-zA-Z0-9\_,]+");
132
-
133
- regex_string = regex_string.replace(new RegExp(p[i]), matcher);
134
- };
135
-
136
- //we want to match the whole string, so include the anchors
137
- return new RegExp("^" + regex_string + "$");
138
- }
139
- };
@@ -1,282 +0,0 @@
1
- /**
2
- * @class ExtMVC.router.Router
3
- * @extends Object
4
- * TODO: [DOCS] Give a good description of the Router
5
- */
6
- ExtMVC.router.Router = function() {};
7
-
8
- ExtMVC.router.Router.prototype = {
9
-
10
- /**
11
- * @property mappings
12
- * @type Array
13
- * Readonly. Maintains the collection of defined routes
14
- */
15
- mappings: [],
16
-
17
- /**
18
- * @property namedRoutes
19
- * @type Object
20
- * Readonly. Maintains the collection of named routes
21
- */
22
- namedRoutes: {},
23
-
24
- /**
25
- * Adds a new route to the collection. Routes are given priority in the order they are added
26
- * @param {String} re The regular expression-style string to match (e.g. ":controller/:action/:id")
27
- * @param {Object} additional_params Any additional options which will be returned along with the match elements if the route matches
28
- * @return {ExtMVC.router.Route} The newly created route object
29
- */
30
- connect: function(re, additional_params) {
31
- var route = new ExtMVC.router.Route(re, additional_params);
32
- this.mappings.push(route);
33
-
34
- return route;
35
- },
36
-
37
- /**
38
- * Defines a named route. This is the same as using connect, but with the option to specify the route by name. e.g.:
39
- * this.name('myRoute', 'my/custom/route/:id', {controller: 'myController', action: 'myAction'});
40
- * this.urlFor('myRoute', {id: 100}); //returns 'my/custom/route/100'
41
- * @param {String} routeName The string name to give this route
42
- * @param {String} re The regular expression-style string to match (e.g. ":controller/:action/:id")
43
- * @param {Object} additional_params Any additional options which will be returned along with the match elements if the route matches
44
- */
45
- name: function(routeName, re, additional_params) {
46
- this.namedRoutes[routeName] = this.connect(re, additional_params);
47
- },
48
-
49
- /**
50
- * Same as calling connect("", options) - connects the empty route string to a controller/action pair
51
- * @params {Object} options An object containing at least a controller and optionally an action (which is otherwise defaulted to index)
52
- */
53
- root: function(options) {
54
- var options = options || {};
55
- this.connect("", Ext.applyIf(options, { action: 'index' }));
56
- },
57
-
58
- /**
59
- * Adds specific index, new, show and edit routes for this resource. e.g.:
60
- * resources('videos') is equivalent to:
61
- * name('videos_path', 'videos', {controller: 'videos', action: 'index'});
62
- * name('new_video_path', 'videos/new', {controller: 'videos', action: 'new' });
63
- * name('video_path', 'videos/:id', {controller: 'videos', action: 'show' });
64
- * name('edit_video_path', 'videos/:id/edit', {controller: 'videos', action: 'edit' });
65
- *
66
- * You can pass a second parameter which is an options object, e.g.:
67
- * resources('videos', {controller: 'myController', myKey: 'myValue'}) sets up the following:
68
- * name('videos_path', 'videos', {controller: 'myController', myKey: 'myValue', action: 'index'});
69
- * name('new_video_path', 'videos/new', {controller: 'myController', myKey: 'myValue', action: 'new' });
70
- * name('video_path', 'videos/:id', {controller: 'myController', myKey: 'myValue', action: 'show' });
71
- * name('edit_video_path', 'videos/:id/edit', {controller: 'myController', myKey: 'myValue', action: 'edit' });
72
- *
73
- * Also accepts a series of arguments - resources('videos', 'bookmarks', 'messages')
74
- * is the same as calling resources with each
75
- *
76
- * Finally, this format is also accepted:
77
- * resources('videos', 'bookmarks', 'messages', {controller: 'myController', myKey: 'myValue'})
78
- * Which is equivalent to calling resources with each of the three strings in turn, each with the
79
- * final argument passed as options
80
- */
81
- resources: function(resource_name, options) {
82
- //if we have been passed a bunch of strings, call resources with each
83
- if (arguments[1] && typeof(arguments[1]) == 'string') {
84
- var lastArg = arguments[arguments.length - 1];
85
-
86
- var opts = (typeof(lastArg) == 'object') ? lastArg : {};
87
-
88
- for (var i=0; i < arguments.length; i++) {
89
- //don't call with the last argument if it is an object as this is a generic settings object
90
- if (!(lastArg === arguments[i] && typeof(lastArg) == 'object')) {
91
- this.resources(arguments[i], opts);
92
- };
93
- };
94
-
95
- return;
96
- };
97
-
98
- //work out the named route names for index, show, new and edit actions
99
- var indexName = String.format("{0}_path", resource_name.pluralize() );
100
- var newName = String.format("new_{0}_path", resource_name.singularize());
101
- var showName = String.format("{0}_path", resource_name.singularize());
102
- var editName = String.format("edit_{0}_path", resource_name.singularize());
103
-
104
- //add named routes for index, new, edit and show
105
- this.name(indexName, resource_name, Ext.apply({}, {controller: resource_name, action: 'index'}));
106
- this.name(newName, resource_name + '/new', Ext.apply({}, {controller: resource_name, action: 'new' }));
107
- this.name(showName, resource_name + '/:id', Ext.apply({}, {controller: resource_name, action: 'show', conditions: {':id': "[0-9]+"}}));
108
- this.name(editName, resource_name + '/:id/edit', Ext.apply({}, {controller: resource_name, action: 'edit', conditions: {':id': "[0-9]+"}}));
109
- },
110
-
111
- /**
112
- * Given a hash containing at route segment options (e.g. {controller: 'index', action: 'welcome'}),
113
- * attempts to generate a url and redirect to it using Ext.History.add.
114
- * All arguments are passed through to this.urlFor()
115
- * @param {Object} options An object containing url segment options (such as controller and action)
116
- * @return {Boolean} True if a url was generated and redirected to
117
- */
118
- redirectTo: function() {
119
- var url = this.urlFor.apply(this, arguments);
120
- if (url) {
121
- Ext.History.add(url);
122
- return true;
123
- } else return false;
124
- },
125
-
126
- /**
127
- * Constructs and returns a config object for a Ext.History based link to a given url spec. This does not create
128
- * an Ext.Component, only a shortcut to its config. This is intended for use in quickly generating menu items
129
- * @param {Object} urlOptions A standard url generation object, e.g. {controller: 'index', action: 'welcome'}
130
- * @param {Object} linkOptions Options for the link itself, e.g. {text: 'My Link Text'}
131
- * @return {Object} a constructed config object for the given parameters
132
- */
133
- linkTo: function(urlOptions, linkOptions) {
134
- var linkOptions = linkOptions || {};
135
-
136
- var url = this.urlFor(urlOptions);
137
- if (url) {
138
- return Ext.applyIf(linkOptions, {
139
- url: url,
140
- cls: [urlOptions.controller, urlOptions.action, urlOptions.id].join("-").replace("--", "-").replace(/-$/, ""),
141
- text: this.constructDefaultLinkToName(urlOptions, linkOptions),
142
- handler: function() {Ext.History.add(url);}
143
- });
144
- } else throw new Error("No match for that url specification");
145
- },
146
-
147
- /**
148
- * Attempts to create good link name for a given object containing action and controller. Override with your own
149
- * function to create custom link names for your app
150
- * @param {Object} urlOptions An object containing at least controller and action properties
151
- * @param {Object} linkOptions An object of arbitrary options for the link, initially passed to linkTo. Not used
152
- * in default implementation but could be useful when overriding this method
153
- * @return {String} The best-guess link name for the given params.
154
- */
155
- constructDefaultLinkToName: function(urlOptions, linkOptions) {
156
- if (!urlOptions || !urlOptions.controller || !urlOptions.action) {return "";}
157
- var linkOptions = linkOptions || {};
158
-
159
- Ext.applyIf(linkOptions, {
160
- singularName: urlOptions.controller.singularize()
161
- });
162
-
163
- var actionName = urlOptions.action.titleize();
164
- if (actionName == 'Index') {
165
- return "Show " + urlOptions.controller.titleize();
166
- } else {
167
- return actionName + " " + linkOptions.singularName.titleize();
168
- }
169
- },
170
-
171
- /**
172
- * @params {String} url The url to be matched by the Router. Router will match against
173
- * all connected matchers in the order they were connected and return an object created
174
- * by parsing the url with the first matching matcher as defined using the connect() method
175
- * @returns {Object} Object of all matches to this url
176
- */
177
- recognise: function(url) {
178
- for (var i=0; i < this.mappings.length; i++) {
179
- var m = this.mappings[i];
180
- var match = m.matchesFor(url);
181
- if (match) { return match; }
182
- };
183
-
184
- return false;
185
- },
186
-
187
- /**
188
- * Takes an object of url generation options such as controller and action. Returns a generated url.
189
- * For a url to be generated, all of these options must match the requirements of at least one route definition
190
- * @param {Object/String} options An object containing url options, or a named route string.
191
- * @param {Object} namedRouteOptions If using a named route, this object is passed as additional parameters. e.g:
192
- * this.name('myRoute', 'my/custom/route/:id', {controller: 'myController', action: 'myAction'});
193
- * this.urlFor('myRoute', {id: 100}); //returns 'my/custom/route/100'
194
- * this.urlFor('myRoute', 100); //returns 'my/custom/route/100' - number argument assumed to be an ID
195
- * this.urlFor('myRoute', modelObj); //returns 'my/custom/route/100' if modelObj is a model object where modelObj.data.id = 100
196
- * @return {String} The generated url, or false if there was no match
197
- */
198
- urlFor: function(options, namedRouteOptions) {
199
- var route;
200
-
201
- //named route
202
- if (typeof(options) == 'string') {
203
- if (route = this.namedRoutes[options]) {
204
- var namedRouteOptions = namedRouteOptions || {};
205
-
206
- //normalise named route options in case we're passed an integer
207
- if (typeof(namedRouteOptions) == 'number') {
208
- namedRouteOptions = {id: namedRouteOptions};
209
- };
210
-
211
- //normalise named route options in case we're passed a model instance
212
- if (namedRouteOptions.data && namedRouteOptions.data.id) {
213
- namedRouteOptions = {id: namedRouteOptions.data.id};
214
- };
215
-
216
- return route.urlForNamed(namedRouteOptions);
217
- };
218
- }
219
- //non-named route
220
- else {
221
- for (var i=0; i < this.mappings.length; i++) {
222
- route = this.mappings[i]; var u = route.urlFor(options);
223
- if (u) { return u; }
224
- };
225
- };
226
-
227
- //there were no matches so return false
228
- return false;
229
- },
230
-
231
- /**
232
- * Immediately redirects to the specified route.
233
- * @param {String} route The route
234
- */
235
- route: function(route) {
236
- document.location.hash = route;
237
- },
238
-
239
- /**
240
- * Creates a handler for redirecting to the specified route
241
- * @param {String} route The route
242
- * @return {Function} handler A function that redirects to the route
243
- */
244
- handleRoute: function(url) {
245
- return this.route.createDelegate(this, [url]);
246
- },
247
-
248
- //experimental...
249
- withOptions: function(options, routes) {
250
- var options = options || {};
251
-
252
- var defaultScope = this;
253
- var optionScope = {};
254
-
255
- optionScope.prototype = this;
256
- Ext.apply(optionScope, {
257
- connect: function(re, additional_params) {
258
- var additional_params = additional_params || {};
259
- Ext.applyIf(additional_params, options);
260
-
261
- defaultScope.connect.call(defaultScope, re, additional_params);
262
- },
263
-
264
- name: function(routeName, re, additional_params) {
265
- var additional_params = additional_params || {};
266
- Ext.applyIf(additional_params, options);
267
-
268
- defaultScope.name.call(defaultScope, routeName, re, additional_params);
269
- }
270
- });
271
-
272
- routes.call(this, optionScope);
273
- }
274
- };
275
-
276
- /**
277
- * Basic default routes. Redefine this method inside config/routes.js
278
- */
279
- ExtMVC.router.Router.defineRoutes = function(map) {
280
- map.connect(":controller/:action");
281
- map.connect(":controller/:action/:id");
282
- };
@@ -1,94 +0,0 @@
1
- /**
2
- * @class String
3
- * Extensions to the String class
4
- **/
5
-
6
- /**
7
- * Capitalizes a string (e.g. ("some test sentence").capitalize() == "Some test sentence")
8
- * @return {String} The capitalized String
9
- */
10
- String.prototype.capitalize = function() {
11
- return this.charAt(0).toUpperCase() + this.substr(1).toLowerCase();
12
- };
13
-
14
- /**
15
- * Puts the string in Title Case (e.g. ("some test sentence").titleize() == "Some Test Sentence")
16
- * @return {String} The titleized String
17
- */
18
- String.prototype.titleize = function() {
19
- return this.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
20
- };
21
-
22
- /**
23
- * Takes any string and de-underscores and uppercases it
24
- * e.g. long_underscored_string => LongUnderscoredString
25
- */
26
- String.prototype.camelize = function() {
27
- return this.replace(/_/g, " ").titleize().replace(/ /g, "");
28
- };
29
-
30
- /**
31
- * Underscores a string (e.g. (("SomeCamelizedString").underscore() == 'some_camelized_string',
32
- * ("some normal string").underscore() == 'some_normal_string')
33
- * @return {String} The underscored string
34
- */
35
- String.prototype.underscore = function() {
36
- return this.replace(/([A-Z])/g, "_$1").toLowerCase().replace(/ /g, "_").replace(/^_/, '');
37
- };
38
-
39
- /**
40
- * Uses the Inflector to singularize itself (e.g. ("cats").singularize() == 'cat')
41
- * @return {String} The singularized version of this string
42
- */
43
- String.prototype.singularize = function() {
44
- return ExtMVC.Inflector.singularize(this);
45
- };
46
-
47
- /**
48
- * Uses the Inflector to pluralize itself (e.g. ("cat").pluralize() == 'cats')
49
- * @return {String} The pluralized version of this string
50
- */
51
- String.prototype.pluralize = function() {
52
- return ExtMVC.Inflector.pluralize(this);
53
- };
54
-
55
- /**
56
- * Attempts to humanize a name by replacing underscores with spaces. Mainly useful for Ext.Model.Base
57
- * @return {String} The humanized string
58
- */
59
- String.prototype.humanize = function() {
60
- return this.underscore().replace(/_/g, " ");
61
- };
62
-
63
- /**
64
- * Replaces instances of the strings &, >, < and " with their escaped versions
65
- * @return {String} The escaped version of the original text
66
- */
67
- String.prototype.escapeHTML = function () {
68
- return this.replace(/&/g,'&amp;').replace(/>/g,'&gt;').replace(/</g,'&lt;').replace(/"/g,'&quot;');
69
- };
70
-
71
- /**
72
- * Converts this string into a currency, prepended with the given currency symbol
73
- * @param {String} symbol The currency symbol to use (defaults to $)
74
- */
75
- String.prototype.toCurrency = function(symbol) {
76
- if (typeof(symbol) == 'undefined') {var symbol = '$';}
77
-
78
- var beforeDecimal = this.split(".")[0],
79
- afterDecimal = this.split(".")[1];
80
-
81
- var segmentCount = Math.floor(beforeDecimal.length / 3);
82
- var firstSegmentWidth = beforeDecimal.length % 3,
83
- pointerPosition = firstSegmentWidth;
84
-
85
- var segments = firstSegmentWidth == 0 ? [] : [beforeDecimal.substr(0, firstSegmentWidth)];
86
-
87
- for (var i=0; i < segmentCount; i++) {
88
- segments.push(beforeDecimal.substr(firstSegmentWidth + (i * 3), 3));
89
- };
90
-
91
- beforeDecimal = symbol + segments.join(",");
92
-
93
- return afterDecimal ? String.format("{0}.{1}", beforeDecimal, afterDecimal) : beforeDecimal;
94
- };