w_syntax_tree-erb 0.10.2 → 0.10.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/Gemfile.lock +1 -1
- data/lib/syntax_tree/erb/format.rb +3 -20
- data/lib/syntax_tree/erb/nodes.rb +34 -18
- data/lib/syntax_tree/erb/parser.rb +1 -1
- data/lib/syntax_tree/erb/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b67bfa283053d82054d6b3f6f41723c4d9ffb6a54431c3e548eeceb0f3d53ef
|
4
|
+
data.tar.gz: 5de3bfd5e3a883a4d8cd595bf525298a7fc24b110acb32e8542aeebcd3e68b98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3be81363e0f5c65864c43d225f4ffb56c3f1e7d5e32ef8a8188e64481d4b6124aa046399e9df05db10c64973eb459c40de63508b343789e0a9afda8fbf64a979
|
7
|
+
data.tar.gz: 22fd1884afe7d82abd172440c5a712b54101730718352acd3078ef7b37f2d79a503da90f90fa5c0831759be465bc6df0af6471a7ab015bb3a673db2df73d19c1
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,21 @@ 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.3] - 2023-08-27
|
10
|
+
|
11
|
+
## Fixes
|
12
|
+
|
13
|
+
- Allows parsing ERB-tags with if, else and end in the same tag
|
14
|
+
|
15
|
+
```erb
|
16
|
+
<%= if true
|
17
|
+
what
|
18
|
+
end %>
|
19
|
+
```
|
20
|
+
|
21
|
+
This opens the possibility for formatting all if-statements with SyntaxTree properly
|
22
|
+
and removes the fix where any if-statement was force to one line.
|
23
|
+
|
9
24
|
## [0.10.2] - 2023-08-22
|
10
25
|
|
11
26
|
### Fixes
|
data/Gemfile.lock
CHANGED
@@ -114,7 +114,7 @@ module SyntaxTree
|
|
114
114
|
q.text(" ")
|
115
115
|
visit(node.keyword)
|
116
116
|
end
|
117
|
-
node.content.
|
117
|
+
node.content.blank? ? q.text(" ") : visit(node.content)
|
118
118
|
|
119
119
|
visit(node.closing_tag)
|
120
120
|
end
|
@@ -163,7 +163,8 @@ module SyntaxTree
|
|
163
163
|
|
164
164
|
def format_statement(statement)
|
165
165
|
formatter =
|
166
|
-
SyntaxTree::Formatter.new("", [],
|
166
|
+
SyntaxTree::Formatter.new("", [], SyntaxTree::ERB::MAX_WIDTH)
|
167
|
+
|
167
168
|
formatter.format(statement)
|
168
169
|
formatter.flush
|
169
170
|
rows = formatter.output.join.split("\n")
|
@@ -305,24 +306,6 @@ module SyntaxTree
|
|
305
306
|
node.respond_to?(:new_line) ? node.new_line&.count || 0 : 0
|
306
307
|
end
|
307
308
|
|
308
|
-
def erb_print_width(node)
|
309
|
-
# Set the width to maximum if we have an IfNode or IfOp,
|
310
|
-
# we cannot format them purely with SyntaxTree because the ERB-syntax will be unparseable.
|
311
|
-
check_for_if_statement(node) ? 999_999 : SyntaxTree::ERB::MAX_WIDTH
|
312
|
-
end
|
313
|
-
|
314
|
-
def check_for_if_statement(node)
|
315
|
-
return false if node.nil?
|
316
|
-
|
317
|
-
if node.is_a?(SyntaxTree::IfNode) || node.is_a?(SyntaxTree::IfOp)
|
318
|
-
return true
|
319
|
-
end
|
320
|
-
|
321
|
-
node.child_nodes.any? do |child_node|
|
322
|
-
check_for_if_statement(child_node)
|
323
|
-
end
|
324
|
-
end
|
325
|
-
|
326
309
|
def handle_child_nodes(child_nodes)
|
327
310
|
group = []
|
328
311
|
|
@@ -295,16 +295,7 @@ module SyntaxTree
|
|
295
295
|
)
|
296
296
|
end
|
297
297
|
|
298
|
-
@content =
|
299
|
-
if content.is_a?(ErbContent)
|
300
|
-
content
|
301
|
-
else
|
302
|
-
# Set content to nil if it is empty
|
303
|
-
content ||= []
|
304
|
-
content = content.map(&:value).join if content.is_a?(Array)
|
305
|
-
ErbContent.new(value: content) unless content.strip.empty?
|
306
|
-
end
|
307
|
-
|
298
|
+
@content = prepare_content(content)
|
308
299
|
@closing_tag = closing_tag
|
309
300
|
end
|
310
301
|
|
@@ -338,6 +329,24 @@ module SyntaxTree
|
|
338
329
|
closing_tag: closing_tag
|
339
330
|
)
|
340
331
|
end
|
332
|
+
|
333
|
+
private
|
334
|
+
|
335
|
+
def prepare_content(content)
|
336
|
+
if content.is_a?(ErbContent)
|
337
|
+
content
|
338
|
+
else
|
339
|
+
# Set content to nil if it is empty
|
340
|
+
content ||= []
|
341
|
+
|
342
|
+
ErbContent.new(value: content)
|
343
|
+
end
|
344
|
+
rescue SyntaxTree::Parser::ParseError
|
345
|
+
# Try to add the keyword to see if it parses
|
346
|
+
result = ErbContent.new(value: [keyword, *content])
|
347
|
+
@keyword = nil
|
348
|
+
result
|
349
|
+
end
|
341
350
|
end
|
342
351
|
|
343
352
|
class ErbBlock < Block
|
@@ -413,7 +422,7 @@ module SyntaxTree
|
|
413
422
|
|
414
423
|
class ErbElse < ErbIf
|
415
424
|
def accept(visitor)
|
416
|
-
visitor.
|
425
|
+
visitor.visit_erb_else(self)
|
417
426
|
end
|
418
427
|
end
|
419
428
|
|
@@ -448,16 +457,23 @@ module SyntaxTree
|
|
448
457
|
end
|
449
458
|
|
450
459
|
class ErbContent < Node
|
451
|
-
attr_reader(:value
|
460
|
+
attr_reader(:value)
|
452
461
|
|
453
462
|
def initialize(value:)
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
rescue SyntaxTree::Parser::ParseError
|
458
|
-
# Removes leading and trailing whitespace
|
459
|
-
@value = value&.lstrip&.rstrip
|
463
|
+
if value.is_a?(Array)
|
464
|
+
value =
|
465
|
+
value.map { |token| token.is_a?(Token) ? token.value : token }.join
|
460
466
|
end
|
467
|
+
@value = SyntaxTree.parse(value.strip)
|
468
|
+
end
|
469
|
+
|
470
|
+
def blank?
|
471
|
+
value.nil? ||
|
472
|
+
value
|
473
|
+
.statements
|
474
|
+
.child_nodes
|
475
|
+
.reject { |node| node.is_a?(SyntaxTree::VoidStmt) }
|
476
|
+
.empty?
|
461
477
|
end
|
462
478
|
|
463
479
|
def accept(visitor)
|
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.
|
4
|
+
version: 0.10.3
|
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-
|
12
|
+
date: 2023-08-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: prettier_print
|
@@ -159,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
159
159
|
- !ruby/object:Gem::Version
|
160
160
|
version: '0'
|
161
161
|
requirements: []
|
162
|
-
rubygems_version: 3.4.
|
162
|
+
rubygems_version: 3.4.10
|
163
163
|
signing_key:
|
164
164
|
specification_version: 4
|
165
165
|
summary: Syntax Tree support for ERB
|