> https://github.com/jaredwy/jsshaper/commit/2edc9b18630088e34ed0f482575adb592fc782f6#src/shaper.js
>
> Here is a small proof of concept for one thing i was looking at. It is
> no way final, just threw it together for the purpose of this example.
Welcome to the group and thanks for writing up your proposal.
> It allows me now to write code like
> if(Shaper.match(IdTemplate,node,function(template,node) {
> return node.value != "document";
> },true))
Currently Shaper.match takes two nodes (the template and the source) and returns whether they are the same (they match) or not. Optionally, it supports wildcard-matching using $ and $$ in the template. It's used to match source declaratively instead of manually inspecting node properties (.type, .value) recursively.
To really understand the use-case you're proposing I'd like to see the template and an example of the source. Seems that you're proposing a way of conditionally matching wildcards? I can see how that could be useful.
I'm not sure about the callback API, though. The template could contain many (conditional) wildcards and it isn't certain that you always want to apply the same extra conditional test to all of them.
Instead, Shaper.match could simply return an array with the nodes matching the wildcards (where a $$ identifier would result in a nested array). This result would still be truthy so the simple boolean usage of Shaper.match would remain the same, but more advanced usages would be permitted easily. That API is also more consistent with Shaper.replace.
> Part two of the proposed change is to change the match character from
> "$" as i discovered this makes it impossible to write a plugin that
> turns
>
> var myScope = (function($) { })($); into something that does var
> myScope = (function($) { })(jQuery);
Absolutely. Both Shaper.match and Shaper.replace should be able to take an optional argument specifying the custom identifiers. Default is that $ matches any node (one), $$ matches a list of nodes.
/Olov
3 maj 2011 kl. 19.59 skrev Jared W:
Welcome to the group and thanks for writing up your proposal.
> https://github.com/jaredwy/jsshaper/commit/2edc9b18630088e34ed0f482575adb592fc782f6#src/shaper.js
>
> Here is a small proof of concept for one thing i was looking at. It is
> no way final, just threw it together for the purpose of this example.
Currently Shaper.match takes two nodes (the template and the source) and returns whether they are the same (they match) or not. Optionally, it supports wildcard-matching using $ and $$ in the template. It's used to match source declaratively instead of manually inspecting node properties (.type, .value) recursively.
> It allows me now to write code like
> if(Shaper.match(IdTemplate,node,function(template,node) {
> return node.value != "document";
> },true))
To really understand the use-case you're proposing I'd like to see the template and an example of the source. Seems that you're proposing a way of conditionally matching wildcards? I can see how that could be useful.
I'm not sure about the callback API, though. The template could contain many (conditional) wildcards and it isn't certain that you always want to apply the same extra conditional test to all of them.
Instead, Shaper.match could simply return an array with the nodes matching the wildcards (where a $$ identifier would result in a nested array). This result would still be truthy so the simple boolean usage of Shaper.match would remain the same, but more advanced usages would be permitted easily. That API is also more consistent with Shaper.replace.
Absolutely. Both Shaper.match and Shaper.replace should be able to take an optional argument specifying the custom identifiers. Default is that $ matches any node (one), $$ matches a list of nodes.
> Part two of the proposed change is to change the match character from
> "$" as i discovered this makes it impossible to write a plugin that
> turns
>
> var myScope = (function($) { })($); into something that does var
> myScope = (function($) { })(jQuery);
/Olov
Basically i am doing some manipulation of some code that is rather dom heavy. I am needing to match "$.getElementById" although i do not want to match if it is querying from the document just on a element.
So currently $ will match a.getElementById and document.getElementById, ideally i would like an easy way to do this inside jsshaper. Your array idea would work very well as well. Will take a look at implementing that.
Absolutely. Both Shaper.match and Shaper.replace should be able to take an optional argument specifying the custom identifiers. Default is that $ matches any node (one), $$ matches a list of nodes.Yup but if that node is named $ we run into an issue heh. So thinking of either changing the wildcard or having a way to optionally turn of wildcard patterns, although you then run into an issue if you want to do something like $/*wildcard*/.something($/*this is a reference to jquery*/