Hello all.
I've just done the AS3 port of the mustache code, and i've got a question
about how the lambda functions should work.
Right now, when it does its thing, the function that gets called gets the
"raw" template text, as described in the man pages.
What i'm not sure of is what happens _after_ that. Lets say you leave the
text, perhaps you do some thing else to it, leaving it alone.
In the AS3 port, any {{vars}} in the text will text replaces (assuming
there is a context for them). ie. if the lambda doesn't do something to
the {{}} in the text it gets given, the engine still gets a chance to do
its thing later on in the process.
Is this how it is supposed to work? I'm not a ruby programmer, so i was
having a hard time groking the code there to figure this out.
Any pointers or suggestions are welcome!
j
Jos Yule
Digital Hyakugei
Processing the raw text should be up to the lambda. If the lambda
returns a string with {{mustaches}}, your library should *not* process
it. The lambda should explicitly process the text.
As a result, you should try to make it easy for users to process the
text if they need to.
Chris
On May 10, 2010, at 11:15 AM, Jos Yule <jos@theorganization.net> wrote:
> Hello all.
>
> I've just done the AS3 port of the mustache code, and i've got a
> question about how the lambda functions should work.
>
> Right now, when it does its thing, the function that gets called
> gets the "raw" template text, as described in the man pages.
>
> What i'm not sure of is what happens _after_ that. Lets say you
> leave the text, perhaps you do some thing else to it, leaving it
> alone.
>
> In the AS3 port, any {{vars}} in the text will text replaces
> (assuming there is a context for them). ie. if the lambda doesn't do
> something to the {{}} in the text it gets given, the engine still
> gets a chance to do its thing later on in the process.
>
> Is this how it is supposed to work? I'm not a ruby programmer, so i
> was having a hard time groking the code there to figure this out.
>
> Any pointers or suggestions are welcome!
>
> j
>
>
> Jos Yule
> Digital Hyakugei
>
>
>
>
Hummm. The way the code is working now, the lambda "pass" happens before
any other passes over the text, obviously so it can get the raw text, so
i'm not sure how to keep the text "unprocessed" if the lambda doesn't do
anything to it, as later passes process the {{}} tags...
Does the Ruby one "pull" the lamdba'ed text out of the flow, so the main
parser doesn't see it? ie. remove all {{#name}}text{{/name}} bits?
Any suggestions or pointers on how this works would be appreciated.
j
On 2010-05-10, at 16:19 , Chris Wanstrath wrote:
> Processing the raw text should be up to the lambda. If the lambda
> returns a string with {{mustaches}}, your library should *not* process
> it. The lambda should explicitly process the text.
>
> As a result, you should try to make it easy for users to process the
> text if they need to.
>
> Chris
>
> On May 10, 2010, at 11:15 AM, Jos Yule <jos@theorganization.net> wrote:
>
>> Hello all.
>>
>> I've just done the AS3 port of the mustache code, and i've got a
>> question about how the lambda functions should work.
>>
>> Right now, when it does its thing, the function that gets called
>> gets the "raw" template text, as described in the man pages.
>>
>> What i'm not sure of is what happens _after_ that. Lets say you
>> leave the text, perhaps you do some thing else to it, leaving it
>> alone.
>>
>> In the AS3 port, any {{vars}} in the text will text replaces
>> (assuming there is a context for them). ie. if the lambda doesn't do
>> something to the {{}} in the text it gets given, the engine still
>> gets a chance to do its thing later on in the process.
>>
>> Is this how it is supposed to work? I'm not a ruby programmer, so i
>> was having a hard time groking the code there to figure this out.
>>
>> Any pointers or suggestions are welcome!
>>
>> j
>>
>>
>> Jos Yule
>> Digital Hyakugei
>>
>>
>>
>>
Jos Yule
Digital Hyakugei
On Mon, May 10, 2010 at 6:27 PM, Jos Yule <jos@theorganization.net> wrote: > Hummm. The way the code is working now, the lambda "pass" happens before any other passes over the text, obviously so it can get the raw text, so i'm not sure how to keep the text "unprocessed" if the lambda doesn't do anything to it, as later passes process the {{}} tags... Does mustache.js have this problem too, then? Sounds like it. > Does the Ruby one "pull" the lamdba'ed text out of the flow, so the main parser doesn't see it? ie. remove all {{#name}}text{{/name}} bits? The Ruby parser uses a string scanner, so it only makes one pass and doesn't backtrack. There's a built in Ruby library for doing string scanning so it's not that difficult for us. You could put in placeholders, but doing a parser-type thing (everything in one pass) might be the best solution. Sorry!
Hurm.
Yes, the .js one is similarly out of spec. i'd assume. It also doesn't do
partials very well. At least, i had to do some work to get it working for
the AS3 version.
Right now the tool goes through a number of "passes" recursively, so
that's where my problem lies.
I could re-code it to be single pass, but i don't have the time, or
honestly, inclination, as it does what i need it to do for right now.
But i will file a bug report so i can always come back to it to try to get
it spec compliant.
Thanks for the hints and pointers!
Is there a standard set of templates/contexts/tests which we could use to
ensure compliance with the spec? Not litteral tests, but a set of example
templates, with example contexts (in some psudo-code) and output, so we
can be sure that when we port we are within spec?
ex:
Test One:
template: "{{simpleVar}}"
context: Object{ simpleVar:"Hello World"}
partials: Object{}
output: "Hello World"
Test Two:
template: "{{#function}}This is a lambda test with embedded
{{variable}}{{/function}}"
context: Object{ function:function() { return function(text){return text}} }
partials:Object{}
output: "This is a lambda test with embedded {{variable}}"
What do you think? Can we cover the requirements with something like this?
I know it would help me.
Thanks
jos
On 2010-05-13, at 13:28 , Chris Wanstrath wrote:
> On Mon, May 10, 2010 at 6:27 PM, Jos Yule <jos@theorganization.net> wrote:
>
>> Hummm. The way the code is working now, the lambda "pass" happens
before any other passes over the text, obviously so it can get the raw
text, so i'm not sure how to keep the text "unprocessed" if the lambda
doesn't do anything to it, as later passes process the {{}} tags...
>
> Does mustache.js have this problem too, then? Sounds like it.
>
>> Does the Ruby one "pull" the lamdba'ed text out of the flow, so the
main parser doesn't see it? ie. remove all {{#name}}text{{/name}} bits?
>
> The Ruby parser uses a string scanner, so it only makes one pass and
> doesn't backtrack. There's a built in Ruby library for doing string
> scanning so it's not that difficult for us.
>
> You could put in placeholders, but doing a parser-type thing
> (everything in one pass) might be the best solution. Sorry!
Jos Yule
Digital Hyakugei
On Thu, May 13, 2010 at 10:46 AM, Jos Yule <jos@theorganization.net> wrote: > I could re-code it to be single pass, but i don't have the time, or honestly, inclination, as it does what i need it to do for right now. Okay cool. I would just list which features it does and does not support. People will understand, and if they want the feature they'll add it. > Is there a standard set of templates/contexts/tests which we could use to ensure compliance with the spec? Not litteral tests, but a set of example templates, with example contexts (in some psudo-code) and output, so we can be sure that when we port we are within spec? Not yet, but I would absolutely like to get this done before Mustache 1.0 is released.