w_syntax_tree-erb 0.10.3 → 0.10.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6b67bfa283053d82054d6b3f6f41723c4d9ffb6a54431c3e548eeceb0f3d53ef
4
- data.tar.gz: 5de3bfd5e3a883a4d8cd595bf525298a7fc24b110acb32e8542aeebcd3e68b98
3
+ metadata.gz: 5da234530c78c55f3594957cdf44e380ed603b92e52c023df68f015d0d8c7f45
4
+ data.tar.gz: 99b3b25d533a09e6337cc552c5f6d9224e977586272afb4c358df277e08c09eb
5
5
  SHA512:
6
- metadata.gz: 3be81363e0f5c65864c43d225f4ffb56c3f1e7d5e32ef8a8188e64481d4b6124aa046399e9df05db10c64973eb459c40de63508b343789e0a9afda8fbf64a979
7
- data.tar.gz: 22fd1884afe7d82abd172440c5a712b54101730718352acd3078ef7b37f2d79a503da90f90fa5c0831759be465bc6df0af6471a7ab015bb3a673db2df73d19c1
6
+ metadata.gz: a408ef26dd34ae012f516224090d65eea520b795c7a50080a8ed603b09095bc0eb7198e97b0ea7d75b9d113896344496cf1854442bf3ee9eab276e2437e86893
7
+ data.tar.gz: dbd2ff290949bc982fe16b7c3153ae01b09adfd8d4fd9e710cca7b6a3dce19646b770274cd00f0438d42ca3daa7a89b824411a9624db98e4aff13b014db03478
data/CHANGELOG.md CHANGED
@@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.10.4] - 2023-08-28
10
+
11
+ - Avoid grouping single tags
12
+ - Handle multiline ERB-comments
13
+
9
14
  ## [0.10.3] - 2023-08-27
10
15
 
11
16
  ## Fixes
@@ -98,7 +103,10 @@ Output:
98
103
  - Can format a lot of .html.erb-syntax and works as a plugin to syntax_tree.
99
104
  - This is still early and there are a lot of different weird syntaxes out there.
100
105
 
101
- [unreleased]: https://github.com/davidwessman/syntax_tree-erb/compare/v0.10.1...HEAD
106
+ [unreleased]: https://github.com/davidwessman/syntax_tree-erb/compare/v0.10.4...HEAD
107
+ [0.10.4]: https://github.com/davidwessman/syntax_tree-erb/compare/v0.10.3...v0.10.4
108
+ [0.10.3]: https://github.com/davidwessman/syntax_tree-erb/compare/v0.10.2...v0.10.3
109
+ [0.10.2]: https://github.com/davidwessman/syntax_tree-erb/compare/v0.10.1...v0.10.2
102
110
  [0.10.1]: https://github.com/davidwessman/syntax_tree-erb/compare/v0.10.0...v0.10.1
103
111
  [0.10.0]: https://github.com/davidwessman/syntax_tree-erb/compare/v0.9.5...v0.10.0
104
112
  [0.9.5]: https://github.com/davidwessman/syntax_tree-erb/compare/v0.9.4...v0.9.5
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- w_syntax_tree-erb (0.10.3)
4
+ w_syntax_tree-erb (0.10.4)
5
5
  prettier_print (~> 1.2, >= 1.2.0)
6
6
  syntax_tree (~> 6.1, >= 6.1.1)
7
7
 
@@ -114,6 +114,7 @@ module SyntaxTree
114
114
  q.text(" ")
115
115
  visit(node.keyword)
116
116
  end
117
+
117
118
  node.content.blank? ? q.text(" ") : visit(node.content)
118
119
 
119
120
  visit(node.closing_tag)
@@ -137,27 +138,25 @@ module SyntaxTree
137
138
  end
138
139
 
139
140
  def visit_erb_content(node)
140
- if node.value.is_a?(String)
141
- output_rows(node.value.split("\n"))
142
- else
143
- nodes = node.value&.statements&.child_nodes || []
144
- nodes = nodes.reject { |node| node.is_a?(SyntaxTree::VoidStmt) }
141
+ # Reject all VoidStmt to avoid empty lines
142
+ nodes =
143
+ (node.value&.statements&.child_nodes || []).reject do |node|
144
+ node.is_a?(SyntaxTree::VoidStmt)
145
+ end
145
146
 
146
- if nodes.size == 1
147
- q.text(" ")
147
+ if nodes.size == 1
148
+ q.text(" ")
149
+ format_statement(nodes.first)
150
+ q.text(" ")
151
+ elsif nodes.size > 1
152
+ q.indent do
153
+ q.breakable("")
148
154
  q.seplist(nodes, -> { q.breakable("") }) do |child_node|
149
155
  format_statement(child_node)
150
156
  end
151
- q.text(" ")
152
- elsif nodes.size > 1
153
- q.indent do
154
- q.breakable("")
155
- q.seplist(nodes, -> { q.breakable("") }) do |child_node|
156
- format_statement(child_node)
157
- end
158
- end
159
- q.breakable
160
157
  end
158
+
159
+ q.breakable
161
160
  end
162
161
  end
163
162
 
@@ -341,20 +340,26 @@ module SyntaxTree
341
340
  end
342
341
 
343
342
  def handle_group(nodes, break_after:)
344
- return unless nodes.any?
345
-
346
- q.group do
347
- nodes.each_with_index do |node, group_index|
348
- visit(node)
349
- next_node = nodes[group_index + 1]
350
- next if next_node.nil?
351
- breakable_between_group(node, next_node)
352
- end
343
+ if nodes.size == 1
344
+ handle_group_nodes(nodes)
345
+ elsif nodes.size > 1
346
+ q.group { handle_group_nodes(nodes) }
347
+ else
348
+ return
353
349
  end
354
350
 
355
351
  breakable_between_group(nodes.last, nil) if break_after
356
352
  end
357
353
 
354
+ def handle_group_nodes(nodes)
355
+ nodes.each_with_index do |node, group_index|
356
+ visit(node)
357
+ next_node = nodes[group_index + 1]
358
+ next if next_node.nil?
359
+ breakable_between_group(node, next_node)
360
+ end
361
+ end
362
+
358
363
  def node_should_group(node)
359
364
  node.is_a?(SyntaxTree::ERB::CharData) ||
360
365
  node.is_a?(SyntaxTree::ERB::ErbNode)
@@ -94,7 +94,7 @@ module SyntaxTree
94
94
  # <!DOCTYPE
95
95
  enum.yield :doctype, $&, index, line
96
96
  state << :inside
97
- when /\A<%#.*%>/
97
+ when /\A<%#[\s\S]*?%>/
98
98
  # An ERB-comment
99
99
  # <%# this is an ERB comment %>
100
100
  enum.yield :erb_comment, $&, index, line
@@ -2,6 +2,6 @@
2
2
 
3
3
  module SyntaxTree
4
4
  module ERB
5
- VERSION = "0.10.3"
5
+ VERSION = "0.10.4"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: w_syntax_tree-erb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.3
4
+ version: 0.10.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Newton
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2023-08-27 00:00:00.000000000 Z
12
+ date: 2023-08-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: prettier_print