Skip to content

Commit 8a657a9

Browse files
authored
Merge pull request #57 from ruby-syntax-tree/update-to-stree-5
Update to Syntax Tree version 5.0.0
2 parents e11e7c6 + 1207573 commit 8a657a9

File tree

7 files changed

+41
-38
lines changed

7 files changed

+41
-38
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
66

77
## [Unreleased]
88

9+
## [3.0.0] - 2022-11-10
10+
11+
### Changed
12+
13+
- Required syntax_tree version 5.0.1 or higher.
14+
915
## [2.0.0] - 2022-10-18
1016

1117
### Added
@@ -72,7 +78,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
7278

7379
- 🎉 Initial release! 🎉
7480

75-
[unreleased]: https://github.com/ruby-syntax-tree/syntax_tree-haml/compare/v2.0.0...HEAD
81+
[unreleased]: https://github.com/ruby-syntax-tree/syntax_tree-haml/compare/v3.0.0...HEAD
82+
[3.0.0]: https://github.com/ruby-syntax-tree/syntax_tree-haml/compare/v2.0.0...v3.0.0
7683
[2.0.0]: https://github.com/ruby-syntax-tree/syntax_tree-haml/compare/v1.3.2...v2.0.0
7784
[1.3.2]: https://github.com/ruby-syntax-tree/syntax_tree-haml/compare/v1.3.1...v1.3.2
7885
[1.3.1]: https://github.com/ruby-syntax-tree/syntax_tree-haml/compare/v1.3.0...v1.3.1

Gemfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ PATH
44
syntax_tree-haml (2.0.0)
55
haml (>= 5.2, != 6.0.0)
66
prettier_print (>= 1.0.0)
7-
syntax_tree (>= 4.0.0)
7+
syntax_tree (>= 5.0.1)
88

99
GEM
1010
remote: https://rubygems.org/
1111
specs:
1212
docile (1.4.0)
13-
haml (6.0.9)
13+
haml (6.0.10)
1414
temple (>= 0.8.2)
1515
thor
1616
tilt
@@ -23,7 +23,7 @@ GEM
2323
simplecov_json_formatter (~> 0.1)
2424
simplecov-html (0.12.3)
2525
simplecov_json_formatter (0.1.4)
26-
syntax_tree (5.0.0)
26+
syntax_tree (5.0.1)
2727
prettier_print (>= 1.1.0)
2828
temple (0.9.1)
2929
thor (1.2.1)

lib/syntax_tree/haml.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ def self.parse(source)
3333

3434
# This is the main entrypoint for the formatter. It parses the source,
3535
# builds a formatter, then pretty prints the result.
36-
def self.format(source, maxwidth = 80)
37-
formatter = Format::Formatter.new(source, +"", maxwidth)
36+
def self.format(source, maxwidth = 80, options: Formatter::Options.new)
37+
formatter = Format::Formatter.new(source, +"", maxwidth, options: options)
3838
parse(source).format(formatter)
3939

4040
formatter.flush

lib/syntax_tree/haml/format.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ module SyntaxTree
44
module Haml
55
class Format < Visitor
66
class Formatter < ::SyntaxTree::Formatter
7-
attr_reader :literal_lines, :quote
7+
attr_reader :literal_lines
88

9-
def initialize(source, *rest)
9+
def initialize(
10+
source,
11+
*rest,
12+
options: ::SyntaxTree::Formatter::Options.new
13+
)
1014
@literal_lines = {}
1115
source
1216
.lines
@@ -15,7 +19,7 @@ def initialize(source, *rest)
1519
@literal_lines[index] = line.rstrip if line.start_with?("!")
1620
end
1721

18-
super(source, *rest)
22+
super(source, *rest, options: options)
1923
end
2024
end
2125

syntax_tree-haml.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
2727
# Can't use 6.0.0 due to https://github.com/haml/haml/issues/1085
2828
spec.add_dependency "haml", ">= 5.2", "!= 6.0.0"
2929
spec.add_dependency "prettier_print", ">= 1.0.0"
30-
spec.add_dependency "syntax_tree", ">= 4.0.0"
30+
spec.add_dependency "syntax_tree", ">= 5.0.1"
3131

3232
spec.add_development_dependency "bundler"
3333
spec.add_development_dependency "minitest"

test/tag_test.rb

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,11 @@ def test_dynamic_attributes_nested_hash
5656
end
5757

5858
def test_dynamic_attributes_nested_hash_single_quotes
59-
with_single_quotes do
60-
assert_format(
61-
"%div{data: { controller: \"lesson-evaluation\" }}",
62-
"%div{data: { controller: 'lesson-evaluation' }}"
63-
)
64-
end
59+
assert_format(
60+
"%div{data: { controller: \"lesson-evaluation\" }}",
61+
"%div{data: { controller: 'lesson-evaluation' }}",
62+
options: SyntaxTree::Formatter::Options.new(quote: "'")
63+
)
6564
end
6665

6766
def test_dynamic_attributes_integers
@@ -84,12 +83,11 @@ def test_dynamic_attributes_strings
8483
end
8584

8685
def test_dynamic_attributes_strings_single_quotes
87-
with_single_quotes do
88-
assert_format(
89-
"%section(xml:lang=\"en\" title=\"title\")",
90-
"%section{'xml:lang': 'en', title: 'title'}"
91-
)
92-
end
86+
assert_format(
87+
"%section(xml:lang=\"en\" title=\"title\")",
88+
"%section{'xml:lang': 'en', title: 'title'}",
89+
options: SyntaxTree::Formatter::Options.new(quote: "'")
90+
)
9391
end
9492

9593
def test_dynamic_attributes_with_at
@@ -137,25 +135,15 @@ def test_quotes_in_strings
137135
end
138136

139137
def test_interpolation_in_strings
140-
with_single_quotes { assert_format(<<~HAML) }
138+
source = <<~HAML
141139
%div{style: "background: center/cover url(\#{url_for(page.resource.file)})"}
142140
HAML
141+
142+
options = SyntaxTree::Formatter::Options.new(quote: "'")
143+
assert_format(source, options: options)
143144
end
144145

145146
def test_interpolation_in_value
146147
assert_format("%p <small>hello</small>\"\#{1 + 2} little pigs\"")
147148
end
148-
149-
private
150-
151-
def with_single_quotes
152-
quote = SyntaxTree::Formatter::OPTIONS[:quote]
153-
SyntaxTree::Formatter::OPTIONS[:quote] = "'"
154-
155-
begin
156-
yield
157-
ensure
158-
SyntaxTree::Formatter::OPTIONS[:quote] = quote
159-
end
160-
end
161149
end

test/test_helper.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515
class Minitest::Test
1616
private
1717

18-
def assert_format(source, expected = nil)
18+
def assert_format(
19+
source,
20+
expected = nil,
21+
options: ::SyntaxTree::Formatter::Options.new
22+
)
1923
# Adding a bit of code here just to make sure the pretty-printing gets
2024
# executed as part of this. Not going to actually assert against it since
2125
# it's more of a nice-to-have and the actual format is not strict.
@@ -26,7 +30,7 @@ def assert_format(source, expected = nil)
2630
# result is what we expect.
2731
assert_equal(
2832
(expected || source).strip,
29-
SyntaxTree::Haml.format(source.dup).strip
33+
SyntaxTree::Haml.format(source.dup, options: options).strip
3034
)
3135
end
3236
end

0 commit comments

Comments
 (0)