syntax_tree-haml 3.0.0 → 4.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -1
- data/Gemfile.lock +12 -15
- data/lib/syntax_tree/haml/format.rb +77 -30
- data/lib/syntax_tree/haml/version.rb +1 -1
- data/syntax_tree-haml.gemspec +2 -3
- metadata +5 -11
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,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.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
|
+
|
16
|
+
## [4.0.0] - 2023-03-07
|
17
|
+
|
18
|
+
### Changed
|
19
|
+
|
20
|
+
- Required syntax_tree version 6.0.0 or higher.
|
21
|
+
- Fixed up hash attribute parser to handle multiline hashes using Syntax Tree itself.
|
22
|
+
|
9
23
|
## [3.0.0] - 2022-12-23
|
10
24
|
|
11
25
|
### Changed
|
@@ -79,7 +93,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
|
|
79
93
|
|
80
94
|
- 🎉 Initial release! 🎉
|
81
95
|
|
82
|
-
[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
|
83
99
|
[3.0.0]: https://github.com/ruby-syntax-tree/syntax_tree-haml/compare/v2.0.0...v3.0.0
|
84
100
|
[2.0.0]: https://github.com/ruby-syntax-tree/syntax_tree-haml/compare/v1.3.2...v2.0.0
|
85
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,10 +1,10 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
syntax_tree-haml (
|
5
|
-
haml (>= 5.2
|
4
|
+
syntax_tree-haml (4.0.1)
|
5
|
+
haml (>= 5.2)
|
6
6
|
prettier_print (>= 1.0.0)
|
7
|
-
syntax_tree (>=
|
7
|
+
syntax_tree (>= 6.0.0)
|
8
8
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
@@ -14,26 +14,23 @@ GEM
|
|
14
14
|
temple (>= 0.8.2)
|
15
15
|
thor
|
16
16
|
tilt
|
17
|
-
minitest (5.
|
18
|
-
prettier_print (1.
|
17
|
+
minitest (5.18.0)
|
18
|
+
prettier_print (1.2.0)
|
19
19
|
rake (13.0.6)
|
20
|
-
simplecov (0.
|
20
|
+
simplecov (0.22.0)
|
21
21
|
docile (~> 1.1)
|
22
22
|
simplecov-html (~> 0.11)
|
23
23
|
simplecov_json_formatter (~> 0.1)
|
24
24
|
simplecov-html (0.12.3)
|
25
25
|
simplecov_json_formatter (0.1.4)
|
26
|
-
syntax_tree (
|
27
|
-
prettier_print (>= 1.
|
28
|
-
temple (0.
|
26
|
+
syntax_tree (6.0.2)
|
27
|
+
prettier_print (>= 1.2.0)
|
28
|
+
temple (0.10.0)
|
29
29
|
thor (1.2.1)
|
30
|
-
tilt (2.0
|
30
|
+
tilt (2.1.0)
|
31
31
|
|
32
32
|
PLATFORMS
|
33
|
-
|
34
|
-
x86_64-darwin-19
|
35
|
-
x86_64-darwin-20
|
36
|
-
x86_64-darwin-21
|
33
|
+
arm64-darwin-22
|
37
34
|
x86_64-linux
|
38
35
|
|
39
36
|
DEPENDENCIES
|
@@ -44,4 +41,4 @@ DEPENDENCIES
|
|
44
41
|
syntax_tree-haml!
|
45
42
|
|
46
43
|
BUNDLED WITH
|
47
|
-
2.
|
44
|
+
2.4.1
|
@@ -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
|
@@ -161,7 +167,6 @@ module SyntaxTree
|
|
161
167
|
end
|
162
168
|
|
163
169
|
LiteralHashValue = Struct.new(:value)
|
164
|
-
StringHashValue = Struct.new(:value, :quote)
|
165
170
|
|
166
171
|
# When formatting a tag, there are a lot of different kinds of things that
|
167
172
|
# can be printed out. There's the tag name, the attributes, the content,
|
@@ -274,7 +279,7 @@ module SyntaxTree
|
|
274
279
|
q.group do
|
275
280
|
level == 0 ? q.breakable_empty : q.breakable_space
|
276
281
|
q.seplist(hash, nil, :each_pair) do |key, value|
|
277
|
-
if key.match?(/^@|[-:]/)
|
282
|
+
if key.match?(/^@|[-:]/) && !key.match?(/^["']/)
|
278
283
|
q.text("#{quote}#{Quotes.normalize(key, quote)}#{quote}:")
|
279
284
|
else
|
280
285
|
q.text("#{key}:")
|
@@ -352,17 +357,7 @@ module SyntaxTree
|
|
352
357
|
# we're going to print them out here.
|
353
358
|
if node.value[:dynamic_attributes].old
|
354
359
|
parts << PlainPart.new("%div") if parts.empty?
|
355
|
-
|
356
|
-
if ::Haml::AttributeParser.available?
|
357
|
-
dynamic = parse_attributes(node.value[:dynamic_attributes].old)
|
358
|
-
parts << if dynamic.is_a?(LiteralHashValue)
|
359
|
-
PlainPart.new(dynamic.value)
|
360
|
-
else
|
361
|
-
HashAttributesPart.new(dynamic)
|
362
|
-
end
|
363
|
-
else
|
364
|
-
parts << PlainPart.new(node.value[:dynamic_attributes].old)
|
365
|
-
end
|
360
|
+
parts << parse_attributes(node.value[:dynamic_attributes].old)
|
366
361
|
end
|
367
362
|
|
368
363
|
# https://haml.info/docs/yardoc/file.REFERENCE.html#object-reference-
|
@@ -388,15 +383,8 @@ module SyntaxTree
|
|
388
383
|
# tag.
|
389
384
|
q.breakable_empty
|
390
385
|
|
391
|
-
if node.value[:parse]
|
392
|
-
|
393
|
-
# interpolation and it's marked as { parse: true }, then we
|
394
|
-
# don't actually want the = prefix, and we want to remove extra
|
395
|
-
# escaping.
|
396
|
-
q.if_break { q.text("") }.if_flat { q.text(" ") }
|
397
|
-
q.text(value[1...-1].gsub(/\\"/, "\""))
|
398
|
-
elsif node.value[:parse]
|
399
|
-
q.text("= #{value}")
|
386
|
+
if node.value[:parse]
|
387
|
+
format_tag_value(q, value)
|
400
388
|
else
|
401
389
|
q.if_break { q.text("") }.if_flat { q.text(" ") }
|
402
390
|
q.text(value)
|
@@ -410,6 +398,31 @@ module SyntaxTree
|
|
410
398
|
|
411
399
|
private
|
412
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
|
+
|
413
426
|
# When printing out sequences of silent scripts, sometimes subsequent nodes
|
414
427
|
# will be continuations of previous nodes. In that case we want to dedent
|
415
428
|
# them to match.
|
@@ -438,18 +451,52 @@ module SyntaxTree
|
|
438
451
|
# Take a source string and attempt to parse it into a set of attributes
|
439
452
|
# that can be used to format the source.
|
440
453
|
def parse_attributes(source)
|
441
|
-
|
442
|
-
|
454
|
+
source = source.strip
|
455
|
+
source = source.start_with?("{") ? source : "{#{source}}"
|
443
456
|
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
457
|
+
program = SyntaxTree.parse(source)
|
458
|
+
return PlainPart.new(source) if program.nil?
|
459
|
+
|
460
|
+
node = program.statements.body.first
|
461
|
+
return PlainPart.new(source) unless node.is_a?(HashLiteral)
|
462
|
+
|
463
|
+
HashAttributesPart.new(parse_attributes_hash(source, node))
|
464
|
+
rescue Parser::ParseError
|
465
|
+
PlainPart.new(source)
|
466
|
+
end
|
467
|
+
|
468
|
+
def parse_attributes_hash(source, node, level = 1)
|
469
|
+
node.assocs.to_h do |assoc|
|
470
|
+
key =
|
471
|
+
case assoc.key
|
472
|
+
when StringLiteral
|
473
|
+
format(assoc.key)
|
474
|
+
when Label
|
475
|
+
assoc.key.value.delete_suffix(":")
|
476
|
+
when DynaSymbol
|
477
|
+
format(assoc.key).delete_prefix(":")
|
478
|
+
else
|
479
|
+
format(assoc.key)
|
480
|
+
end
|
481
|
+
|
482
|
+
value =
|
483
|
+
case assoc.value
|
484
|
+
when HashLiteral
|
485
|
+
parse_attributes_hash(source, assoc.value, level + 1)
|
486
|
+
when StringLiteral
|
487
|
+
assoc.value
|
488
|
+
else
|
489
|
+
LiteralHashValue.new(format(assoc.value, level * 2).lstrip)
|
490
|
+
end
|
491
|
+
|
492
|
+
[key, value]
|
450
493
|
end
|
451
494
|
end
|
452
495
|
|
496
|
+
def format(node, column = 0)
|
497
|
+
SyntaxTree::Formatter.format(+"", node, column)
|
498
|
+
end
|
499
|
+
|
453
500
|
def with_children(node)
|
454
501
|
if node.children.empty?
|
455
502
|
q.group { yield }
|
data/syntax_tree-haml.gemspec
CHANGED
@@ -24,10 +24,9 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
25
|
spec.require_paths = %w[lib]
|
26
26
|
|
27
|
-
|
28
|
-
spec.add_dependency "haml", ">= 5.2", "!= 6.0.0"
|
27
|
+
spec.add_dependency "haml", ">= 5.2"
|
29
28
|
spec.add_dependency "prettier_print", ">= 1.0.0"
|
30
|
-
spec.add_dependency "syntax_tree", ">=
|
29
|
+
spec.add_dependency "syntax_tree", ">= 6.0.0"
|
31
30
|
|
32
31
|
spec.add_development_dependency "bundler"
|
33
32
|
spec.add_development_dependency "minitest"
|
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
|
+
version: 4.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Newton
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: haml
|
@@ -17,9 +17,6 @@ dependencies:
|
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '5.2'
|
20
|
-
- - "!="
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: 6.0.0
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -27,9 +24,6 @@ dependencies:
|
|
27
24
|
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '5.2'
|
30
|
-
- - "!="
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: 6.0.0
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
28
|
name: prettier_print
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -50,14 +44,14 @@ dependencies:
|
|
50
44
|
requirements:
|
51
45
|
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
47
|
+
version: 6.0.0
|
54
48
|
type: :runtime
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
51
|
requirements:
|
58
52
|
- - ">="
|
59
53
|
- !ruby/object:Gem::Version
|
60
|
-
version:
|
54
|
+
version: 6.0.0
|
61
55
|
- !ruby/object:Gem::Dependency
|
62
56
|
name: bundler
|
63
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -159,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
159
153
|
- !ruby/object:Gem::Version
|
160
154
|
version: '0'
|
161
155
|
requirements: []
|
162
|
-
rubygems_version: 3.
|
156
|
+
rubygems_version: 3.4.1
|
163
157
|
signing_key:
|
164
158
|
specification_version: 4
|
165
159
|
summary: Syntax Tree support for Haml
|