syntax_tree-haml 4.0.0 → 4.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +3 -2
- data/CHANGELOG.md +18 -1
- data/Gemfile.lock +4 -3
- data/lib/syntax_tree/haml/format.rb +43 -9
- data/lib/syntax_tree/haml/version.rb +1 -1
- data/syntax_tree-haml.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b926fc681f1792de33a0ab58885860f06337de292164185fd9d0cf86ff80da90
|
4
|
+
data.tar.gz: a09512989ef9b799975ec639ddbaa5fc65bddd76b0cdc9719b309372a5a4cb71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a07aea76babd7c8a4c765749b3107c0dd3a904ced2550ddb15ea85cfaa6d3df12f6d20767c855eede216d54fdf844e41b00efcf186b9b44409510236823d58ae
|
7
|
+
data.tar.gz: 108994617aba53d1eb5758d563c3a5b96f65551ec7a0af9e66862f9c8e26c77232f4eb3bc727d9711f7da78f32d91d91adff3a0152ea6b35d7098a5c14d4fabd
|
data/.github/workflows/main.yml
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
name: Main
|
2
|
+
|
2
3
|
on:
|
3
4
|
push:
|
4
5
|
branches:
|
5
6
|
- main
|
6
7
|
pull_request: {}
|
8
|
+
|
7
9
|
jobs:
|
8
10
|
ci:
|
9
11
|
strategy:
|
@@ -14,10 +16,9 @@ jobs:
|
|
14
16
|
- '2.7.5'
|
15
17
|
- '3.0'
|
16
18
|
- '3.1'
|
19
|
+
- '3.2'
|
17
20
|
name: CI
|
18
21
|
runs-on: ubuntu-latest
|
19
|
-
env:
|
20
|
-
CI: true
|
21
22
|
steps:
|
22
23
|
- uses: actions/checkout@v3
|
23
24
|
- uses: ruby/setup-ruby@v1
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,20 @@ 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.2] - 2023-03-09
|
10
|
+
|
11
|
+
### Changed
|
12
|
+
|
13
|
+
- Require `prettier_print` `1.2.1` or higher to fix the infinite loop bug.
|
14
|
+
- Maintain blank lines in nested nodes.
|
15
|
+
|
16
|
+
## [4.0.1] - 2023-03-07
|
17
|
+
|
18
|
+
### Changed
|
19
|
+
|
20
|
+
- We now keep blank lines around in the source template. (Multiple blank lines are squished down to a single blank line.)
|
21
|
+
- 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.
|
22
|
+
|
9
23
|
## [4.0.0] - 2023-03-07
|
10
24
|
|
11
25
|
### Changed
|
@@ -86,7 +100,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
|
|
86
100
|
|
87
101
|
- 🎉 Initial release! 🎉
|
88
102
|
|
89
|
-
[unreleased]: https://github.com/ruby-syntax-tree/syntax_tree-haml/compare/
|
103
|
+
[unreleased]: https://github.com/ruby-syntax-tree/syntax_tree-haml/compare/v4.0.2...HEAD
|
104
|
+
[4.0.2]: https://github.com/ruby-syntax-tree/syntax_tree-haml/compare/v4.0.1...v4.0.2
|
105
|
+
[4.0.1]: https://github.com/ruby-syntax-tree/syntax_tree-haml/compare/v4.0.0...v4.0.1
|
106
|
+
[4.0.0]: https://github.com/ruby-syntax-tree/syntax_tree-haml/compare/v3.0.0...v4.0.0
|
90
107
|
[3.0.0]: https://github.com/ruby-syntax-tree/syntax_tree-haml/compare/v2.0.0...v3.0.0
|
91
108
|
[2.0.0]: https://github.com/ruby-syntax-tree/syntax_tree-haml/compare/v1.3.2...v2.0.0
|
92
109
|
[1.3.2]: https://github.com/ruby-syntax-tree/syntax_tree-haml/compare/v1.3.1...v1.3.2
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
syntax_tree-haml (4.0.
|
4
|
+
syntax_tree-haml (4.0.2)
|
5
5
|
haml (>= 5.2)
|
6
|
-
prettier_print (>= 1.
|
6
|
+
prettier_print (>= 1.2.1)
|
7
7
|
syntax_tree (>= 6.0.0)
|
8
8
|
|
9
9
|
GEM
|
@@ -15,7 +15,7 @@ GEM
|
|
15
15
|
thor
|
16
16
|
tilt
|
17
17
|
minitest (5.18.0)
|
18
|
-
prettier_print (1.2.
|
18
|
+
prettier_print (1.2.1)
|
19
19
|
rake (13.0.6)
|
20
20
|
simplecov (0.22.0)
|
21
21
|
docile (~> 1.1)
|
@@ -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.
|
@@ -480,8 +504,18 @@ module SyntaxTree
|
|
480
504
|
q.group do
|
481
505
|
q.group { yield }
|
482
506
|
q.indent do
|
507
|
+
previous_line = nil
|
508
|
+
|
483
509
|
node.children.each do |child|
|
484
510
|
q.breakable_force
|
511
|
+
|
512
|
+
if previous_line && (child.line - previous_line) > 1
|
513
|
+
q.breakable_force
|
514
|
+
end
|
515
|
+
|
516
|
+
previous_line =
|
517
|
+
child.children.any? ? child.children.last.line : child.line
|
518
|
+
|
485
519
|
visit(child)
|
486
520
|
end
|
487
521
|
end
|
data/syntax_tree-haml.gemspec
CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.require_paths = %w[lib]
|
26
26
|
|
27
27
|
spec.add_dependency "haml", ">= 5.2"
|
28
|
-
spec.add_dependency "prettier_print", ">= 1.
|
28
|
+
spec.add_dependency "prettier_print", ">= 1.2.1"
|
29
29
|
spec.add_dependency "syntax_tree", ">= 6.0.0"
|
30
30
|
|
31
31
|
spec.add_development_dependency "bundler"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: syntax_tree-haml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Newton
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-03-
|
11
|
+
date: 2023-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: haml
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.
|
33
|
+
version: 1.2.1
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.
|
40
|
+
version: 1.2.1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: syntax_tree
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|