From e1219e6baeb934e450ab8784752ff540e0494687 Mon Sep 17 00:00:00 2001 From: Radon Rosborough Date: Thu, 22 Sep 2022 15:10:14 -0700 Subject: [PATCH 1/4] Add support for Ruby 2.7.0 --- .github/workflows/main.yml | 3 ++- CHANGELOG.md | 4 ++++ Gemfile.lock | 2 +- lib/syntax_tree/haml/format.rb | 4 ++-- lib/syntax_tree/haml/version.rb | 2 +- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 83b450b..11ede67 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,7 +8,8 @@ jobs: fail-fast: false matrix: ruby: - - '2.7' + - '2.7.0' + - '2.7.5' - '3.0' - '3.1' name: CI diff --git a/CHANGELOG.md b/CHANGELOG.md index ac6f8e6..37ba700 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a ## [Unreleased] +### Added + +- Support for Ruby 2.7.0, not just 2.7.3 + ## [1.3.2] - 2022-09-19 ### Added diff --git a/Gemfile.lock b/Gemfile.lock index 8af5b03..df3cd90 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - syntax_tree-haml (1.3.2) + syntax_tree-haml (1.3.3) haml (>= 5.2) prettier_print syntax_tree (>= 2.0.1) diff --git a/lib/syntax_tree/haml/format.rb b/lib/syntax_tree/haml/format.rb index c7ad4e2..7e9e5e1 100644 --- a/lib/syntax_tree/haml/format.rb +++ b/lib/syntax_tree/haml/format.rb @@ -6,7 +6,7 @@ class Format < Visitor class Formatter < ::SyntaxTree::Formatter attr_reader :literal_lines, :quote - def initialize(source, ...) + def initialize(source, *rest) @literal_lines = {} source .lines @@ -15,7 +15,7 @@ def initialize(source, ...) @literal_lines[index] = line.rstrip if line.start_with?("!") end - super(source, ...) + super(source, *rest) end end diff --git a/lib/syntax_tree/haml/version.rb b/lib/syntax_tree/haml/version.rb index 2220e46..ccdf1ae 100644 --- a/lib/syntax_tree/haml/version.rb +++ b/lib/syntax_tree/haml/version.rb @@ -2,6 +2,6 @@ module SyntaxTree module Haml - VERSION = "1.3.2" + VERSION = "1.3.3" end end From caf213bcae0ec39b58d40b1045bbc2b9bf1a28e7 Mon Sep 17 00:00:00 2001 From: Radon Rosborough Date: Thu, 22 Sep 2022 15:32:12 -0700 Subject: [PATCH 2/4] Assume that AttributeParser will always be available --- lib/syntax_tree/haml/format.rb | 12 ++++-------- test/tag_test.rb | 11 ----------- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/lib/syntax_tree/haml/format.rb b/lib/syntax_tree/haml/format.rb index 7e9e5e1..8553060 100644 --- a/lib/syntax_tree/haml/format.rb +++ b/lib/syntax_tree/haml/format.rb @@ -330,15 +330,11 @@ def visit_tag(node) if node.value[:dynamic_attributes].old parts << PlainPart.new("%div") if parts.empty? - if ::Haml::AttributeParser.available? - dynamic = parse_attributes(node.value[:dynamic_attributes].old) - parts << if dynamic.is_a?(LiteralHashValue) - PlainPart.new(dynamic.value) - else - HashAttributesPart.new(dynamic) - end + dynamic = parse_attributes(node.value[:dynamic_attributes].old) + parts << if dynamic.is_a?(LiteralHashValue) + PlainPart.new(dynamic.value) else - parts << PlainPart.new(node.value[:dynamic_attributes].old) + HashAttributesPart.new(dynamic) end end diff --git a/test/tag_test.rb b/test/tag_test.rb index 4b3781c..51dc4df 100644 --- a/test/tag_test.rb +++ b/test/tag_test.rb @@ -121,17 +121,6 @@ def test_long_declaration_before_text HAML end - def test_long_declaration_before_text_without_parser - long = "a" * 80 - - ::Haml::AttributeParser.stub(:available?, false) do - assert_format("%button{ data: { current: #{long} } } foo", <<~HAML) - %button{ data: { current: #{long} } } - foo - HAML - end - end - def test_quotes_in_strings assert_format("%div{title: 'escape \" quotes'}") end From 86ea684ca13320ea53fb1c36c0d762536afdc622 Mon Sep 17 00:00:00 2001 From: Radon Rosborough Date: Thu, 29 Sep 2022 13:15:14 -0700 Subject: [PATCH 3/4] Revert "Assume that AttributeParser will always be available" This reverts commit caf213bcae0ec39b58d40b1045bbc2b9bf1a28e7. We can continue using the existing method in haml 6.0.1 per https://github.com/haml/haml/issues/1085. --- lib/syntax_tree/haml/format.rb | 12 ++++++++---- test/tag_test.rb | 11 +++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/syntax_tree/haml/format.rb b/lib/syntax_tree/haml/format.rb index 8553060..7e9e5e1 100644 --- a/lib/syntax_tree/haml/format.rb +++ b/lib/syntax_tree/haml/format.rb @@ -330,11 +330,15 @@ def visit_tag(node) if node.value[:dynamic_attributes].old parts << PlainPart.new("%div") if parts.empty? - dynamic = parse_attributes(node.value[:dynamic_attributes].old) - parts << if dynamic.is_a?(LiteralHashValue) - PlainPart.new(dynamic.value) + if ::Haml::AttributeParser.available? + dynamic = parse_attributes(node.value[:dynamic_attributes].old) + parts << if dynamic.is_a?(LiteralHashValue) + PlainPart.new(dynamic.value) + else + HashAttributesPart.new(dynamic) + end else - HashAttributesPart.new(dynamic) + parts << PlainPart.new(node.value[:dynamic_attributes].old) end end diff --git a/test/tag_test.rb b/test/tag_test.rb index 51dc4df..4b3781c 100644 --- a/test/tag_test.rb +++ b/test/tag_test.rb @@ -121,6 +121,17 @@ def test_long_declaration_before_text HAML end + def test_long_declaration_before_text_without_parser + long = "a" * 80 + + ::Haml::AttributeParser.stub(:available?, false) do + assert_format("%button{ data: { current: #{long} } } foo", <<~HAML) + %button{ data: { current: #{long} } } + foo + HAML + end + end + def test_quotes_in_strings assert_format("%div{title: 'escape \" quotes'}") end From 5e93c13744f94f99076a5687e7fb9ff0736d72a1 Mon Sep 17 00:00:00 2001 From: Radon Rosborough Date: Thu, 29 Sep 2022 13:18:33 -0700 Subject: [PATCH 4/4] Update haml dependency --- Gemfile.lock | 6 +++--- syntax_tree-haml.gemspec | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index df3cd90..1de60d3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,7 +2,7 @@ PATH remote: . specs: syntax_tree-haml (1.3.3) - haml (>= 5.2) + haml (>= 5.2, != 6.0.0) prettier_print syntax_tree (>= 2.0.1) @@ -10,7 +10,7 @@ GEM remote: https://rubygems.org/ specs: docile (1.4.0) - haml (6.0.0) + haml (6.0.3) temple (>= 0.8.2) thor tilt @@ -23,7 +23,7 @@ GEM simplecov_json_formatter (~> 0.1) simplecov-html (0.12.3) simplecov_json_formatter (0.1.4) - syntax_tree (3.6.0) + syntax_tree (3.6.1) prettier_print temple (0.8.2) thor (1.2.1) diff --git a/syntax_tree-haml.gemspec b/syntax_tree-haml.gemspec index 31bf160..b891092 100644 --- a/syntax_tree-haml.gemspec +++ b/syntax_tree-haml.gemspec @@ -24,7 +24,8 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = %w[lib] - spec.add_dependency "haml", ">= 5.2" + # Can't use 6.0.0 due to https://github.com/haml/haml/issues/1085 + spec.add_dependency "haml", ">= 5.2", "!= 6.0.0" spec.add_dependency "prettier_print" spec.add_dependency "syntax_tree", ">= 2.0.1"