haml 6.0.3 → 6.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +23 -2
- data/REFERENCE.md +39 -1
- data/Rakefile +8 -67
- data/lib/haml/engine.rb +3 -1
- data/lib/haml/object_ref.rb +6 -1
- data/lib/haml/string_splitter.rb +131 -11
- data/lib/haml/util.rb +4 -5
- data/lib/haml/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e9efb6d42c07f38f08e6406c470be766f751439a63c0b151aca4040d5ea583d8
|
4
|
+
data.tar.gz: 8bcc4b22a87eb105e380990aa1fcfee19c9cf1ae61467e9bb9c3130f81977279
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07ebd7d512eac2b19e8d8d2d2611064a4742ead90ad9e6570e7612dd45535797d4479aa169371105a37f9f9ba32e6066337ef4a772b7430c7d2ac3a519d34ebb
|
7
|
+
data.tar.gz: 2fae2a68a205536580450fdd0c1ee1ab2c7f14268a01cc65b225f2115a1b3ee529865c2c184fc9b18e7a2141f6cb08d7a2254f14e0a7d5f61bde477387a114f9
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
# Haml Changelog
|
2
2
|
|
3
|
+
## 6.0.5
|
4
|
+
|
5
|
+
* Resurrect `#haml_object_ref` support in an object reference [#1097](https://github.com/haml/haml/issues/1097)
|
6
|
+
* This was removed in 6.0.0, and added back in this version.
|
7
|
+
* Stop warning `remove_whitespace: true` option.
|
8
|
+
|
9
|
+
## 6.0.4
|
10
|
+
|
11
|
+
Released on October 2, 2022
|
12
|
+
([diff](https://github.com/haml/haml/compare/v6.0.3...v6.0.4)).
|
13
|
+
|
14
|
+
* Fix a parse failure of `%` in attributes [#1096](https://github.com/haml/haml/issues/1096)
|
15
|
+
* Add another fallback from C to Ruby for Wasm.
|
16
|
+
|
3
17
|
## 6.0.3
|
4
18
|
|
5
19
|
Released on September 28, 2022
|
@@ -34,8 +48,15 @@ Released on September 21, 2022
|
|
34
48
|
* The `haml` CLI interface was also replaced.
|
35
49
|
* The interface of `Haml::Engine` is changed. `Haml::Template` is most likely what you need now.
|
36
50
|
* Most Haml helpers are removed.
|
37
|
-
*
|
38
|
-
|
51
|
+
* Rails:
|
52
|
+
* Kept: `find_and_reserve`, `preserve`, `surround`, `precede`, `succeed`, `capture_haml`
|
53
|
+
* Removed: `block_is_haml?`, `flatten`, `haml_concat`, `haml_indent`, `haml_tag`, `haml_tag_if`, `html_attrs`,
|
54
|
+
`html_escape`, `init_haml_helpers`, `is_haml?`, `list_of`, `non_haml`, `tab_down`, `tab_up`, `with_tabs`
|
55
|
+
* Tilt:
|
56
|
+
* Kept: `preserve`
|
57
|
+
* Removed: `block_is_haml?`, `capture_haml`, `escape_once`, `find_and_preserve`, `flatten`, `haml_concat`,
|
58
|
+
`haml_indent`, `haml_tag`, `haml_tag_if`, `html_attrs`, `html_escape`, `init_haml_helpers`, `is_haml?`,
|
59
|
+
`list_of`, `non_haml`, `precede`, `succeed`, `surround`, `tab_down`, `tab_up`, `with_tabs`
|
39
60
|
* Only the attributes in [`Haml::AttributeBuilder::BOOLEAN_ATTRIBUTES`](lib/haml/attribute_builder.rb)
|
40
61
|
are handled as boolean attributes.
|
41
62
|
* Some legacy Rails integration is removed.
|
data/REFERENCE.md
CHANGED
@@ -81,6 +81,32 @@ You can then use it by including the `haml` gem in Ruby code, and using
|
|
81
81
|
engine = Haml::Template.new { "%p Haml code!" }
|
82
82
|
engine.render #=> "<p>Haml code!</p>\n"
|
83
83
|
|
84
|
+
### Options
|
85
|
+
|
86
|
+
Haml understands various configuration options that affect its performance and
|
87
|
+
output.
|
88
|
+
|
89
|
+
In Rails, options can be set by using `Haml::RailsTemplate.set_options` in an initializer:
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
# config/initializers/haml.rb
|
93
|
+
Haml::RailsTemplate.set_options(escape_html: false)
|
94
|
+
```
|
95
|
+
|
96
|
+
Outside Rails, you can set them by configuring them globally in `Haml::Template.options`:
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
Haml::Template.options[:escape_html] = false
|
100
|
+
```
|
101
|
+
|
102
|
+
In sinatra specifically, you can set them in global config with:
|
103
|
+
```ruby
|
104
|
+
set :haml, { escape_html: false }
|
105
|
+
```
|
106
|
+
|
107
|
+
Finally, you can also set them by passing an options hash to `Haml::Engine.new` or `Haml::Template.new`.
|
108
|
+
For the complete list of available options, please see `Haml::Engine`.
|
109
|
+
|
84
110
|
## Plain Text
|
85
111
|
|
86
112
|
A substantial portion of any HTML document is its content, which is plain old
|
@@ -294,7 +320,19 @@ or using `true` and `false`:
|
|
294
320
|
%input(selected=true)
|
295
321
|
|
296
322
|
This feature works only for attributes that are included in
|
297
|
-
[`Haml::AttributeBuilder::BOOLEAN_ATTRIBUTES`](lib/haml/attribute_builder.rb)
|
323
|
+
[`Haml::AttributeBuilder::BOOLEAN_ATTRIBUTES`](lib/haml/attribute_builder.rb),
|
324
|
+
as well as `data-` and `aria-` attributes.
|
325
|
+
|
326
|
+
%input{'data-hidden' => false}
|
327
|
+
%input{'aria-hidden' => false}
|
328
|
+
%input{'xyz-hidden' => false}
|
329
|
+
|
330
|
+
will render as:
|
331
|
+
|
332
|
+
<input>
|
333
|
+
<input>
|
334
|
+
<input xyz-hidden='false'>
|
335
|
+
|
298
336
|
|
299
337
|
<!-- The title to the next section (Prefixed Attributes) has changed. This
|
300
338
|
<a> tag is so old links to here still work. -->
|
data/Rakefile
CHANGED
@@ -35,72 +35,14 @@ end
|
|
35
35
|
|
36
36
|
Dir['benchmark/*.rake'].each { |b| import(b) }
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
t.test_files = files
|
45
|
-
t.verbose = true
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
namespace :hamlit do
|
50
|
-
Rake::TestTask.new do |t|
|
51
|
-
t.libs << 'lib' << 'test'
|
52
|
-
t.ruby_opts = %w[-rtest_helper]
|
53
|
-
t.test_files = Dir['test/hamlit/**/*_test.rb']
|
54
|
-
t.verbose = true
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
namespace :test do
|
59
|
-
Rake::TestTask.new(:all) do |t|
|
60
|
-
t.libs << 'lib' << 'test'
|
61
|
-
files = Dir['test/hamlit/**/*_test.rb']
|
62
|
-
files += Dir['test/haml/*_test.rb']
|
63
|
-
files << 'test/haml/haml-spec/*_test.rb'
|
64
|
-
t.ruby_opts = %w[-rtest_helper]
|
65
|
-
t.test_files = files
|
66
|
-
t.verbose = true
|
67
|
-
end
|
68
|
-
|
69
|
-
Rake::TestTask.new(:spec) do |t|
|
70
|
-
t.libs << 'lib' << 'test'
|
71
|
-
t.ruby_opts = %w[-rtest_helper]
|
72
|
-
t.test_files = %w[test/haml/haml-spec/ugly_test.rb test/haml/haml-spec/pretty_test.rb]
|
73
|
-
t.verbose = true
|
74
|
-
end
|
75
|
-
|
76
|
-
Rake::TestTask.new(:engine) do |t|
|
77
|
-
t.libs << 'lib' << 'test'
|
78
|
-
t.ruby_opts = %w[-rtest_helper]
|
79
|
-
t.test_files = %w[test/haml/engine_test.rb]
|
80
|
-
t.verbose = true
|
81
|
-
end
|
82
|
-
|
83
|
-
Rake::TestTask.new(:filters) do |t|
|
84
|
-
t.libs << 'lib' << 'test'
|
85
|
-
t.ruby_opts = %w[-rtest_helper]
|
86
|
-
t.test_files = %w[test/haml/filters_test.rb]
|
87
|
-
t.verbose = true
|
88
|
-
end
|
89
|
-
|
90
|
-
Rake::TestTask.new(:helper) do |t|
|
91
|
-
t.libs << 'lib' << 'test'
|
92
|
-
t.ruby_opts = %w[-rtest_helper]
|
93
|
-
t.test_files = %w[test/haml/helper_test.rb]
|
94
|
-
t.verbose = true
|
95
|
-
end
|
96
|
-
|
97
|
-
Rake::TestTask.new(:template) do |t|
|
98
|
-
t.libs << 'lib' << 'test'
|
99
|
-
t.ruby_opts = %w[-rtest_helper]
|
100
|
-
t.test_files = %w[test/haml/template_test.rb]
|
101
|
-
t.verbose = true
|
102
|
-
end
|
38
|
+
Rake::TestTask.new do |t|
|
39
|
+
t.libs << 'lib' << 'test'
|
40
|
+
files = Dir['test/haml/**/*_test.rb']
|
41
|
+
t.ruby_opts = %w[-rtest_helper]
|
42
|
+
t.test_files = files
|
43
|
+
t.verbose = true
|
103
44
|
end
|
45
|
+
task test: :compile
|
104
46
|
|
105
47
|
desc 'bench task for CI'
|
106
48
|
task bench: :compile do
|
@@ -137,5 +79,4 @@ task(:doc => 'doc:sass') {sh "yard"}
|
|
137
79
|
desc "Generate documentation incrementally"
|
138
80
|
task(:redoc) {sh "yard -c"}
|
139
81
|
|
140
|
-
task default: %w[compile
|
141
|
-
task test: %w[compile test:all]
|
82
|
+
task default: %w[compile test]
|
data/lib/haml/engine.rb
CHANGED
@@ -3,6 +3,7 @@ require 'temple'
|
|
3
3
|
require 'haml/parser'
|
4
4
|
require 'haml/compiler'
|
5
5
|
require 'haml/html'
|
6
|
+
require 'haml/string_splitter'
|
6
7
|
require 'haml/escapable'
|
7
8
|
require 'haml/force_escapable'
|
8
9
|
require 'haml/dynamic_merger'
|
@@ -22,12 +23,13 @@ module Haml
|
|
22
23
|
param source track wbr),
|
23
24
|
filename: "",
|
24
25
|
disable_capture: false,
|
26
|
+
remove_whitespace: false,
|
25
27
|
)
|
26
28
|
|
27
29
|
use Parser
|
28
30
|
use Compiler
|
29
31
|
use HTML
|
30
|
-
|
32
|
+
use StringSplitter
|
31
33
|
filter :StaticAnalyzer
|
32
34
|
use Escapable
|
33
35
|
use ForceEscapable
|
data/lib/haml/object_ref.rb
CHANGED
@@ -6,7 +6,12 @@ module Haml
|
|
6
6
|
object, prefix = args
|
7
7
|
return {} unless object
|
8
8
|
|
9
|
-
suffix =
|
9
|
+
suffix =
|
10
|
+
if object.respond_to?(:haml_object_ref)
|
11
|
+
object.haml_object_ref
|
12
|
+
else
|
13
|
+
underscore(object.class)
|
14
|
+
end
|
10
15
|
{
|
11
16
|
'class' => [prefix, suffix].compact.join('_'),
|
12
17
|
'id' => [prefix, suffix, object.id || 'new'].compact.join('_'),
|
data/lib/haml/string_splitter.rb
CHANGED
@@ -1,19 +1,139 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require '
|
2
|
+
begin
|
3
|
+
require 'ripper'
|
4
|
+
rescue LoadError
|
5
|
+
end
|
4
6
|
|
5
7
|
module Haml
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
# Compile [:dynamic, "foo#{bar}"] to [:multi, [:static, 'foo'], [:dynamic, 'bar']]
|
9
|
+
class StringSplitter < Temple::Filter
|
10
|
+
if defined?(Ripper) && RUBY_VERSION >= "2.0.0" && Ripper.respond_to?(:lex)
|
11
|
+
class << self
|
12
|
+
# `code` param must be valid string literal
|
13
|
+
def compile(code)
|
14
|
+
[].tap do |exps|
|
15
|
+
tokens = Ripper.lex(code.strip)
|
16
|
+
tokens.pop while tokens.last && [:on_comment, :on_sp].include?(tokens.last[1])
|
17
|
+
|
18
|
+
if tokens.size < 2
|
19
|
+
raise(Haml::InternalError, "Expected token size >= 2 but got: #{tokens.size}")
|
20
|
+
end
|
21
|
+
compile_tokens!(exps, tokens)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def strip_quotes!(tokens)
|
28
|
+
_, type, beg_str = tokens.shift
|
29
|
+
if type != :on_tstring_beg
|
30
|
+
raise(Haml::InternalError, "Expected :on_tstring_beg but got: #{type}")
|
31
|
+
end
|
32
|
+
|
33
|
+
_, type, end_str = tokens.pop
|
34
|
+
if type != :on_tstring_end
|
35
|
+
raise(Haml::InternalError, "Expected :on_tstring_end but got: #{type}")
|
36
|
+
end
|
37
|
+
|
38
|
+
[beg_str, end_str]
|
39
|
+
end
|
40
|
+
|
41
|
+
def compile_tokens!(exps, tokens)
|
42
|
+
beg_str, end_str = strip_quotes!(tokens)
|
43
|
+
|
44
|
+
until tokens.empty?
|
45
|
+
_, type, str = tokens.shift
|
46
|
+
|
47
|
+
case type
|
48
|
+
when :on_tstring_content
|
49
|
+
beg_str, end_str = escape_quotes(beg_str, end_str)
|
50
|
+
exps << [:static, eval("#{beg_str}#{str}#{end_str}").to_s]
|
51
|
+
when :on_embexpr_beg
|
52
|
+
embedded = shift_balanced_embexpr(tokens)
|
53
|
+
exps << [:dynamic, embedded] unless embedded.empty?
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# Some quotes are split-unsafe. Replace such quotes with null characters.
|
59
|
+
def escape_quotes(beg_str, end_str)
|
60
|
+
case [beg_str[-1], end_str]
|
61
|
+
when ['(', ')'], ['[', ']'], ['{', '}']
|
62
|
+
[beg_str.sub(/.\z/) { "\0" }, "\0"]
|
63
|
+
else
|
64
|
+
[beg_str, end_str]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def shift_balanced_embexpr(tokens)
|
69
|
+
String.new.tap do |embedded|
|
70
|
+
embexpr_open = 1
|
71
|
+
|
72
|
+
until tokens.empty?
|
73
|
+
_, type, str = tokens.shift
|
74
|
+
case type
|
75
|
+
when :on_embexpr_beg
|
76
|
+
embexpr_open += 1
|
77
|
+
when :on_embexpr_end
|
78
|
+
embexpr_open -= 1
|
79
|
+
break if embexpr_open == 0
|
80
|
+
end
|
81
|
+
|
82
|
+
embedded << str
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
11
86
|
end
|
12
87
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
88
|
+
def on_dynamic(code)
|
89
|
+
return [:dynamic, code] unless string_literal?(code)
|
90
|
+
return [:dynamic, code] if code.include?("\n")
|
91
|
+
|
92
|
+
temple = [:multi]
|
93
|
+
StringSplitter.compile(code).each do |type, content|
|
94
|
+
case type
|
95
|
+
when :static
|
96
|
+
temple << [:static, content]
|
97
|
+
when :dynamic
|
98
|
+
temple << on_dynamic(content)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
temple
|
102
|
+
end
|
103
|
+
|
104
|
+
private
|
105
|
+
|
106
|
+
def string_literal?(code)
|
107
|
+
return false if SyntaxChecker.syntax_error?(code)
|
108
|
+
|
109
|
+
type, instructions = Ripper.sexp(code)
|
110
|
+
return false if type != :program
|
111
|
+
return false if instructions.size > 1
|
112
|
+
|
113
|
+
type, _ = instructions.first
|
114
|
+
type == :string_literal
|
115
|
+
end
|
116
|
+
|
117
|
+
class SyntaxChecker < Ripper
|
118
|
+
class ParseError < StandardError; end
|
119
|
+
|
120
|
+
def self.syntax_error?(code)
|
121
|
+
self.new(code).parse
|
122
|
+
false
|
123
|
+
rescue ParseError
|
124
|
+
true
|
125
|
+
end
|
126
|
+
|
127
|
+
private
|
128
|
+
|
129
|
+
def on_parse_error(*)
|
130
|
+
raise ParseError
|
131
|
+
end
|
132
|
+
end
|
133
|
+
else
|
134
|
+
# Do nothing if ripper is unavailable
|
135
|
+
def call(ast)
|
136
|
+
ast
|
17
137
|
end
|
18
138
|
end
|
19
139
|
end
|
data/lib/haml/util.rb
CHANGED
@@ -14,16 +14,15 @@ module Haml
|
|
14
14
|
module Util
|
15
15
|
extend self
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
begin
|
18
|
+
require 'haml/haml' # Haml::Util.escape_html
|
19
|
+
rescue LoadError
|
20
|
+
# For JRuby and Wasm, fallback to Ruby implementation when C extension is not available.
|
20
21
|
require 'cgi/escape'
|
21
22
|
|
22
23
|
def self.escape_html(html)
|
23
24
|
CGI.escapeHTML(html.to_s)
|
24
25
|
end
|
25
|
-
else
|
26
|
-
require 'haml/haml' # Haml::Util.escape_html
|
27
26
|
end
|
28
27
|
|
29
28
|
# TODO: Remove unescape_interpolation's workaround and get rid of `respond_to?`.
|
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.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Natalie Weizenbaum
|
@@ -9,10 +9,10 @@ authors:
|
|
9
9
|
- Norman Clarke
|
10
10
|
- Akira Matsuda
|
11
11
|
- Takashi Kokubun
|
12
|
-
autorequire:
|
12
|
+
autorequire:
|
13
13
|
bindir: exe
|
14
14
|
cert_chain: []
|
15
|
-
date: 2022-
|
15
|
+
date: 2022-10-05 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: temple
|
@@ -338,7 +338,7 @@ homepage: https://haml.info
|
|
338
338
|
licenses:
|
339
339
|
- MIT
|
340
340
|
metadata: {}
|
341
|
-
post_install_message:
|
341
|
+
post_install_message:
|
342
342
|
rdoc_options: []
|
343
343
|
require_paths:
|
344
344
|
- lib
|
@@ -354,7 +354,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
354
354
|
version: '0'
|
355
355
|
requirements: []
|
356
356
|
rubygems_version: 3.3.7
|
357
|
-
signing_key:
|
357
|
+
signing_key:
|
358
358
|
specification_version: 4
|
359
359
|
summary: An elegant, structured (X)HTML/XML templating engine.
|
360
360
|
test_files: []
|