twitter / hogan.js

A compiler for the Mustache templating language
http://twitter.github.io/hogan.js
Apache License 2.0
5.14k stars 431 forks source link

adding support for leading dot. adding use of prototypical inheritance for Stack's substitutions and partials #237

Closed shYkiSto closed 6 months ago

shYkiSto commented 8 years ago

There was new feature proposed which is in line with the current spec(which isn't updating for years :() here: https://github.com/mustache/spec/issues/52

It's been implemented in some of the Mustache implementations already and is backward compatible. It should allow us avoid issues when some key is missing in top context and engine is looking for that variable in parent contexts.

shYkiSto commented 8 years ago

Fixed an issue with substitutions when one overrides any other substitutions used for the same partial template during multi level inheritance(in other words all that happening inside other partial template).

Here's the test sample:

{{!subPartial.mustache}}
Haloha! {{$replace}}replace me{{/replace}}
{{!partial.mustache}}
{{<subPartial}}
    {{$replace}}removed1{{/replace}}
{{/subPartial}}
{{<subPartial}}
    {{$replace}}removed2{{/replace}}
{{/subPartial}}
{{!main.mustache}}
{{>partial}}

Without the fix it renders:

Haloha! removed1 Haloha! removed1

When second replacement should be removed2.

The fix is that the stackSubs & stackPartials are updated with prototypical inheritance. So one partial doesn't affect others. And instead just inherits all the information from the parent.

shYkiSto commented 8 years ago

Can split up my work into 2 separated PR.. but not sure if they're going to be ever accepted...

CLAassistant commented 5 years ago

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


fedarovs seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.