w_syntax_tree-erb 0.10.0 → 0.10.2
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 -1
- data/Gemfile.lock +1 -1
- data/lib/syntax_tree/erb/format.rb +1 -1
- data/lib/syntax_tree/erb/nodes.rb +15 -0
- data/lib/syntax_tree/erb/parser.rb +17 -5
- data/lib/syntax_tree/erb/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 657167139e259c320442756b2da4ce405e3ef3df7c3c370e6cd681561c3e7de6
|
4
|
+
data.tar.gz: 7f369c4b9bb2416a533a10734a4b384496712712e9787465d96ff76661a8be6d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a4efea93faf97c4fe05e9a7af6e0dcfd488ffbdea1ad1380e4d13d2a033490cc65ce275b3311d1c1d4c50d7d59efce2552fdd4e13a8324fc8cd5d514ac1c513
|
7
|
+
data.tar.gz: 022be3662cdffa4bf6416354a1f8b518bf1ca0f84875c99d5a919519b7b48e8e8ec608f132c6e3a0f1eaeb2651a7ae337dec0b7961ea14782019205f0221faa2
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,19 @@ 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.2] - 2023-08-22
|
10
|
+
|
11
|
+
### Fixes
|
12
|
+
|
13
|
+
- Handles formatting empty documents and removing leading new-linews in files with content.
|
14
|
+
- Removes trailing whitespace from char data if it is the last element in a document, block or group.
|
15
|
+
|
16
|
+
## [0.10.1] - 2023-08-20
|
17
|
+
|
18
|
+
### Added
|
19
|
+
|
20
|
+
- Allow `DOCTYPE` to be after other tags, to work with e.g. ERB-tags on first line.
|
21
|
+
|
9
22
|
## [0.10.0] - 2023-08-20
|
10
23
|
|
11
24
|
- Changes how whitespace and newlines are handled.
|
@@ -70,7 +83,8 @@ Output:
|
|
70
83
|
- Can format a lot of .html.erb-syntax and works as a plugin to syntax_tree.
|
71
84
|
- This is still early and there are a lot of different weird syntaxes out there.
|
72
85
|
|
73
|
-
[unreleased]: https://github.com/davidwessman/syntax_tree-erb/compare/v0.10.
|
86
|
+
[unreleased]: https://github.com/davidwessman/syntax_tree-erb/compare/v0.10.1...HEAD
|
87
|
+
[0.10.1]: https://github.com/davidwessman/syntax_tree-erb/compare/v0.10.0...v0.10.1
|
74
88
|
[0.10.0]: https://github.com/davidwessman/syntax_tree-erb/compare/v0.9.5...v0.10.0
|
75
89
|
[0.9.5]: https://github.com/davidwessman/syntax_tree-erb/compare/v0.9.4...v0.9.5
|
76
90
|
[0.9.4]: https://github.com/davidwessman/syntax_tree-erb/compare/v0.9.3...v0.9.4
|
data/Gemfile.lock
CHANGED
@@ -606,6 +606,21 @@ module SyntaxTree
|
|
606
606
|
def skip?
|
607
607
|
value.value.strip.empty?
|
608
608
|
end
|
609
|
+
|
610
|
+
# Also remove trailing whitespace
|
611
|
+
def without_new_line
|
612
|
+
self.class.new(
|
613
|
+
**deconstruct_keys([]).merge(
|
614
|
+
new_line: nil,
|
615
|
+
value:
|
616
|
+
Token.new(
|
617
|
+
type: value.type,
|
618
|
+
location: value.location,
|
619
|
+
value: value.value.rstrip
|
620
|
+
)
|
621
|
+
)
|
622
|
+
)
|
623
|
+
end
|
609
624
|
end
|
610
625
|
|
611
626
|
class NewLine < Node
|
@@ -20,16 +20,16 @@ module SyntaxTree
|
|
20
20
|
def initialize(source)
|
21
21
|
@source = source
|
22
22
|
@tokens = make_tokens
|
23
|
+
@found_doctype = false
|
23
24
|
end
|
24
25
|
|
25
26
|
def parse
|
26
|
-
doctype = maybe { parse_doctype }
|
27
27
|
elements = many { parse_any_tag }
|
28
28
|
|
29
29
|
location =
|
30
30
|
elements.first.location.to(elements.last.location) if elements.any?
|
31
31
|
|
32
|
-
Document.new(elements:
|
32
|
+
Document.new(elements: elements, location: location)
|
33
33
|
end
|
34
34
|
|
35
35
|
def debug_tokens
|
@@ -44,11 +44,23 @@ module SyntaxTree
|
|
44
44
|
loop do
|
45
45
|
tag =
|
46
46
|
atleast do
|
47
|
-
maybe {
|
48
|
-
maybe {
|
49
|
-
maybe {
|
47
|
+
maybe { parse_doctype } || maybe { parse_html_comment } ||
|
48
|
+
maybe { parse_erb_tag } || maybe { parse_erb_comment } ||
|
49
|
+
maybe { parse_html_element } || maybe { parse_new_line } ||
|
50
|
+
maybe { parse_chardata }
|
50
51
|
end
|
51
52
|
|
53
|
+
if tag.is_a?(Doctype)
|
54
|
+
if @found_doctype
|
55
|
+
raise(ParseError, "Only one doctype element is allowed")
|
56
|
+
else
|
57
|
+
@found_doctype = true
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# Ignore new lines in beginning of document
|
62
|
+
next if tag.is_a?(NewLine)
|
63
|
+
|
52
64
|
# Allow skipping empty CharData
|
53
65
|
return tag unless tag.skip?
|
54
66
|
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.
|
4
|
+
version: 0.10.2
|
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-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: prettier_print
|