-
-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
request: transforms #12
Comments
I think adding Template.prototype.transform = function (name, fn /*, ... */) {
var args = slice(arguments, 2);
var context = {
data: this.cache.data,
name: name
};
this._.transforms[name] = fn;
return fn.apply(context, args);
}; Now the user can make the transform async just by doing: var yearTransform = function (next) {
if (!this.data.year) {
this.data.year = new Date().getFullYear();
}
next(null, this.data);
};
template.transform('year', yearTransform, function (err, data) {
// validate data or something
}); That is unless you're expecting to do something else with the |
no this is good, it's similar to how you did the transforms on your example project isn't it? |
Yeah, this was similar, but I'm not really using I think if we updated transforms to be more like the binding in helpers, then it'll provide more flexibility and the arguments will make more sense: Template.prototype.transform = function (name, fn /*, ... */) {
var args = slice(arguments, 2);
var context = {
app: this,
data: this.cache.data,
options: this.options,
name: name
};
this._.transforms[name] = fn;
return fn.apply(context, args);
}; |
how are you using that data in helpers? just |
I use it with the var foo = this.app.get('foo'); |
I think we should consider changing transforms to expose
cache.data
as adata
parameter by default.Example
Let's say you want to add a
year
property to the context. Currently it might look like this:With the suggested changes, it might look more like this:
and possibly use an async signature like middleware, eg.
Thoughts @doowb?
The text was updated successfully, but these errors were encountered: