-
Notifications
You must be signed in to change notification settings - Fork 25
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
Improve formatting of multiline ERB #56
base: main
Are you sure you want to change the base?
Conversation
lib/erb/formatter.rb
Outdated
SyntaxTree.format(code, @line_width) | ||
width = @line_width - tag_stack.size * 2 | ||
SyntaxTree.format(code, width) |
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.
fyi: this fixes part of #55
@@ -39,7 +39,7 @@ class Error < StandardError; end | |||
ATTR = Regexp.union(SINGLE_QUOTE_ATTR, DOUBLE_QUOTE_ATTR, UNQUOTED_ATTR, UNQUOTED_VALUE) | |||
MULTILINE_ATTR_NAMES = %w[class data-action] | |||
|
|||
ERB_TAG = %r{(<%(?:==|=|-|))\s*(.*?)\s*(-?%>)}m | |||
ERB_TAG = %r{(<%(?:=|-|#)*)(?:(?!\n)\s)*(.*?)\s*(-?%>)}m |
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.
fyi: (?:(?!\n)\s)
matches all whitespace except for newlines. Done this in order to preserve comment indentation on the first line
I totally didn't notice the existence of #7 and did my own implementation of better multiline ERB.
This PR does 2 things:
(Due to the fact that I was adding to repetitive logic, I chose to optimize the case statement. If this is undesirable and we prefer even more repetition, I'm OK with having that refactored back)