Skip to content

Instantly share code, notes, and snippets.

@secretfader
Created December 3, 2011 16:00
Show Gist options
  • Save secretfader/1427444 to your computer and use it in GitHub Desktop.
Save secretfader/1427444 to your computer and use it in GitHub Desktop.
Express.js View Helper
var ViewProperty = function(type, formatter) {
this.type = type;
if(typeof(formatter) === 'undefined') {
this.plain = true;
} else {
this.formatter = formatter;
}
};
ViewProperty.prototype.set = function(new_value) {
this.value = new_value;
}
ViewProperty.prototype.get = function() {
if(this.plain === true) {
return this.value;
} else {
return this.formatter(this.value);
}
}
app.dynamicHelpers({
pageTitle: function() {
return new ViewProperty('pageTitle',
function(value) {
return [ value, 'Transistor' ].join(' | ');
}
); // Needs a formatter
},
bodyClass: function() {
return new ViewProperty('bodyClass');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment