Skip to content
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

Mustache specs - lambda compliance #304

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

danielfagerstrom
Copy link
Contributor

Fixed most of the failing lambda tests from the Mustache spec from my Mustache spec pull request.

The spec says that for a function that is returned in a section or an interpolation:

  1. When used as the data value for an Interpolation tag, the lambda MUST be
    treatable as an arity 0 function, and invoked as such. The returned value
    MUST be rendered against the default delimiters, then interpolated in place
    of the lambda.
  2. When used as the data value for a Section tag, the lambda MUST be treatable
    as an arity 1 function, and invoked as such (passing a String containing the
    unprocessed section contents). The returned value MUST be rendered against
    the current delimiters, then interpolated in place of the section.

In current mustache.js the return value from a function in a interpolation or section is not interpolated so I implemented that.

For the section functions this breaks one of the current tests so I updated that one.

The test for "Section - Alternate Delimiters - Lambdas used for sections should parse with the current delimiters." still fails, I couldn't find any reasonably simple way to fix that.

…bda should be interpolated. This breaks one of the current tests of lambdas (higher order sections), as it asumes that the result is not interpolated. I updated the test so that it pass.
@mjackson
Copy link
Contributor

mjackson commented Apr 4, 2013

@danielfagerstrom I've merged the first few commits of this pull request already. Would you please rework this request to only include the last two commits (i.e. the ones that have to do with lambda compliance)? Thanks!

@eliOcs
Copy link

eliOcs commented Apr 30, 2013

In version 0.7.2 lambdas don't work:

var Mustache = require("mustache");

Mustache.render("{{#lambda}}Hello{{/lambda}}", {
    lambda: function (hello) {
        return hello + " world!"
    }
}):

returns:

"Hello"

Expected

"Hello world!"

Are they going to be included soon?

@busticated
Copy link
Contributor

hmm... perhaps related?.. i tried doing exactly this --> mustache/spec#54 (comment)

specifically:

view model:

{
    items: [
        { url: 'Some URL',      html: function() { return '{{>image}}'; } },
        { content: 'Some text', html: function() { return '{{>text}}'; } },
    ]
}

base.mustache

{{#items}}
    {{{html}}}
{{/items}}

text.mustache

<p>{{content}}</p>

image.mustache

">
<p><img src="{{url}}"/></p>

expected output:

<p><img src="Some URL"/></p>
<p>Some text</p>

actual output:

{{>image}} {{>text}}

JSFiddle Example

@andrewnicols
Copy link

I've encountered this recently. What's the current state of play if I were to take on the remaining changes?

Relevant part of the spec: https://github.com/mustache/spec/blob/master/specs/~lambdas.yml#L29

@MiniHeyd
Copy link

Is there any update on this? I am still seeing this issue with lambda's where {{ >second }} is printing Instead of the partial it is supposed to render.

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

Successfully merging this pull request may close these issues.

None yet

7 participants