haml 5.0.4 → 5.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +53 -8
- data/.yardopts +1 -2
- data/CHANGELOG.md +13 -1
- data/Gemfile +1 -1
- data/MIT-LICENSE +2 -2
- data/README.md +1 -1
- data/REFERENCE.md +7 -2
- data/benchmark.rb +13 -9
- data/haml.gemspec +1 -3
- data/lib/haml.rb +1 -0
- data/lib/haml/attribute_builder.rb +1 -0
- data/lib/haml/attribute_compiler.rb +1 -0
- data/lib/haml/attribute_parser.rb +2 -0
- data/lib/haml/buffer.rb +4 -1
- data/lib/haml/compiler.rb +3 -2
- data/lib/haml/engine.rb +12 -3
- data/lib/haml/error.rb +1 -0
- data/lib/haml/escapable.rb +1 -0
- data/lib/haml/exec.rb +1 -0
- data/lib/haml/filters.rb +10 -9
- data/lib/haml/generator.rb +2 -1
- data/lib/haml/helpers.rb +7 -11
- data/lib/haml/helpers/action_view_extensions.rb +1 -0
- data/lib/haml/helpers/action_view_mods.rb +4 -1
- data/lib/haml/helpers/action_view_xss_mods.rb +1 -0
- data/lib/haml/helpers/safe_erubi_template.rb +1 -0
- data/lib/haml/helpers/safe_erubis_template.rb +1 -0
- data/lib/haml/helpers/xss_mods.rb +1 -0
- data/lib/haml/options.rb +9 -1
- data/lib/haml/parser.rb +4 -3
- data/lib/haml/plugin.rb +7 -4
- data/lib/haml/railtie.rb +3 -2
- data/lib/haml/sass_rails_filter.rb +1 -0
- data/lib/haml/template.rb +1 -0
- data/lib/haml/template/options.rb +1 -0
- data/lib/haml/temple_engine.rb +11 -9
- data/lib/haml/temple_line_counter.rb +1 -0
- data/lib/haml/util.rb +4 -4
- data/lib/haml/version.rb +2 -1
- metadata +4 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb6c73536c5c41a0bdc61a99d45dd465616af8ef38392c6eadee4e82a5150556
|
4
|
+
data.tar.gz: e932ae5a4187ff9b4b6c4ea09c4d478009408a576282bee619075314dc7d88f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99f293970f051c7b007b8e0620bc64ee416868907b20e7ff10985c27920e7d3221c3ac7e6e4d1b51ecb763cf3a6315db886e0f1ca2cd978bb81e5febcf24a10c
|
7
|
+
data.tar.gz: 37812661dcea2d7de576c38f38df1f4a07231108ef47655cb1ea32f5e2470abe8c9501d1b54a69865d47fb71c9213914d9394fe9372ca8ba601d9bdf33e09a4e
|
data/.travis.yml
CHANGED
@@ -4,14 +4,18 @@ language: ruby
|
|
4
4
|
cache: bundler
|
5
5
|
rvm:
|
6
6
|
- ruby-head
|
7
|
-
- 2.
|
8
|
-
- 2.
|
9
|
-
- 2.
|
7
|
+
- 2.6.3
|
8
|
+
- 2.5.5
|
9
|
+
- 2.4.6
|
10
|
+
- 2.3.8
|
11
|
+
- 2.2.10
|
10
12
|
- 2.1.10
|
11
13
|
- 2.0.0
|
12
|
-
- jruby-9.
|
14
|
+
- jruby-9.2.7.0
|
13
15
|
- rbx-3
|
14
16
|
gemfile:
|
17
|
+
- test/gemfiles/Gemfile.rails-6.0.x
|
18
|
+
- test/gemfiles/Gemfile.rails-5.2.x
|
15
19
|
- test/gemfiles/Gemfile.rails-5.1.x
|
16
20
|
- test/gemfiles/Gemfile.rails-5.0.x
|
17
21
|
- test/gemfiles/Gemfile.rails-5.0.x.erubi
|
@@ -20,6 +24,20 @@ gemfile:
|
|
20
24
|
- test/gemfiles/Gemfile.rails-4.0.x
|
21
25
|
matrix:
|
22
26
|
exclude:
|
27
|
+
- rvm: 2.0.0
|
28
|
+
gemfile: test/gemfiles/Gemfile.rails-6.0.x
|
29
|
+
- rvm: 2.1.10
|
30
|
+
gemfile: test/gemfiles/Gemfile.rails-6.0.x
|
31
|
+
- rvm: 2.2.10
|
32
|
+
gemfile: test/gemfiles/Gemfile.rails-6.0.x
|
33
|
+
- rvm: 2.3.8
|
34
|
+
gemfile: test/gemfiles/Gemfile.rails-6.0.x
|
35
|
+
- rvm: 2.4.6
|
36
|
+
gemfile: test/gemfiles/Gemfile.rails-6.0.x
|
37
|
+
- rvm: 2.0.0
|
38
|
+
gemfile: test/gemfiles/Gemfile.rails-5.2.x
|
39
|
+
- rvm: 2.1.10
|
40
|
+
gemfile: test/gemfiles/Gemfile.rails-5.2.x
|
23
41
|
- rvm: 2.0.0
|
24
42
|
gemfile: test/gemfiles/Gemfile.rails-5.1.x
|
25
43
|
- rvm: 2.1.10
|
@@ -32,12 +50,28 @@ matrix:
|
|
32
50
|
gemfile: test/gemfiles/Gemfile.rails-5.0.x
|
33
51
|
- rvm: 2.1.10
|
34
52
|
gemfile: test/gemfiles/Gemfile.rails-5.0.x.erubi
|
35
|
-
- rvm: 2.4.
|
53
|
+
- rvm: 2.4.6
|
36
54
|
gemfile: test/gemfiles/Gemfile.rails-4.0.x
|
37
|
-
- rvm: 2.4.
|
55
|
+
- rvm: 2.4.6
|
38
56
|
gemfile: test/gemfiles/Gemfile.rails-4.1.x
|
39
|
-
- rvm: 2.4.
|
57
|
+
- rvm: 2.4.6
|
40
58
|
gemfile: test/gemfiles/Gemfile.rails-4.2.x
|
59
|
+
- rvm: 2.5.5
|
60
|
+
gemfile: test/gemfiles/Gemfile.rails-4.0.x
|
61
|
+
- rvm: 2.5.5
|
62
|
+
gemfile: test/gemfiles/Gemfile.rails-4.1.x
|
63
|
+
- rvm: 2.5.5
|
64
|
+
gemfile: test/gemfiles/Gemfile.rails-4.2.x
|
65
|
+
- rvm: 2.6.3
|
66
|
+
gemfile: test/gemfiles/Gemfile.rails-4.0.x
|
67
|
+
- rvm: 2.6.3
|
68
|
+
gemfile: test/gemfiles/Gemfile.rails-4.1.x
|
69
|
+
- rvm: 2.6.3
|
70
|
+
gemfile: test/gemfiles/Gemfile.rails-4.2.x
|
71
|
+
- rvm: 2.6.3
|
72
|
+
gemfile: test/gemfiles/Gemfile.rails-5.0.x
|
73
|
+
- rvm: 2.6.3
|
74
|
+
gemfile: test/gemfiles/Gemfile.rails-5.0.x.erubi
|
41
75
|
- rvm: ruby-head
|
42
76
|
gemfile: test/gemfiles/Gemfile.rails-4.0.x
|
43
77
|
- rvm: ruby-head
|
@@ -45,10 +79,21 @@ matrix:
|
|
45
79
|
- rvm: ruby-head
|
46
80
|
gemfile: test/gemfiles/Gemfile.rails-4.2.x
|
47
81
|
include:
|
48
|
-
- rvm: 2.
|
82
|
+
- rvm: 2.6.3
|
49
83
|
gemfile: test/gemfiles/Gemfile.rails-edge
|
50
84
|
allow_failures:
|
85
|
+
- rvm: ruby-head
|
51
86
|
- rvm: rbx-3
|
52
87
|
- gemfile: test/gemfiles/Gemfile.rails-edge
|
88
|
+
- rvm: jruby-9.2.7.0
|
89
|
+
gemfile: test/gemfiles/Gemfile.rails-4.2.x
|
90
|
+
- rvm: jruby-9.2.7.0
|
91
|
+
gemfile: test/gemfiles/Gemfile.rails-4.1.x
|
92
|
+
- rvm: jruby-9.2.7.0
|
93
|
+
gemfile: test/gemfiles/Gemfile.rails-4.0.x
|
94
|
+
- rvm: jruby-9.2.7.0
|
95
|
+
gemfile: test/gemfiles/Gemfile.rails-5.0.x.erubi
|
53
96
|
fast_finish: true
|
97
|
+
before_install: gem i rubygems-update -v '<3' && update_rubygems # https://github.com/travis-ci/travis-ci/issues/8974
|
98
|
+
before_install: gem i bundler -v '<2'
|
54
99
|
script: "bundle exec rake submodules test"
|
data/.yardopts
CHANGED
@@ -7,8 +7,7 @@
|
|
7
7
|
--title "Haml Documentation"
|
8
8
|
--query 'object.type != :classvariable'
|
9
9
|
--query 'object.type != :constant || @api && @api.text == "public"'
|
10
|
-
--exclude lib/haml/
|
11
|
-
--exclude lib/haml/template/plugin.rb
|
10
|
+
--exclude lib/haml/plugin.rb
|
12
11
|
--exclude lib/haml/railtie.rb
|
13
12
|
--exclude lib/haml/helpers/action_view_mods.rb
|
14
13
|
--exclude lib/haml/helpers/xss_mods.rb
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,18 @@
|
|
1
1
|
# Haml Changelog
|
2
2
|
|
3
|
+
## 5.1.0
|
4
|
+
|
5
|
+
Released on May 16, 2019
|
6
|
+
([diff](https://github.com/haml/haml/compare/v5.0.4...v5.1.0)).
|
7
|
+
|
8
|
+
* Rails 6 support [#1008](https://github.com/haml/haml/pull/1008) (thanks [Seb Jacobs](https://github.com/sebjacobs))
|
9
|
+
* Add `escape_filter_interpolations` option for backwards compatibility with haml 4 defaults [#984](https://github.com/haml/haml/pull/984) (thanks [Will Jordan](https://github.com/wjordan))
|
10
|
+
* Fix error on empty :javascript and :css filter blocks [#986](https://github.com/haml/haml/pull/986) (thanks [Will Jordan](https://github.com/wjordan))
|
11
|
+
* Respect changes in Haml::Options.defaults in `Haml::TempleEngine` options (Takashi Kokubun)
|
12
|
+
* Un-freeze TempleEngine precompiled string literals [#983](https://github.com/haml/haml/pull/983) (thanks [Will Jordan](https://github.com/wjordan))
|
13
|
+
* Various performance/memory improvements [#965](https://github.com/haml/haml/pull/965), [#966](https://github.com/haml/haml/pull/966), [#963](https://github.com/haml/haml/pull/963) (thanks [Dillon Welch](https://github.com/oniofchaos))
|
14
|
+
* Enable `frozen_string_literal` magic comment for all .rb files [#967](https://github.com/haml/haml/pull/967) (thanks [Dillon Welch](https://github.com/oniofchaos))
|
15
|
+
|
3
16
|
## 5.0.4
|
4
17
|
|
5
18
|
Released on October 13, 2017
|
@@ -1452,4 +1465,3 @@ has been moved to [YARD](http://yard.soen.ca).
|
|
1452
1465
|
YARD is an excellent documentation system,
|
1453
1466
|
and allows us to write our documentation in [Maruku](http://maruku.rubyforge.org),
|
1454
1467
|
which is also excellent.
|
1455
|
-
>>>>>>> External Changes
|
data/Gemfile
CHANGED
data/MIT-LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2006-
|
1
|
+
Copyright (c) 2006-2019 Hampton Catlin and Natalie Weizenbaum
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining
|
4
4
|
a copy of this software and associated documentation files (the
|
@@ -17,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
17
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
18
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
19
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -191,7 +191,7 @@ Some of Natalie's work on Haml was supported by Unspace Interactive.
|
|
191
191
|
|
192
192
|
Beyond that, the implementation is licensed under the MIT License.
|
193
193
|
|
194
|
-
Copyright (c) 2006-
|
194
|
+
Copyright (c) 2006-2019 Hampton Catlin, Natalie Weizenbaum and the Haml team
|
195
195
|
|
196
196
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
197
197
|
this software and associated documentation files (the "Software"), to deal in
|
data/REFERENCE.md
CHANGED
@@ -115,6 +115,11 @@ Haml::Options.defaults:
|
|
115
115
|
|
116
116
|
Haml::Options.defaults[:format] = :html5
|
117
117
|
|
118
|
+
In sinatra specifically, you can set them in global config with:
|
119
|
+
```ruby
|
120
|
+
set :haml, { escape_html: true }
|
121
|
+
```
|
122
|
+
|
118
123
|
Finally, you can also set them by passing an options hash to
|
119
124
|
{Haml::Engine#initialize}. For the complete list of available options, please
|
120
125
|
see {Haml::Options}.
|
@@ -1120,8 +1125,8 @@ is compiled to
|
|
1120
1125
|
<p>I <strong>really</strong> prefer <em>raspberry</em> jam.</p>
|
1121
1126
|
</div>
|
1122
1127
|
|
1123
|
-
Note that `#{}` interpolation within filters is HTML-escaped if you specify
|
1124
|
-
{Haml::Options#
|
1128
|
+
Note that `#{}` interpolation within filters is HTML-escaped if you specify true to
|
1129
|
+
{Haml::Options#escape_filter_interpolations `:escape_filter_interpolations`} option.
|
1125
1130
|
|
1126
1131
|
The functionality of some filters such as Markdown can be provided by many
|
1127
1132
|
different libraries. Usually you don't have to worry about this - you can just
|
data/benchmark.rb
CHANGED
@@ -12,7 +12,7 @@ END
|
|
12
12
|
exit 1
|
13
13
|
end
|
14
14
|
|
15
|
-
%w[erb
|
15
|
+
%w[erb erubi rails active_support action_controller
|
16
16
|
action_view action_pack haml/template rbench].each {|dep| require(dep)}
|
17
17
|
|
18
18
|
def view
|
@@ -28,7 +28,7 @@ end
|
|
28
28
|
RBench.run(times) do
|
29
29
|
column :haml, :title => "Haml"
|
30
30
|
column :erb, :title => "ERB"
|
31
|
-
column :
|
31
|
+
column :erubi, :title => "Erubi"
|
32
32
|
|
33
33
|
template_name = 'standard'
|
34
34
|
haml_template = File.read("#{File.dirname(__FILE__)}/test/templates/#{template_name}.haml")
|
@@ -38,12 +38,16 @@ RBench.run(times) do
|
|
38
38
|
obj = Object.new
|
39
39
|
|
40
40
|
Haml::Engine.new(haml_template).def_method(obj, :haml)
|
41
|
-
|
42
|
-
|
41
|
+
if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+
|
42
|
+
obj.instance_eval("def erb; #{ERB.new(erb_template, trim_mode: '-').src}; end")
|
43
|
+
else
|
44
|
+
obj.instance_eval("def erb; #{ERB.new(erb_template, nil, '-').src}; end")
|
45
|
+
end
|
46
|
+
obj.instance_eval("def erubi; #{Erubi::Engine.new(erb_template).src}; end")
|
43
47
|
|
44
48
|
haml { obj.haml }
|
45
49
|
erb { obj.erb }
|
46
|
-
|
50
|
+
erubi { obj.erubi }
|
47
51
|
end
|
48
52
|
|
49
53
|
report "ActionView" do
|
@@ -51,8 +55,8 @@ RBench.run(times) do
|
|
51
55
|
render view, 'templates/standard'
|
52
56
|
render view, 'erb/standard'
|
53
57
|
|
54
|
-
haml
|
55
|
-
|
58
|
+
haml { render view, 'templates/standard' }
|
59
|
+
erubi { render view, 'erb/standard' }
|
56
60
|
end
|
57
61
|
|
58
62
|
report "ActionView with deep partials" do
|
@@ -60,7 +64,7 @@ RBench.run(times) do
|
|
60
64
|
render view, 'templates/action_view'
|
61
65
|
render view, 'erb/action_view'
|
62
66
|
|
63
|
-
haml
|
64
|
-
|
67
|
+
haml { render view, 'templates/action_view' }
|
68
|
+
erubi { render view, 'erb/action_view' }
|
65
69
|
end
|
66
70
|
end
|
data/haml.gemspec
CHANGED
@@ -6,15 +6,13 @@ Gem::Specification.new do |spec|
|
|
6
6
|
spec.summary = "An elegant, structured (X)HTML/XML templating engine."
|
7
7
|
spec.version = Haml::VERSION
|
8
8
|
spec.authors = ['Natalie Weizenbaum', 'Hampton Catlin', 'Norman Clarke', 'Akira Matsuda']
|
9
|
-
spec.email = ['haml@googlegroups.com', '
|
9
|
+
spec.email = ['haml@googlegroups.com', 'ronnie@dio.jp']
|
10
10
|
|
11
|
-
readmes = Dir['*'].reject{ |x| x =~ /(^|[^.a-z])[a-z]+/ || x == "TODO" }
|
12
11
|
spec.executables = ['haml']
|
13
12
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
14
13
|
f.match(%r{\Atest/})
|
15
14
|
end
|
16
15
|
spec.homepage = 'http://haml.info/'
|
17
|
-
spec.has_rdoc = false
|
18
16
|
spec.license = "MIT"
|
19
17
|
|
20
18
|
spec.required_ruby_version = '>= 2.0.0'
|
data/lib/haml.rb
CHANGED
data/lib/haml/buffer.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Haml
|
3
4
|
# This class is used only internally. It holds the buffer of HTML that
|
4
5
|
# is eventually output as the resulting document.
|
@@ -132,7 +133,9 @@ module Haml
|
|
132
133
|
def attributes(class_id, obj_ref, *attributes_hashes)
|
133
134
|
attributes = class_id
|
134
135
|
attributes_hashes.each do |old|
|
135
|
-
|
136
|
+
result = {}
|
137
|
+
old.each { |k, v| result[k.to_s] = v }
|
138
|
+
AttributeBuilder.merge_attributes!(attributes, result)
|
136
139
|
end
|
137
140
|
AttributeBuilder.merge_attributes!(attributes, parse_object_ref(obj_ref)) if obj_ref
|
138
141
|
AttributeBuilder.build_attributes(
|
data/lib/haml/compiler.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'haml/attribute_builder'
|
3
4
|
require 'haml/attribute_compiler'
|
4
5
|
require 'haml/temple_line_counter'
|
@@ -315,7 +316,7 @@ module Haml
|
|
315
316
|
|
316
317
|
case last.first
|
317
318
|
when :text
|
318
|
-
last[1].rstrip
|
319
|
+
last[1] = last[1].rstrip
|
319
320
|
if last[1].empty?
|
320
321
|
@to_merge.slice! index
|
321
322
|
rstrip_buffer! index
|
data/lib/haml/engine.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'forwardable'
|
3
4
|
|
4
5
|
require 'haml/parser'
|
@@ -51,6 +52,9 @@ module Haml
|
|
51
52
|
# see {file:REFERENCE.md#options the Haml options documentation}
|
52
53
|
# @raise [Haml::Error] if there's a Haml syntax error in the template
|
53
54
|
def initialize(template, options = {})
|
55
|
+
# Reflect changes of `Haml::Options.defaults` to `Haml::TempleEngine` options, but `#initialize_encoding`
|
56
|
+
# should be run against the arguemnt `options[:encoding]` for backward compatibility with old `Haml::Engine`.
|
57
|
+
options = Options.defaults.dup.tap { |o| o.delete(:encoding) }.merge!(options)
|
54
58
|
@options = Options.new(options)
|
55
59
|
|
56
60
|
@template = check_haml_encoding(template) do |msg, line|
|
@@ -166,8 +170,13 @@ module Haml
|
|
166
170
|
end
|
167
171
|
|
168
172
|
begin
|
169
|
-
|
170
|
-
|
173
|
+
str = @temple_engine.precompiled_with_ambles(local_names)
|
174
|
+
eval(
|
175
|
+
"Proc.new { |*_haml_locals| _haml_locals = _haml_locals[0] || {}; #{str}}\n",
|
176
|
+
scope,
|
177
|
+
@options.filename,
|
178
|
+
@options.line
|
179
|
+
)
|
171
180
|
rescue ::SyntaxError => e
|
172
181
|
raise SyntaxError, e.message
|
173
182
|
end
|
data/lib/haml/error.rb
CHANGED
data/lib/haml/escapable.rb
CHANGED
data/lib/haml/exec.rb
CHANGED
data/lib/haml/filters.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require "tilt"
|
3
4
|
|
4
5
|
module Haml
|
@@ -164,7 +165,11 @@ module Haml
|
|
164
165
|
if contains_interpolation?(text)
|
165
166
|
return if options[:suppress_eval]
|
166
167
|
|
167
|
-
|
168
|
+
escape = options[:escape_filter_interpolations]
|
169
|
+
# `escape_filter_interpolations` defaults to `escape_html` if unset.
|
170
|
+
escape = options[:escape_html] if escape.nil?
|
171
|
+
|
172
|
+
text = unescape_interpolation(text, escape).gsub(/(\\+)n/) do |s|
|
168
173
|
escapes = $1.size
|
169
174
|
next s if escapes % 2 == 0
|
170
175
|
"#{'\\' * (escapes - 1)}\n"
|
@@ -182,9 +187,8 @@ RUBY
|
|
182
187
|
return
|
183
188
|
end
|
184
189
|
|
185
|
-
rendered = Haml::Helpers::find_and_preserve(filter.render_with_options(text, compiler.options), compiler.options[:preserve])
|
186
|
-
rendered.rstrip
|
187
|
-
push_text("#{rendered}\n")
|
190
|
+
rendered = Haml::Helpers::find_and_preserve(filter.render_with_options(text.to_s, compiler.options), compiler.options[:preserve])
|
191
|
+
push_text("#{rendered.rstrip}\n")
|
188
192
|
end
|
189
193
|
end
|
190
194
|
end
|
@@ -247,10 +251,7 @@ RUBY
|
|
247
251
|
|
248
252
|
# @see Base#render
|
249
253
|
def render(text)
|
250
|
-
|
251
|
-
text.rstrip!
|
252
|
-
text.gsub!("\n", "\n ")
|
253
|
-
"<![CDATA[#{text}\n]]>"
|
254
|
+
"<![CDATA[#{"\n#{text.rstrip}".gsub("\n", "\n ")}\n]]>"
|
254
255
|
end
|
255
256
|
end
|
256
257
|
|
data/lib/haml/generator.rb
CHANGED
data/lib/haml/helpers.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'erb'
|
3
4
|
|
4
5
|
module Haml
|
@@ -109,10 +110,7 @@ MESSAGE
|
|
109
110
|
# @yield The block within which to escape newlines
|
110
111
|
def find_and_preserve(input = nil, tags = haml_buffer.options[:preserve], &block)
|
111
112
|
return find_and_preserve(capture_haml(&block), input || tags) if block
|
112
|
-
tags = tags.
|
113
|
-
s << '|' unless s.empty?
|
114
|
-
s << Regexp.escape(t)
|
115
|
-
end
|
113
|
+
tags = tags.map { |tag| Regexp.escape(tag) }.join('|')
|
116
114
|
re = /<(#{tags})([^>]*)>(.*?)(<\/\1>)/im
|
117
115
|
input.to_s.gsub(re) do |s|
|
118
116
|
s =~ re # Can't rely on $1, etc. existing since Rails' SafeBuffer#gsub is incompatible
|
@@ -200,8 +198,8 @@ MESSAGE
|
|
200
198
|
# @yield [item] A block which contains Haml code that goes within list items
|
201
199
|
# @yieldparam item An element of `enum`
|
202
200
|
def list_of(enum, opts={}, &block)
|
203
|
-
opts_attributes = opts.
|
204
|
-
enum.
|
201
|
+
opts_attributes = opts.map { |k, v| " #{k}='#{v}'" }.join
|
202
|
+
enum.map do |i|
|
205
203
|
result = capture_haml(i, &block)
|
206
204
|
|
207
205
|
if result.count("\n") > 1
|
@@ -211,9 +209,8 @@ MESSAGE
|
|
211
209
|
result.strip!
|
212
210
|
end
|
213
211
|
|
214
|
-
|
215
|
-
|
216
|
-
end
|
212
|
+
%Q!<li#{opts_attributes}>#{result}</li>!
|
213
|
+
end.join("\n")
|
217
214
|
end
|
218
215
|
|
219
216
|
# Returns a hash containing default assignments for the `xmlns`, `lang`, and `xml:lang`
|
@@ -704,4 +701,3 @@ class Object
|
|
704
701
|
false
|
705
702
|
end
|
706
703
|
end
|
707
|
-
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Haml
|
3
4
|
module Helpers
|
4
5
|
module ActionViewMods
|
@@ -52,10 +53,12 @@ module ActionView
|
|
52
53
|
end
|
53
54
|
|
54
55
|
module TagHelper
|
56
|
+
DEFAULT_PRESERVE_OPTIONS = %w(textarea pre code).freeze
|
57
|
+
|
55
58
|
def content_tag_with_haml(name, *args, &block)
|
56
59
|
return content_tag_without_haml(name, *args, &block) unless is_haml?
|
57
60
|
|
58
|
-
preserve = haml_buffer.options.fetch(:preserve,
|
61
|
+
preserve = haml_buffer.options.fetch(:preserve, DEFAULT_PRESERVE_OPTIONS).include?(name.to_s)
|
59
62
|
|
60
63
|
if block_given? && block_is_haml?(block) && preserve
|
61
64
|
return content_tag_without_haml(name, *args) do
|
data/lib/haml/options.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Haml
|
3
4
|
# This class encapsulates all of the configuration options that Haml
|
4
5
|
# understands. Please see the {file:REFERENCE.md#options Haml Reference} to
|
@@ -8,7 +9,7 @@ module Haml
|
|
8
9
|
@valid_formats = [:html4, :html5, :xhtml]
|
9
10
|
|
10
11
|
@buffer_option_keys = [:autoclose, :preserve, :attr_wrapper, :format,
|
11
|
-
:encoding, :escape_html, :escape_attrs, :hyphenate_data_attrs, :cdata]
|
12
|
+
:encoding, :escape_html, :escape_filter_interpolations, :escape_attrs, :hyphenate_data_attrs, :cdata]
|
12
13
|
|
13
14
|
# The default option values.
|
14
15
|
# @return Hash
|
@@ -85,6 +86,13 @@ module Haml
|
|
85
86
|
# Defaults to false.
|
86
87
|
attr_accessor :escape_html
|
87
88
|
|
89
|
+
# Sets whether or not to escape HTML-sensitive characters in interpolated strings.
|
90
|
+
# See also {file:REFERENCE.md#escaping_html Escaping HTML} and
|
91
|
+
# {file:REFERENCE.md#unescaping_html Unescaping HTML}.
|
92
|
+
#
|
93
|
+
# Defaults to the current value of `escape_html`.
|
94
|
+
attr_accessor :escape_filter_interpolations
|
95
|
+
|
88
96
|
# The name of the Haml file being parsed.
|
89
97
|
# This is only used as information when exceptions are raised. This is
|
90
98
|
# automatically assigned when working through ActionView, so it's really
|
data/lib/haml/parser.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'strscan'
|
3
4
|
|
4
5
|
module Haml
|
@@ -698,7 +699,7 @@ module Haml
|
|
698
699
|
end
|
699
700
|
|
700
701
|
static_attributes = {}
|
701
|
-
dynamic_attributes = "{"
|
702
|
+
dynamic_attributes = "{".dup
|
702
703
|
attributes.each do |name, (type, val)|
|
703
704
|
if type == :static
|
704
705
|
static_attributes[name] = val
|
@@ -738,7 +739,7 @@ module Haml
|
|
738
739
|
|
739
740
|
return name, [:static, content.first[1]] if content.size == 1
|
740
741
|
return name, [:dynamic,
|
741
|
-
%!"#{content.each_with_object('') {|(t, v), s| s << (t == :str ? inspect_obj(v)[1...-1] : "\#{#{v}}")}}"!]
|
742
|
+
%!"#{content.each_with_object(''.dup) {|(t, v), s| s << (t == :str ? inspect_obj(v)[1...-1] : "\#{#{v}}")}}"!]
|
742
743
|
end
|
743
744
|
|
744
745
|
def next_line
|
data/lib/haml/plugin.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Haml
|
3
4
|
|
4
5
|
# This module makes Haml work with Rails using the template handler API.
|
5
6
|
class Plugin
|
6
7
|
def handles_encoding?; true; end
|
7
8
|
|
8
|
-
def compile(template)
|
9
|
+
def compile(template, source)
|
9
10
|
options = Haml::Template.options.dup
|
10
11
|
if template.respond_to?(:type)
|
11
12
|
options[:mime_type] = template.type
|
@@ -13,14 +14,16 @@ module Haml
|
|
13
14
|
options[:mime_type] = template.mime_type
|
14
15
|
end
|
15
16
|
options[:filename] = template.identifier
|
16
|
-
Haml::Engine.new(
|
17
|
+
Haml::Engine.new(source, options).compiler.precompiled_with_ambles(
|
17
18
|
[],
|
18
19
|
after_preamble: '@output_buffer = output_buffer ||= ActionView::OutputBuffer.new if defined?(ActionView::OutputBuffer)',
|
19
20
|
)
|
20
21
|
end
|
21
22
|
|
22
|
-
def self.call(template)
|
23
|
-
|
23
|
+
def self.call(template, source = nil)
|
24
|
+
source ||= template.source
|
25
|
+
|
26
|
+
new.compile(template, source)
|
24
27
|
end
|
25
28
|
|
26
29
|
def cache_fragment(block, name = {}, options = nil)
|
data/lib/haml/railtie.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'haml/template/options'
|
3
4
|
|
4
5
|
# check for a compatible Rails version when Haml is loaded
|
5
6
|
if (activesupport_spec = Gem.loaded_specs['activesupport'])
|
6
|
-
if activesupport_spec.version.to_s < '
|
7
|
-
raise Exception.new("\n\n** Haml now requires Rails
|
7
|
+
if activesupport_spec.version.to_s < '4.0'
|
8
|
+
raise Exception.new("\n\n** Haml now requires Rails 4.0 and later. Use Haml version 4.0.x\n\n")
|
8
9
|
end
|
9
10
|
end
|
10
11
|
|
data/lib/haml/template.rb
CHANGED
data/lib/haml/temple_engine.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'temple'
|
3
4
|
require 'haml/escapable'
|
4
5
|
require 'haml/generator'
|
@@ -13,6 +14,7 @@ module Haml
|
|
13
14
|
encoding: nil,
|
14
15
|
escape_attrs: true,
|
15
16
|
escape_html: false,
|
17
|
+
escape_filter_interpolations: nil,
|
16
18
|
filename: '(haml)',
|
17
19
|
format: :html5,
|
18
20
|
hyphenate_data_attrs: true,
|
@@ -49,12 +51,12 @@ module Haml
|
|
49
51
|
# @return [String]
|
50
52
|
def precompiled
|
51
53
|
encoding = Encoding.find(@encoding || '')
|
52
|
-
return @precompiled.force_encoding(encoding) if encoding == Encoding::ASCII_8BIT
|
54
|
+
return @precompiled.dup.force_encoding(encoding) if encoding == Encoding::ASCII_8BIT
|
53
55
|
return @precompiled.encode(encoding)
|
54
56
|
end
|
55
57
|
|
56
58
|
def precompiled_with_return_value
|
57
|
-
"#{precompiled};#{precompiled_method_return_value}"
|
59
|
+
"#{precompiled};#{precompiled_method_return_value}".dup
|
58
60
|
end
|
59
61
|
|
60
62
|
# The source code that is evaluated to produce the Haml document.
|
@@ -64,20 +66,20 @@ module Haml
|
|
64
66
|
#
|
65
67
|
# @return [String]
|
66
68
|
def precompiled_with_ambles(local_names, after_preamble: '')
|
67
|
-
preamble = <<END.tr
|
69
|
+
preamble = <<END.tr("\n", ';')
|
68
70
|
begin
|
69
71
|
extend Haml::Helpers
|
70
72
|
_hamlout = @haml_buffer = Haml::Buffer.new(haml_buffer, #{Options.new(options).for_buffer.inspect})
|
71
73
|
_erbout = _hamlout.buffer
|
72
74
|
#{after_preamble}
|
73
75
|
END
|
74
|
-
postamble = <<END.tr
|
76
|
+
postamble = <<END.tr("\n", ';')
|
75
77
|
#{precompiled_method_return_value}
|
76
78
|
ensure
|
77
79
|
@haml_buffer = @haml_buffer.upper if @haml_buffer
|
78
80
|
end
|
79
81
|
END
|
80
|
-
"#{preamble}#{locals_code(local_names)}#{precompiled}#{postamble}"
|
82
|
+
"#{preamble}#{locals_code(local_names)}#{precompiled}#{postamble}".dup
|
81
83
|
end
|
82
84
|
|
83
85
|
private
|
@@ -99,12 +101,12 @@ END
|
|
99
101
|
def locals_code(names)
|
100
102
|
names = names.keys if Hash === names
|
101
103
|
|
102
|
-
names.
|
104
|
+
names.map do |name|
|
103
105
|
# Can't use || because someone might explicitly pass in false with a symbol
|
104
106
|
sym_local = "_haml_locals[#{inspect_obj(name.to_sym)}]"
|
105
107
|
str_local = "_haml_locals[#{inspect_obj(name.to_s)}]"
|
106
|
-
|
107
|
-
end
|
108
|
+
"#{name} = #{sym_local}.nil? ? #{str_local} : #{sym_local};"
|
109
|
+
end.join
|
108
110
|
end
|
109
111
|
|
110
112
|
def inspect_obj(obj)
|
data/lib/haml/util.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
begin
|
4
4
|
require 'erubis/tiny'
|
@@ -166,7 +166,7 @@ MSG
|
|
166
166
|
# and the rest of the string.
|
167
167
|
# `["Foo (Bar (Baz bang) bop)", " (Bang (bop bip))"]` in the example above.
|
168
168
|
def balance(scanner, start, finish, count = 0)
|
169
|
-
str = ''
|
169
|
+
str = ''.dup
|
170
170
|
scanner = StringScanner.new(scanner) unless scanner.is_a? StringScanner
|
171
171
|
regexp = Regexp.new("(.*?)[\\#{start.chr}\\#{finish.chr}]", Regexp::MULTILINE)
|
172
172
|
while scanner.scan(regexp)
|
@@ -199,7 +199,7 @@ MSG
|
|
199
199
|
end
|
200
200
|
|
201
201
|
def unescape_interpolation(str, escape_html = nil)
|
202
|
-
res = ''
|
202
|
+
res = ''.dup
|
203
203
|
rest = Haml::Util.handle_interpolation str.dump do |scan|
|
204
204
|
escapes = (scan[2].size - 1) / 2
|
205
205
|
char = scan[3] # '{', '@' or '$'
|
@@ -212,7 +212,7 @@ MSG
|
|
212
212
|
else
|
213
213
|
scan.scan(/\w+/)
|
214
214
|
end
|
215
|
-
content = eval(
|
215
|
+
content = eval("\"#{interpolated}\"")
|
216
216
|
content.prepend(char) if char == '@' || char == '$'
|
217
217
|
content = "Haml::Helpers.html_escape((#{content}))" if escape_html
|
218
218
|
|
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: 5.0
|
4
|
+
version: 5.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Natalie Weizenbaum
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2019-05-16 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: temple
|
@@ -105,7 +105,7 @@ description: |
|
|
105
105
|
but it can function as a stand-alone templating engine.
|
106
106
|
email:
|
107
107
|
- haml@googlegroups.com
|
108
|
-
-
|
108
|
+
- ronnie@dio.jp
|
109
109
|
executables:
|
110
110
|
- haml
|
111
111
|
extensions: []
|
@@ -179,8 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
179
179
|
- !ruby/object:Gem::Version
|
180
180
|
version: '0'
|
181
181
|
requirements: []
|
182
|
-
|
183
|
-
rubygems_version: 2.6.14
|
182
|
+
rubygems_version: 3.0.1
|
184
183
|
signing_key:
|
185
184
|
specification_version: 4
|
186
185
|
summary: An elegant, structured (X)HTML/XML templating engine.
|