haml 6.0.11 → 6.0.12

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: 1775ac3d762a6136ef378f69b5522a73b98dfe5ce5a4727c06a061e3d6ceb989
4
- data.tar.gz: '06938ad9c4452c051d39dbc1d03bd352fa260a4f3768afb3bcce66f3f3b81b70'
3
+ metadata.gz: 4dfc2f798a71c0128dbbbd06c47d480b24350032d376f6a36ffc555482e4e749
4
+ data.tar.gz: 421b21fd205b9ebe320da800acc44df8fb30b446629a29bbd2c46a3c3d0b0387
5
5
  SHA512:
6
- metadata.gz: ac77e8fd0f76d1bdec1092f34e95b438ce0e85477d7eb5a9a973f8ab1d95327be035eac8b70589cb043d99a7ab5bb9d112136ca21c022d2f157239d99aea62a7
7
- data.tar.gz: c76565dda6a32822dfb98a8c808b7dfe8c0b640cc59516bf2c69cb6b51aa1605aafbe506d747a67c26c35f46e09f342bf4493191cd8cfb71f100c146ea74c935
6
+ metadata.gz: 5c158b9e6862a0a83443a375baf329c84a5eae3928709cfa685fe68a80ed3a6e47279ec9a3be015881de78ca1b85c51d2f47a65b99b58b317da2a6e04d2e5c70
7
+ data.tar.gz: 2ab0dcc943438c1534132896b754dd671876fef85bf3980a6165181f520f74fe1382365c0b061e49018f2e86c696cf002f597b208de293e50ea292741f1cbbf9
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Haml Changelog
2
2
 
3
+ ## 6.0.12
4
+
5
+ * Fix a whitespace removal with `>` and an `if`-`else` statement [#1114](https://github.com/haml/haml/issues/1114)
6
+
3
7
  ## 6.0.11
4
8
 
5
9
  * Fix a whitespace removal with `>` and an `if` statement [#1114](https://github.com/haml/haml/issues/1114)
@@ -6,6 +6,7 @@ module Haml
6
6
  class ChildrenCompiler
7
7
  def initialize
8
8
  @lineno = 1
9
+ @multi_flattener = Temple::Filters::MultiFlattener.new
9
10
  end
10
11
 
11
12
  def compile(node, &block)
@@ -89,15 +90,48 @@ module Haml
89
90
  end
90
91
 
91
92
  def rstrip_whitespace!(temple)
93
+ return if temple.size == 1
94
+
92
95
  case temple[0]
93
- when :multi, :block
96
+ when :multi
94
97
  case temple[-1][0]
95
- when :multi, :block
96
- rstrip_whitespace!(temple[-1])
97
98
  when :whitespace
98
99
  temple.delete_at(-1)
100
+ when :multi, :block
101
+ rstrip_whitespace!(temple[-1])
102
+ end
103
+ when :block
104
+ _block, code, exp = temple
105
+ if code.start_with?(/\s*if\s/)
106
+ # Remove [:whitespace] before `end`
107
+ exp.replace(@multi_flattener.call(exp))
108
+ rstrip_whitespace!(exp)
109
+
110
+ # Remove [:whitespace] before `else` if exists
111
+ else_index = find_else_index(exp)
112
+ if else_index
113
+ whitespace_index = else_index - 1
114
+ while exp[whitespace_index] == [:newline]
115
+ whitespace_index -= 1
116
+ end
117
+ if exp[whitespace_index] == [:whitespace]
118
+ exp.delete_at(whitespace_index)
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
124
+
125
+ def find_else_index(temple)
126
+ multi, *args = temple
127
+ return nil if multi != :multi
128
+
129
+ args.each_with_index do |arg, index|
130
+ if arg[0] == :code && arg[1].match?(/\A\s*else\s*\z/)
131
+ return index + 1
99
132
  end
100
133
  end
134
+ nil
101
135
  end
102
136
 
103
137
  def insert_whitespace?(node)
data/lib/haml/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Haml
3
- VERSION = '6.0.11'
3
+ VERSION = '6.0.12'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haml
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.11
4
+ version: 6.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Natalie Weizenbaum
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: exe
14
14
  cert_chain: []
15
- date: 2022-11-26 00:00:00.000000000 Z
15
+ date: 2022-11-27 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: temple