diff --git a/erb-formatter.gemspec b/erb-formatter.gemspec index 9a68c5b..efacebf 100644 --- a/erb-formatter.gemspec +++ b/erb-formatter.gemspec @@ -28,8 +28,6 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] - spec.add_dependency "syntax_tree", '~> 6.0' - spec.add_development_dependency "tailwindcss-rails", "~> 2.0" spec.add_development_dependency "m", "~> 1.0" end diff --git a/lib/erb/formatter.rb b/lib/erb/formatter.rb index a868a44..88730a5 100644 --- a/lib/erb/formatter.rb +++ b/lib/erb/formatter.rb @@ -8,20 +8,7 @@ require 'securerandom' require 'erb/formatter/version' -require 'syntax_tree' -require 'syntax_tree/plugin/trailing_comma' - class ERB::Formatter - module SyntaxTreeCommandPatch - def format(q) - q.group do - q.format(message) - q.text(" ") - q.format(arguments) # WAS: q.nest(message.value.length + 1) { q.format(arguments) } - end - end - end - autoload :IgnoreList, 'erb/formatter/ignore_list' class Error < StandardError; end @@ -37,7 +24,7 @@ class Error < StandardError; end BAD_ATTR = %r{#{ATTR_NAME}=\s+}u QUOTED_ATTR = Regexp.union(SINGLE_QUOTE_ATTR, DOUBLE_QUOTE_ATTR) ATTR = Regexp.union(SINGLE_QUOTE_ATTR, DOUBLE_QUOTE_ATTR, UNQUOTED_ATTR, UNQUOTED_VALUE) - MULTILINE_ATTR_NAMES = %w[class data-action] + MULTILINE_ATTR_NAMES = %w[data-action] ERB_TAG = %r{(<%(?:==|=|-|))\s*(.*?)\s*(-?%>)}m ERB_PLACEHOLDER = %r{erb[a-z0-9]+tag} @@ -144,12 +131,12 @@ def format_attributes(tag_name, attrs, tag_closing) name, value = attr.split('=', 2) if value.nil? - attr_html << indented("#{name}") + attr_html << (within_line_width ? " #{name}" : indented("#{name}")) next end if /\A#{UNQUOTED_VALUE}\z/o.match?(value) - attr_html << indented("#{name}=\"#{value}\"") + attr_html << (within_line_width ? " #{name}=\"#{value}\"" : indented("#{name}=\"#{value}\"")) next end @@ -268,21 +255,6 @@ def format_ruby(code, autoclose: false) code += "\nend" unless RUBY_OPEN_BLOCK["#{code}\nend"] code += "\n}" unless RUBY_OPEN_BLOCK["#{code}\n}"] end - p RUBY_IN_: code if @debug - - SyntaxTree::Command.prepend SyntaxTreeCommandPatch - - code = begin - SyntaxTree.format(code, @line_width) - rescue SyntaxTree::Parser::ParseError => error - p RUBY_PARSE_ERROR: error if @debug - code - end - - lines = code.strip.lines - lines = lines[0...-1] if autoclose - code = lines.map { |l| indented(l.chomp("\n"), strip: false) }.join.strip - p RUBY_OUT: code if @debug code end diff --git a/lib/erb/formatter/command_line.rb b/lib/erb/formatter/command_line.rb index 92cfa51..880affa 100644 --- a/lib/erb/formatter/command_line.rb +++ b/lib/erb/formatter/command_line.rb @@ -9,7 +9,7 @@ def self.tailwindcss_class_sorter(css_path) css = css.tr("\n", " ").gsub(%r{\/\*.*?\*\/},"") # remove comments css = css.gsub(%r<@media.*?\{>, "") # strip media queries css = css.scan(%r<(?:^|\}|\{) *(\S.*?) *\{>).join(" ") # extract selectors - classes = css.tr(","," ").split(" ").grep(/\./).uniq.map { _1.split('.').last.gsub("\\", "") } + classes = css.tr(","," ").split(" ").grep(/\./).uniq.map { _1.split('.').last.gsub("\\3", "").gsub("\\", "") } indexed_classes = Hash[classes.zip((0...classes.size).to_a)] ->(class_name) do diff --git a/test/fixtures/attributes.html.erb b/test/fixtures/attributes.html.erb index daaeb6d..e87be9a 100644 --- a/test/fixtures/attributes.html.erb +++ b/test/fixtures/attributes.html.erb @@ -9,3 +9,5 @@ data-short-url="//test.com/?q=v" data-long-url="https://google.ca/this-is-a-long-url-with-a-query-string?query=something" data-long-url-single='https://google.ca/this-is-a-long-url-with-a-query-string?query=something'> + + diff --git a/test/fixtures/attributes.html.expected.erb b/test/fixtures/attributes.html.expected.erb index 0aed143..2419918 100644 --- a/test/fixtures/attributes.html.expected.erb +++ b/test/fixtures/attributes.html.expected.erb @@ -8,3 +8,10 @@ data-long-url="https://google.ca/this-is-a-long-url-with-a-query-string?query=something" data-long-url-single='https://google.ca/this-is-a-long-url-with-a-query-string?query=something' > + + diff --git a/test/fixtures/tailwindcss/class_sorting.html.erb b/test/fixtures/tailwindcss/class_sorting.html.erb index 9ff335d..9db9519 100644 --- a/test/fixtures/tailwindcss/class_sorting.html.erb +++ b/test/fixtures/tailwindcss/class_sorting.html.erb @@ -7,7 +7,7 @@