Skip to content

Commit 9eeabc5

Browse files
committed
Bump to v1.3.0
1 parent be05c74 commit 9eeabc5

File tree

5 files changed

+47
-4
lines changed

5 files changed

+47
-4
lines changed

CHANGELOG.md

+6
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+
## [1.3.0] - 2022-07-22
10+
11+
### Added
12+
13+
- Support changing the preferred quote through the single quotes plugin.
14+
915
## [1.2.1] - 2022-07-22
1016

1117
### Changed

Gemfile.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
syntax_tree-haml (1.2.1)
4+
syntax_tree-haml (1.3.0)
55
haml (>= 5.2)
66
prettier_print
77
syntax_tree (>= 2.0.1)

lib/syntax_tree/haml/format.rb

+8-2
Original file line numberDiff line numberDiff line change
@@ -245,15 +245,21 @@ def format_value(q, hash, level = 0)
245245
end
246246

247247
def self.hash_key(key)
248-
key.match?(/^@|[-:]/) ? "\"#{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
249254
end
250255

251256
def self.hash_value(value)
252257
case value
253258
when LiteralHashValue
254259
value.value
255260
when String
256-
"\"#{Quotes.normalize(value, "\"")}\""
261+
quote = SyntaxTree::Formatter::OPTIONS[:quote]
262+
"#{quote}#{Quotes.normalize(value, quote)}#{quote}"
257263
else
258264
value.to_s
259265
end

lib/syntax_tree/haml/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
module SyntaxTree
44
module Haml
5-
VERSION = "1.2.1"
5+
VERSION = "1.3.0"
66
end
77
end

test/tag_test.rb

+31
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ def test_dynamic_attributes_nested_hash
5555
assert_format("%div{data: { controller: \"lesson-evaluation\" }}")
5656
end
5757

58+
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
65+
end
66+
5867
def test_dynamic_attributes_integers
5968
assert_format("%span{foo: 1}")
6069
end
@@ -74,6 +83,15 @@ def test_dynamic_attributes_strings
7483
)
7584
end
7685

86+
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
93+
end
94+
7795
def test_dynamic_attributes_with_at
7896
assert_format("%span{\"@click\": \"open = true\"}")
7997
end
@@ -124,4 +142,17 @@ def test_quotes_in_strings
124142
def test_interpolation_in_value
125143
assert_format("%p <small>hello</small>\"\#{1 + 2} little pigs\"")
126144
end
145+
146+
private
147+
148+
def with_single_quotes
149+
quote = SyntaxTree::Formatter::OPTIONS[:quote]
150+
SyntaxTree::Formatter::OPTIONS[:quote] = "'"
151+
152+
begin
153+
yield
154+
ensure
155+
SyntaxTree::Formatter::OPTIONS[:quote] = quote
156+
end
157+
end
127158
end

0 commit comments

Comments
 (0)