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

An inline partial should not be indented #715

Closed
hail2u opened this issue Aug 27, 2019 · 6 comments
Closed

An inline partial should not be indented #715

hail2u opened this issue Aug 27, 2019 · 6 comments
Labels

Comments

@hail2u
Copy link

hail2u commented Aug 27, 2019

The content of an inline partial is indented in v3.0.2 (of course not in v3.0.1). People does not want these extra white spaces in an HTML file.

test.json:

{}

test.mustache:

    <div>{{> partial}}</div>

partial.mustache:

This is a partial.

Run:

$ mustache -p partial.mustache test.json test.mustache
    <div>    This is a partial.</div>
@phillipj
Copy link
Collaborator

Thanks for reporting!

I for sure agree your example looks both weird and unexpected. Without digging deep into how this could be solved in this project, I'm starting to get curious how other mustache implementations (java, PHP etc) handles indentation of partials.

The expected (or shall we say sensible) output of your example would be great to have as an unit test inside ./test/partial-test.js.

@phillipj
Copy link
Collaborator

@yotammadem you got any thoughts on this by any chance?

@yotammadem
Copy link
Contributor

I will take a look at this soon. Strange that the partials spec does not test it

@yotammadem
Copy link
Contributor

This is strange..
When I tried to reproduce this with a unit test:

    it('Inline partials should not be indented', function () {
      var template = '"    <div>{{> partial}}</div>"';
      var data = {};
      var partials = {'partial':'This is a partial.'};
      var expected = '"    <div>This is a partial.</div>"';
      var renderResult = Mustache.render(template, data, partials);
      assert.equal(renderResult, expected);
    });

The unit test passed..
I will try with the command line

@yotammadem
Copy link
Contributor

Ok, it was my mistake, when I ran this test, it failed:

it('Inline partials should not be indented', function () {
      var template = '    <div>{{> partial}}</div>';
      var data = {};
      var partials = {'partial':'This is a partial.'};
      var expected = '    <div>This is a partial.</div>';
      var renderResult = Mustache.render(template, data, partials);
      assert.equal(renderResult, expected);
    });

@yotammadem
Copy link
Contributor

@phillipj Take a look at: #716

@phillipj phillipj added the Bug label Sep 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants