syntax_tree-haml 2.0.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 61fd378df6679c193bda86bdb1f1f78de949b0978c7ec02ec114e1d8fadcd3b5
4
- data.tar.gz: 1011cad24c3f91ab3086c14b9dda49c6a0093d20c8d3af8fc86286e8dd8851ed
3
+ metadata.gz: 93531550f281631f3aa86988c3309f3a48250bd6e218c3712013bbcc1a590480
4
+ data.tar.gz: f8cf31bae239650f86a13dd8d0bdda41c5eab011bbd1ae829656df387b22b1bf
5
5
  SHA512:
6
- metadata.gz: 3cfb430120300e2fe6a593a7a47e8be22c09d160960b5a6f6d324e117827d752c648d6111c47d664a8d137cff584aa5fb856d93241c5f7edf2be2360e7e8f8c4
7
- data.tar.gz: 4e4597ea20a6514cc10ff326db244616ebdd41f11d71095f76ca4aabfb1a1c355e76620e024223ff761e5f9f5bcd0eb868ca62323b2ba669a202da8c0ba13d55
6
+ metadata.gz: caac6d625f266b6ac4d5808065573f2ae70de84ad3670cbed2c1cea8089e75e1f8986e5391f0349975ff0d1cb32a65aa114e3d3578207be46b8637358162f06a
7
+ data.tar.gz: fc8b9c900b04d1a6536ac7d7299d66be150111d11989f855e5bfd17820939fefca789f09fd8c830e761721a3ffc396c2a54865792e9c242e66de498efe5aef8d
data/CHANGELOG.md CHANGED
@@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [3.0.0] - 2022-12-23
10
+
11
+ ### Changed
12
+
13
+ - Required syntax_tree version 5.0.1 or higher.
14
+ - Drop internal pattern matching in order to support Ruby implementations that don't support it.
15
+
9
16
  ## [2.0.0] - 2022-10-18
10
17
 
11
18
  ### Added
@@ -72,7 +79,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
72
79
 
73
80
  - 🎉 Initial release! 🎉
74
81
 
75
- [unreleased]: https://github.com/ruby-syntax-tree/syntax_tree-haml/compare/v2.0.0...HEAD
82
+ [unreleased]: https://github.com/ruby-syntax-tree/syntax_tree-haml/compare/v3.0.0...HEAD
83
+ [3.0.0]: https://github.com/ruby-syntax-tree/syntax_tree-haml/compare/v2.0.0...v3.0.0
76
84
  [2.0.0]: https://github.com/ruby-syntax-tree/syntax_tree-haml/compare/v1.3.2...v2.0.0
77
85
  [1.3.2]: https://github.com/ruby-syntax-tree/syntax_tree-haml/compare/v1.3.1...v1.3.2
78
86
  [1.3.1]: https://github.com/ruby-syntax-tree/syntax_tree-haml/compare/v1.3.0...v1.3.1
data/Gemfile.lock CHANGED
@@ -1,21 +1,21 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- syntax_tree-haml (2.0.0)
4
+ syntax_tree-haml (3.0.0)
5
5
  haml (>= 5.2, != 6.0.0)
6
6
  prettier_print (>= 1.0.0)
7
- syntax_tree (>= 4.0.0)
7
+ syntax_tree (>= 5.0.1)
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
12
  docile (1.4.0)
13
- haml (6.0.7)
13
+ haml (6.1.1)
14
14
  temple (>= 0.8.2)
15
15
  thor
16
16
  tilt
17
17
  minitest (5.16.3)
18
- prettier_print (1.0.1)
18
+ prettier_print (1.1.0)
19
19
  rake (13.0.6)
20
20
  simplecov (0.21.2)
21
21
  docile (~> 1.1)
@@ -23,9 +23,9 @@ GEM
23
23
  simplecov_json_formatter (~> 0.1)
24
24
  simplecov-html (0.12.3)
25
25
  simplecov_json_formatter (0.1.4)
26
- syntax_tree (4.0.1)
27
- prettier_print (>= 1.0.1)
28
- temple (0.8.2)
26
+ syntax_tree (5.0.1)
27
+ prettier_print (>= 1.1.0)
28
+ temple (0.9.1)
29
29
  thor (1.2.1)
30
30
  tilt (2.0.11)
31
31
 
@@ -4,9 +4,13 @@ module SyntaxTree
4
4
  module Haml
5
5
  class Format < Visitor
6
6
  class Formatter < ::SyntaxTree::Formatter
7
- attr_reader :literal_lines, :quote
7
+ attr_reader :literal_lines
8
8
 
9
- def initialize(source, *rest)
9
+ def initialize(
10
+ source,
11
+ *rest,
12
+ options: ::SyntaxTree::Formatter::Options.new
13
+ )
10
14
  @literal_lines = {}
11
15
  source
12
16
  .lines
@@ -15,7 +19,7 @@ module SyntaxTree
15
19
  @literal_lines[index] = line.rstrip if line.start_with?("!")
16
20
  end
17
21
 
18
- super(source, *rest)
22
+ super(source, *rest, options: options)
19
23
  end
20
24
  end
21
25
 
@@ -412,11 +416,11 @@ module SyntaxTree
412
416
  def continuation?(node, child)
413
417
  return false if child.type != :silent_script
414
418
 
415
- case [node.value[:keyword], child.value[:keyword]]
416
- in ["case", "in" | "when" | "else"]
417
- true
418
- in ["if" | "unless", "elsif" | "else"]
419
- true
419
+ case node.value[:keyword]
420
+ when "case"
421
+ %w[in when else].include?(child.value[:keyword])
422
+ when "if", "unless"
423
+ %w[elsif else].include?(child.value[:keyword])
420
424
  else
421
425
  false
422
426
  end
@@ -434,11 +438,12 @@ module SyntaxTree
434
438
  # Take a source string and attempt to parse it into a set of attributes
435
439
  # that can be used to format the source.
436
440
  def parse_attributes(source)
437
- case Ripper.sexp(source)
438
- in [:program, [[:hash, *], *]] if parsed =
439
- ::Haml::AttributeParser.parse(source)
441
+ program = Ripper.sexp(source)
442
+ type = program && program[1][0][0]
443
+
444
+ if type == :hash && (parsed = ::Haml::AttributeParser.parse(source))
440
445
  parsed.to_h { |key, value| [key, parse_attributes(value)] }
441
- in [:program, [[:string_literal, *], *]]
446
+ elsif type == :string_literal
442
447
  SyntaxTree.parse(source).statements.body[0]
443
448
  else
444
449
  LiteralHashValue.new(source)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module SyntaxTree
4
4
  module Haml
5
- VERSION = "2.0.0"
5
+ VERSION = "3.0.0"
6
6
  end
7
7
  end
@@ -33,8 +33,8 @@ module SyntaxTree
33
33
 
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
- 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)
38
38
  parse(source).format(formatter)
39
39
 
40
40
  formatter.flush
@@ -59,24 +59,26 @@ class Haml::Parser::ParseNode
59
59
  # accept a visitor in order to walk through the tree.
60
60
  def accept(visitor)
61
61
  case type
62
- in :comment
62
+ when :comment
63
63
  visitor.visit_comment(self)
64
- in :doctype
64
+ when :doctype
65
65
  visitor.visit_doctype(self)
66
- in :filter
66
+ when :filter
67
67
  visitor.visit_filter(self)
68
- in :haml_comment
68
+ when :haml_comment
69
69
  visitor.visit_haml_comment(self)
70
- in :plain
70
+ when :plain
71
71
  visitor.visit_plain(self)
72
- in :root
72
+ when :root
73
73
  visitor.visit_root(self)
74
- in :script
74
+ when :script
75
75
  visitor.visit_script(self)
76
- in :silent_script
76
+ when :silent_script
77
77
  visitor.visit_silent_script(self)
78
- in :tag
78
+ when :tag
79
79
  visitor.visit_tag(self)
80
+ else
81
+ raise "Unknown node type: #{type}"
80
82
  end
81
83
  end
82
84
 
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
27
27
  # Can't use 6.0.0 due to https://github.com/haml/haml/issues/1085
28
28
  spec.add_dependency "haml", ">= 5.2", "!= 6.0.0"
29
29
  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"
31
31
 
32
32
  spec.add_development_dependency "bundler"
33
33
  spec.add_development_dependency "minitest"
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: 2.0.0
4
+ version: 3.0.0
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-10-18 00:00:00.000000000 Z
11
+ date: 2022-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: haml
@@ -50,14 +50,14 @@ dependencies:
50
50
  requirements:
51
51
  - - ">="
52
52
  - !ruby/object:Gem::Version
53
- version: 4.0.0
53
+ version: 5.0.1
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - ">="
59
59
  - !ruby/object:Gem::Version
60
- version: 4.0.0
60
+ version: 5.0.1
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: bundler
63
63
  requirement: !ruby/object:Gem::Requirement