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

Disappearing helper contents #66

Open
nknapp opened this issue Jun 9, 2015 · 11 comments
Open

Disappearing helper contents #66

nknapp opened this issue Jun 9, 2015 · 11 comments
Labels

Comments

@nknapp
Copy link
Contributor

nknapp commented Jun 9, 2015

I just noticed that some of the entries of the comment-patterns-doc are not displayed correctly: the Mustache and Handlebars multiline-patterns are disappearing. I have cut the problem down to these two files

  • .verb.md:
This is a {%= disappearing() %} helper
  • Part of verbfile.js
verb.helper("disappearing", function() {
  return "{{! abc }}"
});

The output is not, as I would have expected:

This is a {{! abc }} helper

but

This is a  helper

(see verb-tests).
I would like to know why. Is this a bug?

@jonschlinkert
Copy link
Member

Looks like it's producing exactly what would be expected. {{! abc }} is a handlebars comment. Which is removed from the rendered result. http://handlebarsjs.com/#comments

@nknapp
Copy link
Contributor Author

nknapp commented Jun 9, 2015

But why is the helper-output treated as handlebars-template?

@jonschlinkert
Copy link
Member

try doing verb --set stripComments=false or verb stripComments=false

@jonschlinkert
Copy link
Member

https://github.com/verbose/verb/blob/master/lib/plugins/comments.js.

since lodash doesn't have any kind of comments feature, it was implemented as an extra feature. It doesn't look like I wired up the config store to be used for options on that plugin though, so the flag will need to be set every time you run verb until that's implemented. All we need to do is add something like this inside the plugin:

var stripComments = this.config.get('stripComments');

then use whatever that returns if it's not undefined

@jonschlinkert
Copy link
Member

actually I think it should be disabled by default.... I'll mark this as a bug in the meantime since it's causing unexpected results and it's not clear to the user what's happening

@nknapp
Copy link
Contributor Author

nknapp commented Jun 9, 2015

Ah, that explains it. Maybe comment-stripping should occur before parsing the template, so that helper output is not stripped.
Having comments is fine, but I think the output of helpers should not be modified.

@jonschlinkert
Copy link
Member

Maybe comment-stripping should occur before parsing the template, so that helper output is not stripped.

probably, let's give that a shot. I don't think there was a specific reason I chose postRender, I just couldn't think of a reason not to at the time...

but I think the output of helpers should not be modified.

completely agree, this is why I marked it a bug. I would have never occurred to me that someone would create a lodash helper to generate handlebars comments lol. don't take that as a slam though! I'm all for using whatever techniques are necessary to get a job done!

@nknapp
Copy link
Contributor Author

nknapp commented Jun 10, 2015

Maybe (haven't tried it yet!), it is possible to make comments in lodash-templates like
{%=''/* this is a comment */ %} or something like that.

@tunnckoCore
Copy link

I can't understand what is the logic. In both sides there's no logic for me - in template engine (no matter what it is) it would be skipped, also in verb. Why someone would want to preserve template comment, when template engine do nothing with them? But okey if they are preserved, where you will use them, for what, when and why? I mean.. if you want to use them just for hinting you always can use html comments and it is guaranteed that they won't be displayed, then the job won't be related to verb and template engine.

I dont know, maybe missing the point. I think it's not a bug.

@tunnckoCore
Copy link

PS: And okey, if you disable "stripping comments" they will stay after verb finishes rendering. So.. I guess you want to run one more rendering (with another template engine) over that output.. why? why not use verb, it is powerful and more than generator, more than documentator and etc.

@nknapp
Copy link
Contributor Author

nknapp commented Jun 14, 2015

@tunnckoCore My problem is that the documentation of comment-patterns concerning Handlebars templates is wrong. The multilineComment-part should be

multiLineComment: [{
    start: '<!--',
    middle: '',
    end: '-->'
  }, {
    start: '{{!--',
    middle: '',
    end: '--}}',
    apidoc: true
  }, {
    start: '{{!',
    middle: '',
    end: '}}'
  }]

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