syntax_tree-haml 4.0.0 → 4.0.1
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 +10 -1
- data/Gemfile.lock +2 -1
- data/lib/syntax_tree/haml/format.rb +33 -9
- data/lib/syntax_tree/haml/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz: '
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '081e23c9f9f103fd51db64973ec590cb21e1f4e34b31dc6769e70d2e7ec83db8'
|
4
|
+
data.tar.gz: 900420a1918e007b906c3bf94d9d8639bc379acd82f29b1cdd307c2ca21688a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 991fb1d1aedd65e2bcea53b89cc710dd3734109770bf03dc79070437129397cfbaa4b7a400c4584881e41a52db46bf0254cd84d3499ff1b4a3b3763ef29cb32e
|
7
|
+
data.tar.gz: b48967b39546927871d86c485210ba6ccf007ae608bd3cdbacc8962658c1648d56e3ac76074e73042962142b799f0785b4719f8b680abbc972088e2eea622327
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [4.0.1] - 2023-03-07
|
10
|
+
|
11
|
+
### Changed
|
12
|
+
|
13
|
+
- We now keep blank lines around in the source template. (Multiple blank lines are squished down to a single blank line.)
|
14
|
+
- We now actually parse the Ruby code written in `%=` tags. This fixed a couple of bugs and allows us to better format the output. For example, `%p= 1+1` will now be formatted as `%p= 1 + 1`. If the output fails to parse it falls back to the previous behavior of just printing the Ruby code as-is.
|
15
|
+
|
9
16
|
## [4.0.0] - 2023-03-07
|
10
17
|
|
11
18
|
### Changed
|
@@ -86,7 +93,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
|
|
86
93
|
|
87
94
|
- 🎉 Initial release! 🎉
|
88
95
|
|
89
|
-
[unreleased]: https://github.com/ruby-syntax-tree/syntax_tree-haml/compare/
|
96
|
+
[unreleased]: https://github.com/ruby-syntax-tree/syntax_tree-haml/compare/v4.0.1...HEAD
|
97
|
+
[4.0.1]: https://github.com/ruby-syntax-tree/syntax_tree-haml/compare/v4.0.0...v4.0.1
|
98
|
+
[4.0.0]: https://github.com/ruby-syntax-tree/syntax_tree-haml/compare/v3.0.0...v4.0.0
|
90
99
|
[3.0.0]: https://github.com/ruby-syntax-tree/syntax_tree-haml/compare/v2.0.0...v3.0.0
|
91
100
|
[2.0.0]: https://github.com/ruby-syntax-tree/syntax_tree-haml/compare/v1.3.2...v2.0.0
|
92
101
|
[1.3.2]: https://github.com/ruby-syntax-tree/syntax_tree-haml/compare/v1.3.1...v1.3.2
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
syntax_tree-haml (4.0.
|
4
|
+
syntax_tree-haml (4.0.1)
|
5
5
|
haml (>= 5.2)
|
6
6
|
prettier_print (>= 1.0.0)
|
7
7
|
syntax_tree (>= 6.0.0)
|
@@ -31,6 +31,7 @@ GEM
|
|
31
31
|
|
32
32
|
PLATFORMS
|
33
33
|
arm64-darwin-22
|
34
|
+
x86_64-linux
|
34
35
|
|
35
36
|
DEPENDENCIES
|
36
37
|
bundler
|
@@ -120,7 +120,13 @@ module SyntaxTree
|
|
120
120
|
|
121
121
|
# Visit the root node of the AST.
|
122
122
|
def visit_root(node)
|
123
|
+
previous_line = nil
|
124
|
+
|
123
125
|
node.children.each do |child|
|
126
|
+
q.breakable_force if previous_line && (child.line - previous_line) > 1
|
127
|
+
previous_line =
|
128
|
+
child.children.any? ? child.children.last.line : child.line
|
129
|
+
|
124
130
|
visit(child)
|
125
131
|
q.breakable_force
|
126
132
|
end
|
@@ -377,15 +383,8 @@ module SyntaxTree
|
|
377
383
|
# tag.
|
378
384
|
q.breakable_empty
|
379
385
|
|
380
|
-
if node.value[:parse]
|
381
|
-
|
382
|
-
# interpolation and it's marked as { parse: true }, then we
|
383
|
-
# don't actually want the = prefix, and we want to remove extra
|
384
|
-
# escaping.
|
385
|
-
q.if_break { q.text("") }.if_flat { q.text(" ") }
|
386
|
-
q.text(value[1...-1].gsub(/\\"/, "\""))
|
387
|
-
elsif node.value[:parse]
|
388
|
-
q.text("= #{value}")
|
386
|
+
if node.value[:parse]
|
387
|
+
format_tag_value(q, value)
|
389
388
|
else
|
390
389
|
q.if_break { q.text("") }.if_flat { q.text(" ") }
|
391
390
|
q.text(value)
|
@@ -399,6 +398,31 @@ module SyntaxTree
|
|
399
398
|
|
400
399
|
private
|
401
400
|
|
401
|
+
def format_tag_value(q, value)
|
402
|
+
program = SyntaxTree.parse(value)
|
403
|
+
if !program || program.statements.body.length > 1
|
404
|
+
return q.text("= #{value}")
|
405
|
+
end
|
406
|
+
|
407
|
+
statement = program.statements.body.first
|
408
|
+
formatter = SyntaxTree::Formatter.new(value, [], Float::INFINITY)
|
409
|
+
formatter.format(statement)
|
410
|
+
formatter.flush
|
411
|
+
formatted = formatter.output.join
|
412
|
+
|
413
|
+
if statement.is_a?(StringLiteral) && statement.parts.length > 1
|
414
|
+
# There's a weird case here where if the value includes interpolation
|
415
|
+
# and it's marked as { parse: true }, then we don't actually want the
|
416
|
+
# = prefix, and we want to remove extra escaping.
|
417
|
+
q.if_break { q.text("") }.if_flat { q.text(" ") }
|
418
|
+
q.text(formatted[1...-1].gsub(/\\"/, "\""))
|
419
|
+
else
|
420
|
+
q.text("= #{formatted}")
|
421
|
+
end
|
422
|
+
rescue Parser::ParseError
|
423
|
+
q.text("= #{value}")
|
424
|
+
end
|
425
|
+
|
402
426
|
# When printing out sequences of silent scripts, sometimes subsequent nodes
|
403
427
|
# will be continuations of previous nodes. In that case we want to dedent
|
404
428
|
# them to match.
|