ERB deserves its own commenting token
- 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.
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 --#>
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.
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.
I'd just really like to see this solved even if none of my code is used.
Updated by k0kubun (Takashi Kokubun) over 6 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.