Left: | ||
Right: |
OLD | NEW |
---|---|
1 /* | 1 /* |
2 This file is part of the Juju GUI, which lets users view and manage Juju | 2 This file is part of the Juju GUI, which lets users view and manage Juju |
3 environments within a graphical interface (https://launchpad.net/juju-gui). | 3 environments within a graphical interface (https://launchpad.net/juju-gui). |
4 Copyright (C) 2012-2013 Canonical Ltd. | 4 Copyright (C) 2012-2013 Canonical Ltd. |
5 | 5 |
6 This program is free software: you can redistribute it and/or modify it under | 6 This program is free software: you can redistribute it and/or modify it under |
7 the terms of the GNU Affero General Public License version 3, as published by | 7 the terms of the GNU Affero General Public License version 3, as published by |
8 the Free Software Foundation. | 8 the Free Software Foundation. |
9 | 9 |
10 This program is distributed in the hope that it will be useful, but WITHOUT | 10 This program is distributed in the hope that it will be useful, but WITHOUT |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
254 var l = timestrings, | 254 var l = timestrings, |
255 prefix = l.prefixAgo, | 255 prefix = l.prefixAgo, |
256 suffix = l.suffixAgo, | 256 suffix = l.suffixAgo, |
257 distanceMillis = Y.Lang.now() - t, | 257 distanceMillis = Y.Lang.now() - t, |
258 seconds = Math.abs(distanceMillis) / 1000, | 258 seconds = Math.abs(distanceMillis) / 1000, |
259 minutes = seconds / 60, | 259 minutes = seconds / 60, |
260 hours = minutes / 60, | 260 hours = minutes / 60, |
261 days = hours / 24, | 261 days = hours / 24, |
262 years = days / 365; | 262 years = days / 365; |
263 | 263 |
264 /** | 264 /* |
265 Given a number and a way to convert the number to a string that is a | 265 Given a number and a way to convert the number to a string that is a |
266 template or a function producing a template string, return the template | 266 template or a function producing a template string, return the template |
267 substituted with the number. | 267 substituted with the number. |
268 | 268 |
269 Internal helper function to humanizeTimestamp, intentionally not | 269 Internal helper function to humanizeTimestamp, intentionally not |
270 formatted to be included in exported docs. | 270 formatted to be included in exported docs. |
271 */ | 271 */ |
272 function substitute(stringOrFunction, number) { | 272 function substitute(stringOrFunction, number) { |
273 var string = Y.Lang.isFunction(stringOrFunction) ? | 273 var string = Y.Lang.isFunction(stringOrFunction) ? |
274 stringOrFunction(number, distanceMillis) : stringOrFunction, | 274 stringOrFunction(number, distanceMillis) : stringOrFunction, |
(...skipping 928 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1203 } | 1203 } |
1204 return ret; | 1204 return ret; |
1205 }); | 1205 }); |
1206 | 1206 |
1207 Y.Handlebars.registerHelper('markdown', function(text) { | 1207 Y.Handlebars.registerHelper('markdown', function(text) { |
1208 if (!text || text === undefined) {return '';} | 1208 if (!text || text === undefined) {return '';} |
1209 return new Y.Handlebars.SafeString( | 1209 return new Y.Handlebars.SafeString( |
1210 Y.Markdown.toHTML(text)); | 1210 Y.Markdown.toHTML(text)); |
1211 }); | 1211 }); |
1212 | 1212 |
1213 /** | 1213 /* |
1214 * Generate a landscape badge using a partial internally. | 1214 * Generate a landscape badge using a partial internally. |
1215 */ | 1215 */ |
1216 Y.Handlebars.registerHelper('landscapeBadge', function( | 1216 Y.Handlebars.registerHelper('landscapeBadge', function( |
1217 landscape, model, intent, hint) { | 1217 landscape, model, intent, hint) { |
1218 if (!landscape) { | 1218 if (!landscape) { |
1219 return ''; | 1219 return ''; |
1220 } | 1220 } |
1221 var output = ''; | 1221 var output = ''; |
1222 var badge = landscape.getLandscapeBadge(model, intent, hint); | 1222 var badge = landscape.getLandscapeBadge(model, intent, hint); |
1223 | 1223 |
(...skipping 23 matching lines...) Expand all Loading... | |
1247 res = res + options.fn({ | 1247 res = res + options.fn({ |
1248 key: key, | 1248 key: key, |
1249 value: object[key] | 1249 value: object[key] |
1250 }); | 1250 }); |
1251 }); | 1251 }); |
1252 } | 1252 } |
1253 return res; | 1253 return res; |
1254 }); | 1254 }); |
1255 | 1255 |
1256 | 1256 |
1257 /** | 1257 /* |
1258 If built around checking if x == y. | 1258 If built around checking if x == y. |
1259 Supports an inverse so that we can use an else clause. | 1259 Supports an inverse so that we can use an else clause. |
jeff.pihach
2013/06/05 19:53:22
I wonder if there is a proper way to document thes
benji
2013/06/05 20:01:04
I was wondering the same thing but I didn't find a
| |
1260 | |
1261 */ | 1260 */ |
1262 Y.Handlebars.registerHelper('if_eq', function(x, y, options) { | 1261 Y.Handlebars.registerHelper('if_eq', function(x, y, options) { |
1263 if (x === y) { | 1262 if (x === y) { |
1264 return options.fn(this); | 1263 return options.fn(this); |
1265 } else { | 1264 } else { |
1266 return options.inverse(this); | 1265 return options.inverse(this); |
1267 } | 1266 } |
1268 }); | 1267 }); |
1269 | 1268 |
1270 /** | 1269 /* |
1271 * pluralize | 1270 * pluralize |
1272 * | 1271 * |
1273 * pluralize is a handlebar helper that handles pluralization of strings. | 1272 * pluralize is a handlebar helper that handles pluralization of strings. |
1274 * The requirement for pluralization is based on the passed in object, | 1273 * The requirement for pluralization is based on the passed in object, |
1275 * which can be number, array, or object. If a number, it is directly | 1274 * which can be number, array, or object. If a number, it is directly |
1276 * checked to see if pluralization is needed. Arrays and objects are | 1275 * checked to see if pluralization is needed. Arrays and objects are |
1277 * checked for length or size attributes, which are then used. | 1276 * checked for length or size attributes, which are then used. |
1278 * | 1277 * |
1279 * By default, if pluralization is needed, an 's' is appended to the | 1278 * By default, if pluralization is needed, an 's' is appended to the |
1280 * string. This handles the regular case (e.g. cat => cats). Irregular | 1279 * string. This handles the regular case (e.g. cat => cats). Irregular |
(...skipping 16 matching lines...) Expand all Loading... | |
1297 if (typeof(plural_word) === 'string') { | 1296 if (typeof(plural_word) === 'string') { |
1298 return plural_word; | 1297 return plural_word; |
1299 } else { | 1298 } else { |
1300 return word + 's'; | 1299 return word + 's'; |
1301 } | 1300 } |
1302 } else { | 1301 } else { |
1303 return word; | 1302 return word; |
1304 } | 1303 } |
1305 }); | 1304 }); |
1306 | 1305 |
1307 /** | 1306 /* |
1308 * Truncate helper to keep text sizes to a specified limit. | 1307 * Truncate helper to keep text sizes to a specified limit. |
1309 * | 1308 * |
1310 * {{truncate field 100}} | 1309 * {{truncate field 100}} |
1311 * | 1310 * |
1312 */ | 1311 */ |
1313 Y.Handlebars.registerHelper('truncate', function(string, length) { | 1312 Y.Handlebars.registerHelper('truncate', function(string, length) { |
1314 if (string && string.length > length) { | 1313 if (string && string.length > length) { |
1315 return Y.Lang.trimRight(string.substring(0, length)) + '...'; | 1314 return Y.Lang.trimRight(string.substring(0, length)) + '...'; |
1316 } | 1315 } |
1317 else { | 1316 else { |
1318 return string; | 1317 return string; |
1319 } | 1318 } |
1320 }); | 1319 }); |
1321 | 1320 |
1322 /** | 1321 /* |
1323 * Extension for views to provide an apiFailure method. | 1322 * Extension for views to provide an apiFailure method. |
1324 * | 1323 * |
1325 * @class apiFailure | 1324 * @class apiFailure |
1326 */ | 1325 */ |
1327 utils.apiFailingView = function() { | 1326 utils.apiFailingView = function() { |
1328 this._initAPIFailingView(); | 1327 this._initAPIFailingView(); |
1329 }; | 1328 }; |
1330 utils.apiFailingView.prototype = { | 1329 utils.apiFailingView.prototype = { |
1331 /** | 1330 /** |
1332 * Constructor | 1331 * Constructor |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1373 'base-build', | 1372 'base-build', |
1374 'handlebars', | 1373 'handlebars', |
1375 'node', | 1374 'node', |
1376 'view', | 1375 'view', |
1377 'panel', | 1376 'panel', |
1378 'json-stringify', | 1377 'json-stringify', |
1379 'gallery-markdown', | 1378 'gallery-markdown', |
1380 'datatype-date-format' | 1379 'datatype-date-format' |
1381 ] | 1380 ] |
1382 }); | 1381 }); |
OLD | NEW |