haml 6.0.7 → 6.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +2 -8
- data/CHANGELOG.md +35 -2
- data/REFERENCE.md +6 -7
- data/lib/haml/compiler/children_compiler.rb +45 -16
- data/lib/haml/compiler/comment_compiler.rb +14 -2
- data/lib/haml/engine.rb +2 -0
- data/lib/haml/filters/erb.rb +1 -1
- data/lib/haml/filters/tilt_base.rb +11 -1
- data/lib/haml/version.rb +1 -1
- data/lib/haml/whitespace.rb +8 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4dfc2f798a71c0128dbbbd06c47d480b24350032d376f6a36ffc555482e4e749
|
4
|
+
data.tar.gz: 421b21fd205b9ebe320da800acc44df8fb30b446629a29bbd2c46a3c3d0b0387
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c158b9e6862a0a83443a375baf329c84a5eae3928709cfa685fe68a80ed3a6e47279ec9a3be015881de78ca1b85c51d2f47a65b99b58b317da2a6e04d2e5c70
|
7
|
+
data.tar.gz: 2ab0dcc943438c1534132896b754dd671876fef85bf3980a6165181f520f74fe1382365c0b061e49018f2e86c696cf002f597b208de293e50ea292741f1cbbf9
|
data/.github/workflows/test.yml
CHANGED
@@ -25,16 +25,10 @@ jobs:
|
|
25
25
|
- truffleruby-head
|
26
26
|
steps:
|
27
27
|
- uses: actions/checkout@v2
|
28
|
+
- run: sudo apt-get update && sudo apt-get install -y nodejs libxslt-dev # nodejs for execjs, libxslt for TruffleRuby nokogiri
|
28
29
|
- name: Set up Ruby
|
29
30
|
uses: ruby/setup-ruby@v1
|
30
31
|
with:
|
31
32
|
ruby-version: ${{ matrix.ruby }}
|
32
|
-
|
33
|
-
with:
|
34
|
-
path: vendor/bundle
|
35
|
-
key: ${{ runner.os }}-${{ matrix.ruby }}-gems-${{ hashFiles('**/Gemfile.lock') }}
|
36
|
-
restore-keys: ${{ runner.os }}-gems-
|
37
|
-
- run: sudo apt-get update && sudo apt-get install -y nodejs libxslt-dev # nodejs for execjs, libxslt for TruffleRuby nokogiri
|
38
|
-
- name: bundle install
|
39
|
-
run: bundle config path vendor/bundle && bundle install -j$(nproc) --retry 3
|
33
|
+
bundler-cache: true
|
40
34
|
- run: bundle exec rake test
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,26 @@
|
|
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
|
+
|
7
|
+
## 6.0.11
|
8
|
+
|
9
|
+
* Fix a whitespace removal with `>` and an `if` statement [#1114](https://github.com/haml/haml/issues/1114)
|
10
|
+
|
11
|
+
## 6.0.10
|
12
|
+
|
13
|
+
* Evaluate :erb filter in the template context like Haml 5
|
14
|
+
|
15
|
+
## 6.0.9
|
16
|
+
|
17
|
+
* Support sass-embedded [#1112](https://github.com/haml/haml/issues/1112)
|
18
|
+
|
19
|
+
## 6.0.8
|
20
|
+
|
21
|
+
* Support interpolation in HTML comments, which has not been working since 6.0.0
|
22
|
+
[#1107](https://github.com/haml/haml/issues/1107)
|
23
|
+
|
3
24
|
## 6.0.7
|
4
25
|
|
5
26
|
* `Haml::Engine` and `Haml::Template` use StringBuffer instead of ArrayBuffer
|
@@ -58,6 +79,8 @@ Released on September 21, 2022
|
|
58
79
|
* The parser is kept as is, but everything else is replaced.
|
59
80
|
* The `haml` CLI interface was also replaced.
|
60
81
|
* The interface of `Haml::Engine` is changed. `Haml::Template` is most likely what you need now.
|
82
|
+
* before: `Haml::Engine.new("%p Haml code!").render`
|
83
|
+
* after: `Haml::Template.new { "%p Haml code!" }.render`
|
61
84
|
* Most Haml helpers are removed.
|
62
85
|
* Rails:
|
63
86
|
* Kept: `find_and_reserve`, `preserve`, `surround`, `precede`, `succeed`, `capture_haml`
|
@@ -68,9 +91,19 @@ Released on September 21, 2022
|
|
68
91
|
* Removed: `block_is_haml?`, `capture_haml`, `escape_once`, `find_and_preserve`, `flatten`, `haml_concat`,
|
69
92
|
`haml_indent`, `haml_tag`, `haml_tag_if`, `html_attrs`, `html_escape`, `init_haml_helpers`, `is_haml?`,
|
70
93
|
`list_of`, `non_haml`, `precede`, `succeed`, `surround`, `tab_down`, `tab_up`, `with_tabs`
|
71
|
-
* Only the attributes
|
72
|
-
|
94
|
+
* Only the following attributes and `aria`/`data` attributes are considered boolean attributes:
|
95
|
+
* `allowfullscreen`, `async`, `autobuffer`, `autofocus`, `autoplay`, `checked`, `controls`, `default`,
|
96
|
+
`defer`, `disabled`, `download`, `formnovalidate`, `hidden`, `inert`, `ismap`, `itemscope`, `loop`,
|
97
|
+
`multiple`, `muted`, `novalidate`, `open`, `pubdate`, `readonly`, `required`, `reversed`, `scoped`,
|
98
|
+
`seamless`, `selected`, `sortable`, `truespeed`, `typemustmatch`
|
99
|
+
* Only `data` and `aria` attributes support using a nested Hash to render hyphenated attributes, e.g.
|
100
|
+
`data: { foo: 'bar' }` becomes `data-foo="bar"`, but this no longer works for non-`data`/`aria` attributes.
|
73
101
|
* Some legacy Rails integration is removed.
|
102
|
+
* The default value of `escape_html` option became true.
|
103
|
+
* `-` script lines no longer support capturing. Only `=` lines are supported to yield a nested block.
|
104
|
+
* Overriding `data` attributes with another falsy `data-*` attribute that has the same name
|
105
|
+
is no longer supported. [#1105](https://github.com/haml/haml/issues/1105)
|
106
|
+
* :erb filter is not executed in the template context (fixed in 6.0.10)
|
74
107
|
|
75
108
|
## 5.2.2
|
76
109
|
|
data/REFERENCE.md
CHANGED
@@ -338,20 +338,19 @@ will render as:
|
|
338
338
|
<a> tag is so old links to here still work. -->
|
339
339
|
<a id="html5_custom_data_attributes" style="border:0;"></a>
|
340
340
|
|
341
|
-
####
|
341
|
+
#### Data Attributes
|
342
342
|
|
343
343
|
HTML5 allows for adding
|
344
344
|
[custom non-visible data attributes](http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#embedding-custom-non-visible-data-with-the-data-*-attributes)
|
345
345
|
to elements using attribute names beginning with `data-`. The
|
346
346
|
[Accessible Rich Internet Applications](http://www.w3.org/WAI/intro/aria)
|
347
|
-
specification makes use of attributes beginning with `aria-`.
|
348
|
-
frameworks that use non-standard attributes with a common prefix.
|
347
|
+
specification makes use of attributes beginning with `aria-`.
|
349
348
|
|
350
349
|
Haml can help generate collections of attributes that share a prefix like
|
351
|
-
these. Any entry in an attribute hash that has a Hash as its
|
352
|
-
into a series of attributes, one for each key/value pair in
|
353
|
-
attribute name formed by joining the “parent” key name to
|
354
|
-
hyphen.
|
350
|
+
these. Any entry in an `data` or `aria` attribute hash that has a Hash as its
|
351
|
+
value is expanded into a series of attributes, one for each key/value pair in
|
352
|
+
the hash, with the attribute name formed by joining the “parent” key name to
|
353
|
+
the key name with a hyphen. This works only for `data` or `aria`.
|
355
354
|
|
356
355
|
For example:
|
357
356
|
|
@@ -6,21 +6,22 @@ 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)
|
12
13
|
temple = [:multi]
|
13
14
|
return temple if node.children.empty?
|
14
15
|
|
15
|
-
temple << :whitespace if prepend_whitespace?(node)
|
16
|
+
temple << [:whitespace] if prepend_whitespace?(node)
|
16
17
|
node.children.each do |n|
|
17
18
|
rstrip_whitespace!(temple) if nuke_prev_whitespace?(n)
|
18
19
|
insert_newlines!(temple, n)
|
19
20
|
temple << moving_lineno(n) { block.call(n) }
|
20
|
-
temple << :whitespace if insert_whitespace?(n)
|
21
|
+
temple << [:whitespace] if insert_whitespace?(n)
|
21
22
|
end
|
22
23
|
rstrip_whitespace!(temple) if nuke_inner_whitespace?(node)
|
23
|
-
|
24
|
+
temple
|
24
25
|
end
|
25
26
|
|
26
27
|
private
|
@@ -56,17 +57,6 @@ module Haml
|
|
56
57
|
temple
|
57
58
|
end
|
58
59
|
|
59
|
-
def confirm_whitespace(temple)
|
60
|
-
temple.map do |exp|
|
61
|
-
case exp
|
62
|
-
when :whitespace
|
63
|
-
[:static, "\n"]
|
64
|
-
else
|
65
|
-
exp
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
60
|
def prepend_whitespace?(node)
|
71
61
|
return false unless %i[comment tag].include?(node.type)
|
72
62
|
!nuke_inner_whitespace?(node)
|
@@ -100,9 +90,48 @@ module Haml
|
|
100
90
|
end
|
101
91
|
|
102
92
|
def rstrip_whitespace!(temple)
|
103
|
-
if temple
|
104
|
-
|
93
|
+
return if temple.size == 1
|
94
|
+
|
95
|
+
case temple[0]
|
96
|
+
when :multi
|
97
|
+
case temple[-1][0]
|
98
|
+
when :whitespace
|
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
|
132
|
+
end
|
105
133
|
end
|
134
|
+
nil
|
106
135
|
end
|
107
136
|
|
108
137
|
def insert_whitespace?(node)
|
@@ -14,7 +14,7 @@ module Haml
|
|
14
14
|
|
15
15
|
def compile_html_comment(node, &block)
|
16
16
|
if node.children.empty?
|
17
|
-
[:html, :comment,
|
17
|
+
[:html, :comment, compile_text(node)]
|
18
18
|
else
|
19
19
|
[:html, :comment, yield(node)]
|
20
20
|
end
|
@@ -28,12 +28,24 @@ module Haml
|
|
28
28
|
|
29
29
|
content =
|
30
30
|
if node.children.empty?
|
31
|
-
|
31
|
+
compile_text(node)
|
32
32
|
else
|
33
33
|
yield(node)
|
34
34
|
end
|
35
35
|
[:html, :condcomment, condition, content, node.value[:revealed]]
|
36
36
|
end
|
37
|
+
|
38
|
+
def compile_text(node)
|
39
|
+
text =
|
40
|
+
if node.value[:parse]
|
41
|
+
# Just always escaping the result for safety. We could respect
|
42
|
+
# escape_html, but I don't see any use case for it.
|
43
|
+
[:escape, true, [:dynamic, node.value[:text]]]
|
44
|
+
else
|
45
|
+
[:static, node.value[:text]]
|
46
|
+
end
|
47
|
+
[:multi, [:static, ' '], text, [:static, ' ']]
|
48
|
+
end
|
37
49
|
end
|
38
50
|
end
|
39
51
|
end
|
data/lib/haml/engine.rb
CHANGED
@@ -8,6 +8,7 @@ require 'haml/escapable'
|
|
8
8
|
require 'haml/force_escapable'
|
9
9
|
require 'haml/dynamic_merger'
|
10
10
|
require 'haml/ambles'
|
11
|
+
require 'haml/whitespace'
|
11
12
|
|
12
13
|
module Haml
|
13
14
|
class Engine < Temple::Engine
|
@@ -36,6 +37,7 @@ module Haml
|
|
36
37
|
filter :ControlFlow
|
37
38
|
use Ambles
|
38
39
|
filter :MultiFlattener
|
40
|
+
use Whitespace
|
39
41
|
filter :StaticMerger
|
40
42
|
use DynamicMerger
|
41
43
|
use :Generator, -> { options[:generator] }
|
data/lib/haml/filters/erb.rb
CHANGED
@@ -7,7 +7,11 @@ module Haml
|
|
7
7
|
def self.render(name, source, indent_width: 0)
|
8
8
|
text = ::Tilt["t.#{name}"].new { source }.render
|
9
9
|
return text if indent_width == 0
|
10
|
-
text.
|
10
|
+
if text.frozen?
|
11
|
+
text.gsub(/^/, ' ' * indent_width)
|
12
|
+
else
|
13
|
+
text.gsub!(/^/, ' ' * indent_width)
|
14
|
+
end
|
11
15
|
end
|
12
16
|
|
13
17
|
def explicit_require?(needed_registration)
|
@@ -17,6 +21,12 @@ module Haml
|
|
17
21
|
|
18
22
|
private
|
19
23
|
|
24
|
+
# TODO: support interpolation
|
25
|
+
def precompiled_with_tilt(node, name)
|
26
|
+
src = ::Tilt["t.#{name}"].new { node.value[:text] }.send(:precompiled, {}).first
|
27
|
+
[:dynamic, src]
|
28
|
+
end
|
29
|
+
|
20
30
|
def compile_with_tilt(node, name, indent_width: 0)
|
21
31
|
if ::Haml::Util.contains_interpolation?(node.value[:text])
|
22
32
|
dynamic_compile(node, name, indent_width: indent_width)
|
data/lib/haml/version.rb
CHANGED
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.
|
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-
|
15
|
+
date: 2022-11-27 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: temple
|
@@ -334,6 +334,7 @@ files:
|
|
334
334
|
- lib/haml/temple_line_counter.rb
|
335
335
|
- lib/haml/util.rb
|
336
336
|
- lib/haml/version.rb
|
337
|
+
- lib/haml/whitespace.rb
|
337
338
|
homepage: https://haml.info
|
338
339
|
licenses:
|
339
340
|
- MIT
|
@@ -353,7 +354,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
353
354
|
- !ruby/object:Gem::Version
|
354
355
|
version: '0'
|
355
356
|
requirements: []
|
356
|
-
rubygems_version: 3.
|
357
|
+
rubygems_version: 3.4.0.dev
|
357
358
|
signing_key:
|
358
359
|
specification_version: 4
|
359
360
|
summary: An elegant, structured (X)HTML/XML templating engine.
|