Skip to content

Instantly share code, notes, and snippets.

@brianjmiller
Created September 28, 2011 19:39
Show Gist options
  • Save brianjmiller/1249009 to your computer and use it in GitHub Desktop.
Save brianjmiller/1249009 to your computer and use it in GitHub Desktop.
Additional MakeNode _templateHandlers
Y.MakeNode.prototype._templateHandlers["@@"] = function (args) {
args = this._parseMakeNodeArgs(args);
if (args.length !== 2 || args[0] === "" || args[1] === "") {
return;
}
var av = this.get(args[0]);
if (! av) {
return;
}
return av.get(args[1]);
};
Y.MakeNode.prototype._templateHandlers["@p"] = function (args) {
args = this._parseMakeNodeArgs(args);
if (args.length !== 2 || args[0] === "" || args[1] === "") {
return;
}
var av = this.get(args[0]);
if (! av) {
return;
}
return av[args[1]];
};
Y.MakeNode.prototype._templateHandlers["p@"] = function (args) {
args = this._parseMakeNodeArgs(args);
if (args.length !== 2 || args[0] === "" || args[1] === "") {
return;
}
var pv = this[args[0]];
if (! pv) {
return;
}
return pv.get(args[1]);
};
@Satyam
Copy link

Satyam commented Sep 29, 2011

You don't actually need to call _parsemakeNodeArgs for this one. Just splitting args on whitespace should do. The parser is useful when you want to allow for strings containing whitespace but, presumably, the arguments here would be proper identifiers and do not need to be quoted.

Y.MakeNode.prototype._templateHandlers["p@"] = function (args) {
    args = args.split(' ');
    var value = this[args[0]];
    if (value) {
          return value.get(args[1]);
   }
};  

this allows you to call it like this: {p@ prop att} instead of {p@ "prop" "att"}, which is easier, unless you have identifiers that need quoting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment