-
Notifications
You must be signed in to change notification settings - Fork 71
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
Possible Improvement to Comments #8
Comments
It seems like a change like this would make Comment tags mirror Set Delimiter tags in implementation. I presently dislike that we have to deal with special cases like this, though I can see the value in being able to comment out tags, and I'd rather not try to solve the delimiter counting problem. I've thrown the question out to a wider pool, but I think I'm +1 to including this in v2.0.0 of the spec. |
Hmm... I'm down for a +1 here. Makes sense. |
I'm -1, for the following reasons:
Yet, the problem is real. It's difficult, in today's mustache syntax, to quickly comment out a whole bunch of template lines. Since the problem is real, it's not new. And solution has already been found by other languages. Namely : the single-line comment, introduced by // in C++ and javascript, # in shell and ruby, etc. This is the direction we should aim at. |
Groue, can you elaborate on why this would have a negative performance impact? The change can still be matched with a regular expression:
And just to clarify this would not allow nesting of comments. The following would still be bad:
Which actually resembles the parsing behaviour of the following C#, C++, and C code perfectly:
I hope that this clarifies the original suggestion a bit. |
I admit I missed the exclamation mark in your proposal for a new comment closing !}} tag, and that there is no request for nested comments in your initial writing. My apologies. But now, I don't get how you're planning to keep compatibility, if you change the comment closing tag : |
I think what I really meant to say with that line about backwards compatibility is that the existing Mustache code is forwards compatible with this change. new-style comments (assuming they are not commenting out Mustache code) would be acceptable old-style comments since older parsers would treat the last ! as just another character. But you are right, it seems this suggestion loses backwards compatibility in its present form. I can think of ways of fudging a parser to work correctly with both syntaxes, but they all have a hack-ish taste (balanced parenthesis matching, longest match, etc). Another token for this construct perhaps? |
Keeping my -1 until a solid proposal has been written, then. Also, let's keep in mind that :
|
Also, agree that it's not that big of an issue. If the main use case is just to be able to quickly comment out sections of mustache templates... well... maybe a vim plugin is the way to go? |
Since there seems to be some confusion, let's refocus a bit:
There has been a concrete proposal made: the This change offers a tangible benefit: comment tags cannot enclose other mustache tags, which is an inconvenience. |
👍 Many people expect this to work, but it does not. Comments are already a special case so I think the closing bang is a-ok. |
Should we keep on discussing the alteration of the comment syntax, I would keep investigating the one-line comment, since it would solve both the "comment tags cannot enclose other mustache tags" inconvenience, and the nested comments that some other users will eventually ask for, too.
Now in order to comment a bunch of lines, with tags, with comments, anything, we just have to prepend each line with (if |
@groue I'm curious about how you're using Mustache. I see you've written an Obj-C implementation — what sort of templates are you Mustaching? I ask because to me the single line comment feels very un-HTMLy, where all carets are balanced. But maybe that's too narrow a perspective. |
@defunkt: I'm using it, as many, to render HTML. iOS ships with a remarkable UIWebView, but no templating tool for rendering the HTML. I developed GRMustache for this only purpose, and I'm quite glad you did whole the hard work of setting up the {{mustache}} core. I was quite happy to use its advanced features, namely partials and lambda sections. Some users of GRMustache came to it because they were already there, ready to be unleashed. Mustache, with its default HTML escaping, looks like it is a HTML-oriented templating language. I think this is only a convenience, a safe default, but certainly not something which should taint mustache forever. Where, in its core concepts of tags and their relationship with the rendered data, would lie any HTML-focused property? I may well one day generate some Python with it, or some PDF, and maybe not with my Obj-C implementation. I mean, who knows? Now, on the comments syntax discussion. @thegrandpoobah asked for comments that would enclose other mustache tags. This is feature request [1]. In other languages, it's quite common that people ask for nestable comments. This is feature request [2]. In the language history I'm aware of, [1] is not common, since the comment syntax is usually very distinct. It's obvious that But in the same language history, [2] is very common. And the rest-of-the-line comment has been the cleverest solution to it. There is no ambiguity, it comments anything, it's easy to nest comments, and as @agibralter mentioned, text editors can trivially provide with quick commenting of whole file sections. The reason why I focus on this [2] stuff, the nested comments, and the rest-of-the-line comment solution, whereas nobody here seems to care, is that I know for sure that some people will care one day, and that it solves [1] altogether. I hope I've been clearer. I'd with much joy throw away HTML-like balanced syntax, when I consider the benefits of rest-of-the-line comments. |
Also, I think everybody here has been mad, at least once, at the balanced HTML/XML comments :-) |
Last point: I strongly support that Mustache keeps its {{! local comment (!)}}. Rest-of-the-line comments would be an extension to Mustache syntax, certainly not a replacement for the balanced comment tags we're already used to. |
Certainly if you use the evolution of C as a case study, both |
Well, the two ideas do not have the same merit, and they are linked:
|
Issue #9 has been created for the discussion of single-line comments. As for block comments, the best analogue I can point to is SGML / XML / HTML comments; being inherently tag-based languages, they solved the problem of nesting tags inside block comments some time ago. The distinction between the two is that HTML et al are fundamentally tags containing textual content, whereas Mustache templates are fundamentally textual content containing tags. Nesting comments inside comments is something I've never before heard a demand for, and several widely used languages abide with the lack (e.g. CSS). I'm still 👍 to this becoming the block comment structure for v2.0.0 of the Mustache spec. Then again, I've never been upset by the balanced HTML / XML comment style (in HTML). |
Comment SectionsMulti-line mixed content comments would be easier to implement as a reserved section tag name:
I just implemented this in Mustache.php in 2 lines of code. |
To that end, |
FYI - I created a spec and submitted a pull request. |
This is super-old, but a question came up in Whenever we get around to making progress on Mustache 2.0, I'd totally be on board with adding a CDATA-ish super-comment like this:
Spec'd as: /\{\{!!.*?!!\}\}/m It's a backwards compatibility break, but the chances of a collision with IRL current templates are fairly small. This would make it easy to comment out mustache tags and such. |
Only if nesting would be supported. And Wrapping a template snippet in So no, it is not easy. Let's face it : the only commenting technique that deserves the "easy" qualifier, i.e. always work without requiring any Joule of the user's brain, is the end-of-line comment ( |
Please close/delete all open is please Check and close the issues |
Please close/delete the issues |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
In the spec, the syntax for Comments states that comments are opened with '{{!' and closed with '}}', the consequence being that '}}' cannot appear inside comments. That's fine and works fairly well. But one thing I've found useful during everyday coding is to comment out Mustache code fragments using Mustache comments. Our "Mustache-like" parser achieves this by using '{{!' as the open token and '!}}' as the close token. So in our parser, when you have a code fragment like:
you can easily comment it out via:
A similar thing cannot be achieved with a spec-compliant parser which I think is a shame.
As far as I understand it, this request would be backwards compatible too since existing code must not nest '}}' in comments.
What do you guys think?
The text was updated successfully, but these errors were encountered: