mirror of
https://github.com/Mibew/i18n.git
synced 2025-01-22 21:40:28 +03:00
Fix bug in Handlebars apply helper. Update docs
This commit is contained in:
parent
c1b633843f
commit
4102ce00f3
@ -5,5 +5,5 @@
|
|||||||
Copyright (c) 2005-2011 Mibew Messenger Community
|
Copyright (c) 2005-2011 Mibew Messenger Community
|
||||||
License: http://mibew.org/license.php
|
License: http://mibew.org/license.php
|
||||||
*/
|
*/
|
||||||
Handlebars.registerHelper("apply",function(b,a){var c=b,e=/^[0-9A-z_]+$/,a=a.split(/\s*,\s*/),d;for(d in a)if(a.hasOwnProperty(d)&&e.test(a[d])){if("function"!=typeof Handlebars.helpers[a[d]])throw Error("Unregistered helper '"+a[d]+"'!");c=Handlebars.helpers[a[d]](c)}return new Handlebars.SafeString(c)});
|
Handlebars.registerHelper("apply",function(b,a){var c=b,e=/^[0-9A-z_]+$/,a=a.split(/\s*,\s*/),d;for(d in a)if(a.hasOwnProperty(d)&&e.test(a[d])){if("function"!=typeof Handlebars.helpers[a[d]])throw Error("Unregistered helper '"+a[d]+"'!");c=Handlebars.helpers[a[d]](c).toString()}return new Handlebars.SafeString(c)});
|
||||||
Handlebars.registerHelper("formatTime",function(b){var a=new Date(1E3*b),b=a.getHours().toString(),c=a.getMinutes().toString(),a=a.getSeconds().toString();return(10<b?b:"0"+b)+":"+(10<c?c:"0"+c)+":"+(10<a?a:"0"+a)});Handlebars.registerHelper("urlReplace",function(b){return new Handlebars.SafeString(b.replace(/((?:https?|ftp):\/\/\S*)/g,'<a href="$1" target="_blank">$1</a>'))});Handlebars.registerHelper("nl2br",function(b){return new Handlebars.SafeString(b.replace(/\n/g,"<br/>"))});
|
Handlebars.registerHelper("formatTime",function(b){var a=new Date(1E3*b),b=a.getHours().toString(),c=a.getMinutes().toString(),a=a.getSeconds().toString();return(10<b?b:"0"+b)+":"+(10<c?c:"0"+c)+":"+(10<a?a:"0"+a)});Handlebars.registerHelper("urlReplace",function(b){return new Handlebars.SafeString(b.replace(/((?:https?|ftp):\/\/\S*)/g,'<a href="$1" target="_blank">$1</a>'))});Handlebars.registerHelper("nl2br",function(b){return new Handlebars.SafeString(b.replace(/\n/g,"<br/>"))});
|
@ -11,11 +11,19 @@
|
|||||||
*
|
*
|
||||||
* This helper provide an ability to apply several helpers to single Handlebars
|
* This helper provide an ability to apply several helpers to single Handlebars
|
||||||
* expression
|
* expression
|
||||||
|
*
|
||||||
|
* Example of helper usage:
|
||||||
|
* <code>
|
||||||
|
* {{apply text "emHelper, strongHelper"}}
|
||||||
|
* </code>
|
||||||
|
* In the example above helpers will apply to text one after another: first
|
||||||
|
* 'emHelper' and second 'strongHelper'.
|
||||||
*/
|
*/
|
||||||
Handlebars.registerHelper('apply', function(text, helpers) {
|
Handlebars.registerHelper('apply', function(text, helpers) {
|
||||||
var result = text;
|
var result = text;
|
||||||
var validHelperName = /^[0-9A-z_]+$/;
|
var validHelperName = /^[0-9A-z_]+$/;
|
||||||
helpers = helpers.split(/\s*,\s*/);
|
helpers = helpers.split(/\s*,\s*/);
|
||||||
|
// Apply helpers one after another
|
||||||
for (var prop in helpers) {
|
for (var prop in helpers) {
|
||||||
if (! helpers.hasOwnProperty(prop) ||
|
if (! helpers.hasOwnProperty(prop) ||
|
||||||
! validHelperName.test(helpers[prop])) {
|
! validHelperName.test(helpers[prop])) {
|
||||||
@ -26,7 +34,7 @@ Handlebars.registerHelper('apply', function(text, helpers) {
|
|||||||
"Unregistered helper '" + helpers[prop] + "'!"
|
"Unregistered helper '" + helpers[prop] + "'!"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
result = Handlebars.helpers[helpers[prop]](result);
|
result = Handlebars.helpers[helpers[prop]](result).toString();
|
||||||
}
|
}
|
||||||
return new Handlebars.SafeString(result);
|
return new Handlebars.SafeString(result);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user