syntax_tree-haml 1.3.0 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -1
- data/Gemfile.lock +4 -4
- data/README.md +1 -1
- data/lib/syntax_tree/haml/format.rb +55 -39
- data/lib/syntax_tree/haml/version.rb +1 -1
- data/lib/syntax_tree/haml.rb +5 -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: bddc6888f36d28a1f0829960a0be5a71edb719342895c68a1635f474fe977634
|
4
|
+
data.tar.gz: b56774e91f16a8521ca888824f84a4d9dbd3242837d74107add7255f3bc571d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9b36d29e67e7ea5424825a8344580c3560e7a49672fceb121eec6959a4e0becbb0a8481e935450c3566e6c5647062f90ad6b9411d2d8ce202d2c98b4695eece
|
7
|
+
data.tar.gz: 35dcaa252fdfe1b53bf8904feb2d312cd7c6f353bc48343f0944a030c315a9289bce62a6578f5c6d5813d992c35681cb9770abd66e2cc5ea53fab3389b8b4f7f
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,18 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [1.3.2] - 2022-09-19
|
10
|
+
|
11
|
+
### Added
|
12
|
+
|
13
|
+
- Properly support unescaping plain and script.
|
14
|
+
|
15
|
+
## [1.3.1] - 2022-08-01
|
16
|
+
|
17
|
+
### Changed
|
18
|
+
|
19
|
+
- Use Syntax Tree to handle properly quoting strings.
|
20
|
+
|
9
21
|
## [1.3.0] - 2022-07-22
|
10
22
|
|
11
23
|
### Added
|
@@ -48,7 +60,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
|
|
48
60
|
|
49
61
|
- 🎉 Initial release! 🎉
|
50
62
|
|
51
|
-
[unreleased]: https://github.com/ruby-syntax-tree/syntax_tree-haml/compare/v1.2
|
63
|
+
[unreleased]: https://github.com/ruby-syntax-tree/syntax_tree-haml/compare/v1.3.2...HEAD
|
64
|
+
[1.3.2]: https://github.com/ruby-syntax-tree/syntax_tree-haml/compare/v1.3.1...v1.3.2
|
65
|
+
[1.3.1]: https://github.com/ruby-syntax-tree/syntax_tree-haml/compare/v1.3.0...v1.3.1
|
66
|
+
[1.3.0]: https://github.com/ruby-syntax-tree/syntax_tree-haml/compare/v1.2.1...v1.3.0
|
52
67
|
[1.2.1]: https://github.com/ruby-syntax-tree/syntax_tree-haml/compare/v1.2.0...v1.2.1
|
53
68
|
[1.2.0]: https://github.com/ruby-syntax-tree/syntax_tree-haml/compare/v1.1.0...v1.2.0
|
54
69
|
[1.1.0]: https://github.com/ruby-syntax-tree/syntax_tree-haml/compare/v1.0.1...v1.1.0
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
syntax_tree-haml (1.3.
|
4
|
+
syntax_tree-haml (1.3.2)
|
5
5
|
haml (>= 5.2)
|
6
6
|
prettier_print
|
7
7
|
syntax_tree (>= 2.0.1)
|
@@ -13,7 +13,7 @@ GEM
|
|
13
13
|
haml (5.2.2)
|
14
14
|
temple (>= 0.8.0)
|
15
15
|
tilt
|
16
|
-
minitest (5.16.
|
16
|
+
minitest (5.16.3)
|
17
17
|
prettier_print (0.1.0)
|
18
18
|
rake (13.0.6)
|
19
19
|
simplecov (0.21.2)
|
@@ -22,10 +22,10 @@ GEM
|
|
22
22
|
simplecov_json_formatter (~> 0.1)
|
23
23
|
simplecov-html (0.12.3)
|
24
24
|
simplecov_json_formatter (0.1.4)
|
25
|
-
syntax_tree (3.
|
25
|
+
syntax_tree (3.6.0)
|
26
26
|
prettier_print
|
27
27
|
temple (0.8.2)
|
28
|
-
tilt (2.0.
|
28
|
+
tilt (2.0.11)
|
29
29
|
|
30
30
|
PLATFORMS
|
31
31
|
ruby
|
data/README.md
CHANGED
@@ -55,7 +55,7 @@ template.haml 1ms
|
|
55
55
|
|
56
56
|
## Development
|
57
57
|
|
58
|
-
After checking out the repo, run `
|
58
|
+
After checking out the repo, run `bundle install` to install dependencies. Then, run `rake test` to run the tests. You can also run `bundle console` for an interactive prompt that will allow you to experiment.
|
59
59
|
|
60
60
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
61
61
|
|
@@ -3,6 +3,22 @@
|
|
3
3
|
module SyntaxTree
|
4
4
|
module Haml
|
5
5
|
class Format < Visitor
|
6
|
+
class Formatter < ::SyntaxTree::Formatter
|
7
|
+
attr_reader :literal_lines, :quote
|
8
|
+
|
9
|
+
def initialize(source, ...)
|
10
|
+
@literal_lines = {}
|
11
|
+
source
|
12
|
+
.lines
|
13
|
+
.each
|
14
|
+
.with_index(1) do |line, index|
|
15
|
+
@literal_lines[index] = line.rstrip if line.start_with?("!")
|
16
|
+
end
|
17
|
+
|
18
|
+
super(source, ...)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
6
22
|
attr_reader :q
|
7
23
|
|
8
24
|
def initialize(q)
|
@@ -62,12 +78,11 @@ module SyntaxTree
|
|
62
78
|
text = node.value[:text].strip
|
63
79
|
|
64
80
|
if text.include?("\n")
|
81
|
+
separator = -> { q.breakable(force: true) }
|
82
|
+
|
65
83
|
q.indent do
|
66
|
-
|
67
|
-
q.seplist(
|
68
|
-
text.split("\n"),
|
69
|
-
-> { q.breakable(force: true) }
|
70
|
-
) { |segment| q.text(segment) }
|
84
|
+
separator.call
|
85
|
+
q.seplist(text.split("\n"), separator) { |segment| q.text(segment) }
|
71
86
|
end
|
72
87
|
else
|
73
88
|
q.text(" #{text}")
|
@@ -76,9 +91,13 @@ module SyntaxTree
|
|
76
91
|
|
77
92
|
# https://haml.info/docs/yardoc/file.REFERENCE.html#plain-text
|
78
93
|
def visit_plain(node)
|
79
|
-
|
80
|
-
|
81
|
-
|
94
|
+
if line = q.literal_lines[node.line]
|
95
|
+
q.text(line)
|
96
|
+
else
|
97
|
+
text = node.value[:text]
|
98
|
+
q.text("\\") if escaped?(text)
|
99
|
+
q.text(text)
|
100
|
+
end
|
82
101
|
end
|
83
102
|
|
84
103
|
# Visit the root node of the AST.
|
@@ -92,12 +111,14 @@ module SyntaxTree
|
|
92
111
|
# https://haml.info/docs/yardoc/file.REFERENCE.html#inserting_ruby
|
93
112
|
def visit_script(node)
|
94
113
|
with_children(node) do
|
95
|
-
q.
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
114
|
+
if line = q.literal_lines[node.line]
|
115
|
+
q.text(line)
|
116
|
+
else
|
117
|
+
q.text("&") if node.value[:escape_html]
|
118
|
+
q.text(node.value[:preserve] ? "~" : "=")
|
119
|
+
q.text(" ")
|
120
|
+
q.text(node.value[:text].strip)
|
121
|
+
end
|
101
122
|
end
|
102
123
|
end
|
103
124
|
|
@@ -123,6 +144,8 @@ module SyntaxTree
|
|
123
144
|
|
124
145
|
LiteralHashValue = Struct.new(:value)
|
125
146
|
|
147
|
+
StringHashValue = Struct.new(:value, :quote)
|
148
|
+
|
126
149
|
# When formatting a tag, there are a lot of different kinds of things that
|
127
150
|
# can be printed out. There's the tag name, the attributes, the content,
|
128
151
|
# etc. This object is responsible for housing all of those parts.
|
@@ -220,19 +243,33 @@ module SyntaxTree
|
|
220
243
|
private
|
221
244
|
|
222
245
|
def format_value(q, hash, level = 0)
|
246
|
+
quote = q.quote
|
247
|
+
|
223
248
|
q.group do
|
224
249
|
q.text("{")
|
225
250
|
q.indent do
|
226
251
|
q.group do
|
227
252
|
q.breakable(level == 0 ? "" : " ")
|
228
253
|
q.seplist(hash, nil, :each_pair) do |key, value|
|
229
|
-
|
254
|
+
if key.match?(/^@|[-:]/)
|
255
|
+
q.text("#{quote}#{Quotes.normalize(key, quote)}#{quote}:")
|
256
|
+
else
|
257
|
+
q.text("#{key}:")
|
258
|
+
end
|
259
|
+
|
230
260
|
q.text(" ")
|
231
261
|
|
232
|
-
|
262
|
+
case value
|
263
|
+
when Hash
|
233
264
|
format_value(q, value, level + 1)
|
265
|
+
when LiteralHashValue
|
266
|
+
q.text(value.value)
|
267
|
+
when StringLiteral
|
268
|
+
value.format(q)
|
269
|
+
when String
|
270
|
+
q.text("#{quote}#{Quotes.normalize(value, quote)}#{quote}")
|
234
271
|
else
|
235
|
-
q.text(
|
272
|
+
q.text(value.to_s)
|
236
273
|
end
|
237
274
|
end
|
238
275
|
end
|
@@ -244,27 +281,6 @@ module SyntaxTree
|
|
244
281
|
end
|
245
282
|
end
|
246
283
|
|
247
|
-
def self.hash_key(key)
|
248
|
-
if key.match?(/^@|[-:]/)
|
249
|
-
quote = SyntaxTree::Formatter::OPTIONS[:quote]
|
250
|
-
"#{quote}#{Quotes.normalize(key, quote)}#{quote}:"
|
251
|
-
else
|
252
|
-
"#{key}:"
|
253
|
-
end
|
254
|
-
end
|
255
|
-
|
256
|
-
def self.hash_value(value)
|
257
|
-
case value
|
258
|
-
when LiteralHashValue
|
259
|
-
value.value
|
260
|
-
when String
|
261
|
-
quote = SyntaxTree::Formatter::OPTIONS[:quote]
|
262
|
-
"#{quote}#{Quotes.normalize(value, quote)}#{quote}"
|
263
|
-
else
|
264
|
-
value.to_s
|
265
|
-
end
|
266
|
-
end
|
267
|
-
|
268
284
|
# Visit a tag node.
|
269
285
|
def visit_tag(node)
|
270
286
|
parts = PartList.new(node)
|
@@ -405,7 +421,7 @@ module SyntaxTree
|
|
405
421
|
::Haml::AttributeParser.parse(source)
|
406
422
|
parsed.to_h { |key, value| [key, parse_attributes(value)] }
|
407
423
|
in [:program, [[:string_literal, *], *]]
|
408
|
-
source[
|
424
|
+
SyntaxTree.parse(source).statements.body[0]
|
409
425
|
else
|
410
426
|
LiteralHashValue.new(source)
|
411
427
|
end
|
data/lib/syntax_tree/haml.rb
CHANGED
@@ -34,7 +34,11 @@ module SyntaxTree
|
|
34
34
|
# This is the main entrypoint for the formatter. It parses the source,
|
35
35
|
# builds a formatter, then pretty prints the result.
|
36
36
|
def self.format(source, maxwidth = 80)
|
37
|
-
|
37
|
+
formatter = Format::Formatter.new(source, +"", maxwidth)
|
38
|
+
parse(source).format(formatter)
|
39
|
+
|
40
|
+
formatter.flush
|
41
|
+
formatter.output
|
38
42
|
end
|
39
43
|
|
40
44
|
# This is a required API for syntax tree which just delegates to File.read.
|
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: 1.3.
|
4
|
+
version: 1.3.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: 2022-
|
11
|
+
date: 2022-09-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: haml
|
@@ -152,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
152
|
- !ruby/object:Gem::Version
|
153
153
|
version: '0'
|
154
154
|
requirements: []
|
155
|
-
rubygems_version: 3.3.
|
155
|
+
rubygems_version: 3.3.21
|
156
156
|
signing_key:
|
157
157
|
specification_version: 4
|
158
158
|
summary: Syntax Tree support for Haml
|