Feature #11624
closedERB deserves its own commenting token
Description
Problem¶
- ERB is a DSL but commenting out code is not the easy workflow feature in ERB that it is in other languages.
- ERB elements were cleverly designed to look like a special kind of html element so it makes programmers unhappy and surprised when commenting the HTML does not affect the ruby elements nested inside.
- This makes certain workflows particularly difficult e.g. sketching out a view to aide with iteratively developing its underlying model.
Solution¶
This proposes a new set of ERB commenting tokens - currently for use with HTML only.
They take the form of an HTML comment combined with a Ruby comment.
Looks like this:
<#--
None of this will be outputted: <%= my_ruby_var %>
and neither will this
--#>
Implementation¶
This patch takes a cautious approach. Legacy ERB files may contain typos which happen to match ERB comment token. These are invalid HTML but may have been tolerated and simply printed out in the displayed webpage. For this reason the implementation ignores the ERB comment tokens unless they are properly closed off. This greatly reduces the likelihood of legacy issues and if they do arise they will not disrupt intended functionality.
Personal note¶
I realise I can't suggest anything that hasn't been thought of already. I see that the main reason this hasn't already been implemented is probably because ERB is not just for HTML. However, it may be that a pair of tokens can be found and proven to be compatible with most languages.
Thousands of people clearly continue to want this and the hackiness of the accepted answers on stack overflow shows how others have just gotten used to doing it the hard way.
http://stackoverflow.com/questions/3426671/how-does-one-comment-in-an-erb-template
http://stackoverflow.com/questions/3127644/block-comments-in-html-erb-templates-in-rails
http://stackoverflow.com/questions/3901619/how-to-comment-lines-in-rails-html-erb-files
I'd just really like to see this solved even if none of my code is used.
Files
Updated by nobu (Nobuyoshi Nakada) about 9 years ago
- Description updated (diff)
- Status changed from Open to Assigned
- Assignee set to seki (Masatoshi Seki)
Updated by hsbt (Hiroshi SHIBATA) over 7 years ago
- Assignee changed from seki (Masatoshi Seki) to k0kubun (Takashi Kokubun)
- Target version set to 2.5
Updated by k0kubun (Takashi Kokubun) over 7 years ago
- Status changed from Assigned to Rejected
This syntax only adds a support for comments that include "%>" or "%%>". I think the major use case of such kind of feature is just ad-hoc disabling partial template and it's not for a normal permanent comment, which can be done in "<%#". So I think its use case is limited compared to "<%#"'s one.
The downside of this feature is slowing down compilation. It will be reported as a bug like [Bug #12074].
Comparing merits and demerits, for now, I reject this feature in ERB and solve your problem with third-party library https://github.com/k0kubun/erb-comment.
If you want to use it on Rails, you may need to port this to Erubi. If main use case is web application (it's not the case for ERB), it's less important to care about compilation cost. So it'll be a good idea to have such a feature in Erubi.