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

(error) Changes for Mustache compatibility & latest version of therubyracer #256

Closed
wants to merge 5 commits into from

Conversation

bensummers
Copy link

Mustache compatibility

I'm in the process of changing a project to use Handlebars templates, and found a couple of differences between the way that Handlebars and Mustache work. Two of the commits in this pull request change Handlebars to be compatible with:

  • Allow : in ID names, which allows partials with : to work. We use this for 'namespacing' partials.
  • If there exists a property matching the name of the partial and the value is an object, move the context to that object

Getting going

I also had problems getting the tests to run in the first place. There are two more commits to fix the developer documentation and add the this argument to procs as required by therubyracer.

Jison problem?

There are three test failures which I couldn't fix, which look like this:

  1. Parser raises if there's a Parse error
    Failure/Error: lambda { ast_for("{{foo}") }.should raise_error(V8::JSError, /Parse error on line 1/)
    expected V8::JSError with message matching /Parse error on line 1/, got #<V8::JSError: Cannot read property '0' of undefined>

    ./spec/parser_spec.rb:249

This may be a jison issue; it generates this code:

    if (typeof action === "undefined" || !action.length || !action[0]) {
        var errStr = "";
    }
    if (action[0] instanceof Array && action.length > 1) {
        throw new Error("Parse Error: multiple actions possible at state: " + state + ", token: " + symbol);
    }

which, if action === undefined, will then immediately evaluate action[0], which will throw this error.

I'm using jison 0.3.8.

therubyracer requires a this argument as the first argument of each
proc called from the JS side.
Mustache.js allows : in IDs. This allows partial names to contain the :
character, the convention for namespaces.
If there exists a property matching the name of the partial and the
value is an object, move the context to that object
Make sure that none of the Handlebars objects are modified when parsing
a template by using new objects with prototypes instead.
@bensummers
Copy link
Author

Incorrectly made pull request with commits from the head. Closing in favour of new pull request #257 which has the correct commit range.

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

Successfully merging this pull request may close these issues.

1 participant