syntax_tree-haml 1.3.1 → 1.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0dfb86a00b3723b124c178e28e4a6af8a604aba895a495324ea151732449bde3
4
- data.tar.gz: d597c33107dc7d04b1b52dbe645b2b8b0bf0830e0dc328f83971e95305dab32f
3
+ metadata.gz: bddc6888f36d28a1f0829960a0be5a71edb719342895c68a1635f474fe977634
4
+ data.tar.gz: b56774e91f16a8521ca888824f84a4d9dbd3242837d74107add7255f3bc571d7
5
5
  SHA512:
6
- metadata.gz: b6c225f3fcbd9af942f4a6cc00ca8a018a9ebec362b18e987f3b38895164da276ceec928fc02303fcb5055b4a4d787e0224d37cea9402de94f3310171e290c87
7
- data.tar.gz: 40ae9ef5f96374fed98f1e00302bfda455e3b279f4f653c733cd806bdc52af37ee4f56bd6464b3a16442dd522a56afc23a8773d07692213d978bad16d68b87ac
6
+ metadata.gz: e9b36d29e67e7ea5424825a8344580c3560e7a49672fceb121eec6959a4e0becbb0a8481e935450c3566e6c5647062f90ad6b9411d2d8ce202d2c98b4695eece
7
+ data.tar.gz: 35dcaa252fdfe1b53bf8904feb2d312cd7c6f353bc48343f0944a030c315a9289bce62a6578f5c6d5813d992c35681cb9770abd66e2cc5ea53fab3389b8b4f7f
data/CHANGELOG.md CHANGED
@@ -6,6 +6,12 @@ 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
+
9
15
  ## [1.3.1] - 2022-08-01
10
16
 
11
17
  ### Changed
@@ -54,7 +60,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
54
60
 
55
61
  - 🎉 Initial release! 🎉
56
62
 
57
- [unreleased]: https://github.com/ruby-syntax-tree/syntax_tree-haml/compare/v1.3.1...HEAD
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
58
65
  [1.3.1]: https://github.com/ruby-syntax-tree/syntax_tree-haml/compare/v1.3.0...v1.3.1
59
66
  [1.3.0]: https://github.com/ruby-syntax-tree/syntax_tree-haml/compare/v1.2.1...v1.3.0
60
67
  [1.2.1]: https://github.com/ruby-syntax-tree/syntax_tree-haml/compare/v1.2.0...v1.2.1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- syntax_tree-haml (1.3.1)
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.2)
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,7 +22,7 @@ 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.2.1)
25
+ syntax_tree (3.6.0)
26
26
  prettier_print
27
27
  temple (0.8.2)
28
28
  tilt (2.0.11)
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 `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
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
- q.breakable(force: true)
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
- text = node.value[:text]
80
- q.text("\\") if escaped?(text)
81
- q.text(text)
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.text("&") if node.value[:escape_html]
96
-
97
- node.value[:preserve] ? q.text("~") : q.text("=")
98
-
99
- q.text(" ")
100
- q.text(node.value[:text].strip)
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
 
@@ -222,7 +243,7 @@ module SyntaxTree
222
243
  private
223
244
 
224
245
  def format_value(q, hash, level = 0)
225
- quote = SyntaxTree::Formatter::OPTIONS[:quote]
246
+ quote = q.quote
226
247
 
227
248
  q.group do
228
249
  q.text("{")
@@ -244,8 +265,7 @@ module SyntaxTree
244
265
  when LiteralHashValue
245
266
  q.text(value.value)
246
267
  when StringLiteral
247
- qq = Formatter.new("")
248
- qq.with_target(q.target) { value.format(qq) }
268
+ value.format(q)
249
269
  when String
250
270
  q.text("#{quote}#{Quotes.normalize(value, quote)}#{quote}")
251
271
  else
@@ -2,6 +2,6 @@
2
2
 
3
3
  module SyntaxTree
4
4
  module Haml
5
- VERSION = "1.3.1"
5
+ VERSION = "1.3.2"
6
6
  end
7
7
  end
@@ -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
- PrettierPrint.format(+"", maxwidth) { |q| parse(source).format(q) }
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.1
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-08-01 00:00:00.000000000 Z
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.3
155
+ rubygems_version: 3.3.21
156
156
  signing_key:
157
157
  specification_version: 4
158
158
  summary: Syntax Tree support for Haml