-
Notifications
You must be signed in to change notification settings - Fork 32
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
Comment out ERB #820
Comment out ERB #820
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -389,4 +389,17 @@ def to_utf8! | |
end | ||
end | ||
|
||
end # class String | ||
def comment_erb | ||
# Split with -1 to avoid stripping empty strings | ||
output = self.split("\n", -1).collect! do |line| | ||
# If we have a commented out line (starts with #) | ||
# which contains an ERB statement (<% ...) | ||
# then comment out the ERB statement (<%# ...) | ||
if line.strip() =~ /^#.*<%/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should allow whitespace before the # sign. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm explicitly not allowing trailing ERB. See comment. Also I added the ability to disable ERB commenting with |
||
line.gsub!('<%', '<%#') | ||
end | ||
line.chomp | ||
end | ||
return output.join("\n") | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could just be self.lines instead of split("\n", -1)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
self.lines
has different behavior thansplit("\n", -1)
when it comes to empty strings