haml 6.0.11-java → 6.1.0-java

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: 31849c95695d5db575f824528a49044c948bd030c9716a38d94db197269079ce
4
- data.tar.gz: 931c560f376df2ba100ae8524e345807e990303fdb6b8cc8f6a8a37a3b761dd5
3
+ metadata.gz: 147595059b4f0b4101d22c513864c0c84d80150e45aaf01056f5aa107bc813cf
4
+ data.tar.gz: a5b64fa5da7a110d35ac3dda6474850fc5e6ea58cdde991663c65aaa3b4c0afb
5
5
  SHA512:
6
- metadata.gz: a064605dc7436fa9cb8bbb143c029cf37cc25c9c5ff2ece1d5225c4b0c5ef54f4314bc014f71550d66f26dd8a64ce800553642a94263488719d60856efcb6b74
7
- data.tar.gz: 8a61fafa65f148a3548feddc7e65a801ce75f08f1ac256a4a5e2bf1d7940ff6a6016b4b6d13d3c4228ab96e3980b63e07a9fcd3bcffcba2fcc7ac8253d3c49e3
6
+ metadata.gz: 30b7b6705eef6a9501d7a6c62178c07045cba98473ef0b49d788d166bc7d7dbaa64dee2524bd9159c296a31f5b9a3d33bb13d98473e7b0c6fcdc9fb080224491
7
+ data.tar.gz: 1313af8b1a09c826712e72aec31241bf7fb8f08ed6a7b00648868b4043dd16da3941e5c93afbb3fb0785436cca5e807220b78fb02009513d348595de4c5f5c45
@@ -14,6 +14,7 @@ jobs:
14
14
  test:
15
15
  runs-on: ubuntu-latest
16
16
  strategy:
17
+ fail-fast: false
17
18
  matrix:
18
19
  ruby:
19
20
  - '2.5'
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Haml Changelog
2
2
 
3
+ ## 6.1.0
4
+
5
+ * Optimize away a `to_s` call on `=` scripts
6
+ * Fix escaping for objects that return an `html_safe` string on `to_s` [#1117](https://github.com/haml/haml/issues/1117)
7
+
8
+ ## 6.0.12
9
+
10
+ * Fix a whitespace removal with `>` and an `if`-`else` statement [#1114](https://github.com/haml/haml/issues/1114)
11
+
3
12
  ## 6.0.11
4
13
 
5
14
  * 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)
@@ -98,10 +98,8 @@ module Haml
98
98
  def compile_script_result(result, node)
99
99
  if !node.value[:escape_html] && node.value[:preserve]
100
100
  result = find_and_preserve(result)
101
- else
102
- result = "(#{result}).to_s"
103
101
  end
104
- [:escape, node.value[:escape_html], [:dynamic, result]]
102
+ [:escapeany, node.value[:escape_html], [:dynamic, result]]
105
103
  end
106
104
 
107
105
  def find_and_preserve(code)
data/lib/haml/engine.rb CHANGED
@@ -4,8 +4,9 @@ require 'haml/parser'
4
4
  require 'haml/compiler'
5
5
  require 'haml/html'
6
6
  require 'haml/string_splitter'
7
- require 'haml/escapable'
8
- require 'haml/force_escapable'
7
+ require 'haml/escape'
8
+ require 'haml/escape_any'
9
+ require 'haml/force_escape'
9
10
  require 'haml/dynamic_merger'
10
11
  require 'haml/ambles'
11
12
  require 'haml/whitespace'
@@ -32,8 +33,9 @@ module Haml
32
33
  use HTML
33
34
  use StringSplitter
34
35
  filter :StaticAnalyzer
35
- use Escapable
36
- use ForceEscapable
36
+ use Escape
37
+ use EscapeAny
38
+ use ForceEscape
37
39
  filter :ControlFlow
38
40
  use Ambles
39
41
  filter :MultiFlattener
@@ -2,7 +2,7 @@
2
2
  require 'haml/util'
3
3
 
4
4
  module Haml
5
- class Escapable < Temple::Filters::Escapable
5
+ class Escape < Temple::Filters::Escapable
6
6
  def initialize(opts = {})
7
7
  super
8
8
  @escape_code = options[:escape_code] ||
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+ require 'haml/escape'
3
+
4
+ module Haml
5
+ # This module allows Temple::Filter to dispatch :fescape on `#compile`.
6
+ module EscapeanyDispathcer
7
+ def on_escapeany(flag, exp)
8
+ [:escapeany, flag, compile(exp)]
9
+ end
10
+ end
11
+ ::Temple::Filter.include EscapeanyDispathcer
12
+
13
+ # Unlike Haml::Escape, this calls to_s when not escaped.
14
+ class EscapeAny < Escape
15
+ alias_method :on_escapeany, :on_escape
16
+
17
+ def on_dynamic(value)
18
+ [:dynamic, @escape ? @escape_code % value : "(#{value}).to_s"]
19
+ end
20
+ end
21
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- require 'haml/escapable'
2
+ require 'haml/escape'
3
3
 
4
4
  module Haml
5
5
  # This module allows Temple::Filter to dispatch :fescape on `#compile`.
@@ -10,8 +10,8 @@ module Haml
10
10
  end
11
11
  ::Temple::Filter.include FescapeDispathcer
12
12
 
13
- # Unlike Haml::Escapable, this escapes value even if it's html_safe.
14
- class ForceEscapable < Escapable
13
+ # Unlike Haml::Escape, this escapes value even if it's html_safe.
14
+ class ForceEscape < Escape
15
15
  def initialize(opts = {})
16
16
  super
17
17
  @escape_code = options[:escape_code] || "::Haml::Util.escape_html((%s))"
@@ -20,8 +20,8 @@ module Haml
20
20
 
21
21
  alias_method :on_fescape, :on_escape
22
22
 
23
- # ForceEscapable doesn't touch :escape expression.
24
- # This method is not used if it's inserted after Haml::Escapable.
23
+ # ForceEscape doesn't touch :escape expression.
24
+ # This method is not used if it's inserted after Haml::Escape.
25
25
  def on_escape(flag, exp)
26
26
  [:escape, flag, compile(exp)]
27
27
  end
@@ -52,4 +52,6 @@ end
52
52
 
53
53
  # Haml extends Haml::Helpers in ActionView each time.
54
54
  # It costs much, so Haml includes a compatible module at first.
55
- ActionView::Base.send :include, Haml::RailsHelpers
55
+ ActiveSupport.on_load(:action_view) do
56
+ include Haml::RailsHelpers
57
+ end
data/lib/haml/util.rb CHANGED
@@ -27,6 +27,7 @@ module Haml
27
27
 
28
28
  # TODO: Remove unescape_interpolation's workaround and get rid of `respond_to?`.
29
29
  def self.escape_html_safe(html)
30
+ html = html.to_s
30
31
  (html.respond_to?(:html_safe?) && html.html_safe?) ? html : escape_html(html)
31
32
  end
32
33
 
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.1.0'
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.1.0
5
5
  platform: java
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-12-10 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  requirement: !ruby/object:Gem::Requirement
@@ -300,7 +300,8 @@ files:
300
300
  - lib/haml/dynamic_merger.rb
301
301
  - lib/haml/engine.rb
302
302
  - lib/haml/error.rb
303
- - lib/haml/escapable.rb
303
+ - lib/haml/escape.rb
304
+ - lib/haml/escape_any.rb
304
305
  - lib/haml/filters.rb
305
306
  - lib/haml/filters/base.rb
306
307
  - lib/haml/filters/cdata.rb
@@ -318,7 +319,7 @@ files:
318
319
  - lib/haml/filters/scss.rb
319
320
  - lib/haml/filters/text_base.rb
320
321
  - lib/haml/filters/tilt_base.rb
321
- - lib/haml/force_escapable.rb
322
+ - lib/haml/force_escape.rb
322
323
  - lib/haml/helpers.rb
323
324
  - lib/haml/html.rb
324
325
  - lib/haml/identity.rb