Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

modifiers neeed #182

Closed
gendalf opened this Issue · 1 comment

2 participants

@gendalf

Hi
Hello. Previously, he wrote a lot of complicated patterns on the smary. How about the idea of ​​adding modifiers variables?

is my realization in utils.js
var applyModifiers = function(str) {
var modifiers = str.split('|');
var result = modifiers.shift();
for(var i=0; i<modifiers.length; i++) {
params = modifiers[i].split(':'); modifier = params.shift();
result = "_jademodifiers."+modifier+".call("+result+(params.length?','+params.join(','):'')+")";
}
return result;
}

var interpolate = exports.interpolate = function(str){
return str.replace(/(\)?([#$!]){(.*?)}/g, function(str, escape, flag, code){
if (escape) return str;
var cc = ('!' == flag ? '' : 'escape') + "(" + applyModifiers( code.replace(/\'/g, "'") ) + ")";
return "' + " + cc + " + '";
});
};

_jademodifiers is global array of functions... filed by registerModifier in jade

in template: #{somevar|truncate:20} or #{somevar|dateformat:dd.mm.yy}

is only fast realization... is not prodction code

@tj
Owner
tj commented

why not just use helper functions? #{truncate(somevar, 20)} i think it's more natural for js folk

@tj tj closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.