haml 4.0.7 → 5.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/test.yml +36 -0
- data/.gitignore +19 -0
- data/.gitmodules +3 -0
- data/.yardopts +2 -3
- data/CHANGELOG.md +146 -4
- data/FAQ.md +4 -14
- data/Gemfile +16 -0
- data/MIT-LICENSE +2 -2
- data/README.md +90 -47
- data/REFERENCE.md +160 -74
- data/Rakefile +44 -63
- data/TODO +24 -0
- data/benchmark.rb +70 -0
- data/haml.gemspec +45 -0
- data/lib/haml/.gitattributes +1 -0
- data/lib/haml/attribute_builder.rb +219 -0
- data/lib/haml/attribute_compiler.rb +237 -0
- data/lib/haml/attribute_parser.rb +150 -0
- data/lib/haml/buffer.rb +12 -175
- data/lib/haml/compiler.rb +110 -320
- data/lib/haml/engine.rb +34 -41
- data/lib/haml/error.rb +28 -24
- data/lib/haml/escapable.rb +77 -0
- data/lib/haml/exec.rb +38 -20
- data/lib/haml/filters.rb +22 -27
- data/lib/haml/generator.rb +42 -0
- data/lib/haml/helpers/action_view_extensions.rb +4 -2
- data/lib/haml/helpers/action_view_mods.rb +45 -60
- data/lib/haml/helpers/action_view_xss_mods.rb +2 -0
- data/lib/haml/helpers/safe_erubi_template.rb +20 -0
- data/lib/haml/helpers/safe_erubis_template.rb +5 -1
- data/lib/haml/helpers/xss_mods.rb +23 -13
- data/lib/haml/helpers.rb +134 -89
- data/lib/haml/options.rb +63 -69
- data/lib/haml/parser.rb +319 -227
- data/lib/haml/plugin.rb +54 -0
- data/lib/haml/railtie.rb +43 -12
- data/lib/haml/sass_rails_filter.rb +18 -4
- data/lib/haml/template/options.rb +13 -2
- data/lib/haml/template.rb +13 -6
- data/lib/haml/temple_engine.rb +124 -0
- data/lib/haml/temple_line_counter.rb +30 -0
- data/lib/haml/util.rb +83 -202
- data/lib/haml/version.rb +3 -1
- data/lib/haml.rb +2 -0
- data/yard/default/.gitignore +1 -0
- data/yard/default/fulldoc/html/css/common.sass +15 -0
- data/yard/default/layout/html/footer.erb +12 -0
- metadata +73 -115
- data/lib/haml/template/plugin.rb +0 -41
- data/test/engine_test.rb +0 -2013
- data/test/erb/_av_partial_1.erb +0 -12
- data/test/erb/_av_partial_2.erb +0 -8
- data/test/erb/action_view.erb +0 -62
- data/test/erb/standard.erb +0 -55
- data/test/filters_test.rb +0 -254
- data/test/gemfiles/Gemfile.rails-3.0.x +0 -5
- data/test/gemfiles/Gemfile.rails-3.1.x +0 -6
- data/test/gemfiles/Gemfile.rails-3.2.x +0 -5
- data/test/gemfiles/Gemfile.rails-4.0.x +0 -5
- data/test/haml-spec/LICENSE +0 -14
- data/test/haml-spec/README.md +0 -106
- data/test/haml-spec/lua_haml_spec.lua +0 -38
- data/test/haml-spec/perl_haml_test.pl +0 -81
- data/test/haml-spec/ruby_haml_test.rb +0 -23
- data/test/haml-spec/tests.json +0 -660
- data/test/helper_test.rb +0 -583
- data/test/markaby/standard.mab +0 -52
- data/test/mocks/article.rb +0 -6
- data/test/parser_test.rb +0 -105
- data/test/results/content_for_layout.xhtml +0 -12
- data/test/results/eval_suppressed.xhtml +0 -9
- data/test/results/helpers.xhtml +0 -70
- data/test/results/helpful.xhtml +0 -10
- data/test/results/just_stuff.xhtml +0 -70
- data/test/results/list.xhtml +0 -12
- data/test/results/nuke_inner_whitespace.xhtml +0 -40
- data/test/results/nuke_outer_whitespace.xhtml +0 -148
- data/test/results/original_engine.xhtml +0 -20
- data/test/results/partial_layout.xhtml +0 -5
- data/test/results/partial_layout_erb.xhtml +0 -5
- data/test/results/partials.xhtml +0 -21
- data/test/results/render_layout.xhtml +0 -3
- data/test/results/silent_script.xhtml +0 -74
- data/test/results/standard.xhtml +0 -162
- data/test/results/tag_parsing.xhtml +0 -23
- data/test/results/very_basic.xhtml +0 -5
- data/test/results/whitespace_handling.xhtml +0 -90
- data/test/template_test.rb +0 -354
- data/test/templates/_av_partial_1.haml +0 -9
- data/test/templates/_av_partial_1_ugly.haml +0 -9
- data/test/templates/_av_partial_2.haml +0 -5
- data/test/templates/_av_partial_2_ugly.haml +0 -5
- data/test/templates/_layout.erb +0 -3
- data/test/templates/_layout_for_partial.haml +0 -3
- data/test/templates/_partial.haml +0 -8
- data/test/templates/_text_area.haml +0 -3
- data/test/templates/_text_area_helper.html.haml +0 -4
- data/test/templates/action_view.haml +0 -47
- data/test/templates/action_view_ugly.haml +0 -47
- data/test/templates/breakage.haml +0 -8
- data/test/templates/content_for_layout.haml +0 -8
- data/test/templates/eval_suppressed.haml +0 -11
- data/test/templates/helpers.haml +0 -55
- data/test/templates/helpful.haml +0 -11
- data/test/templates/just_stuff.haml +0 -85
- data/test/templates/list.haml +0 -12
- data/test/templates/nuke_inner_whitespace.haml +0 -32
- data/test/templates/nuke_outer_whitespace.haml +0 -144
- data/test/templates/original_engine.haml +0 -17
- data/test/templates/partial_layout.haml +0 -3
- data/test/templates/partial_layout_erb.erb +0 -4
- data/test/templates/partialize.haml +0 -1
- data/test/templates/partials.haml +0 -12
- data/test/templates/render_layout.haml +0 -2
- data/test/templates/silent_script.haml +0 -45
- data/test/templates/standard.haml +0 -43
- data/test/templates/standard_ugly.haml +0 -43
- data/test/templates/tag_parsing.haml +0 -21
- data/test/templates/very_basic.haml +0 -4
- data/test/templates/whitespace_handling.haml +0 -87
- data/test/test_helper.rb +0 -81
- data/test/util_test.rb +0 -63
data/lib/haml/options.rb
CHANGED
@@ -1,53 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Haml
|
2
4
|
# This class encapsulates all of the configuration options that Haml
|
3
5
|
# understands. Please see the {file:REFERENCE.md#options Haml Reference} to
|
4
6
|
# learn how to set the options.
|
5
7
|
class Options
|
6
|
-
|
7
|
-
@defaults = {
|
8
|
-
:attr_wrapper => "'",
|
9
|
-
:autoclose => %w(area base basefont br col command embed frame
|
10
|
-
hr img input isindex keygen link menuitem meta
|
11
|
-
param source track wbr),
|
12
|
-
:encoding => "UTF-8",
|
13
|
-
:escape_attrs => true,
|
14
|
-
:escape_html => false,
|
15
|
-
:filename => '(haml)',
|
16
|
-
:format => :html5,
|
17
|
-
:hyphenate_data_attrs => true,
|
18
|
-
:line => 1,
|
19
|
-
:mime_type => 'text/html',
|
20
|
-
:preserve => %w(textarea pre code),
|
21
|
-
:remove_whitespace => false,
|
22
|
-
:suppress_eval => false,
|
23
|
-
:ugly => false,
|
24
|
-
:cdata => false,
|
25
|
-
:parser_class => ::Haml::Parser,
|
26
|
-
:compiler_class => ::Haml::Compiler
|
27
|
-
}
|
28
|
-
|
29
8
|
@valid_formats = [:html4, :html5, :xhtml]
|
9
|
+
@buffer_option_keys = [:autoclose, :preserve, :attr_wrapper, :format,
|
10
|
+
:encoding, :escape_html, :escape_filter_interpolations, :escape_attrs, :hyphenate_data_attrs, :cdata]
|
11
|
+
|
12
|
+
class << self
|
13
|
+
# The default option values.
|
14
|
+
# @return Hash
|
15
|
+
def defaults
|
16
|
+
@defaults ||= Haml::TempleEngine.options.to_hash.merge(encoding: 'UTF-8')
|
17
|
+
end
|
30
18
|
|
31
|
-
|
32
|
-
|
19
|
+
# An array of valid values for the `:format` option.
|
20
|
+
# @return Array
|
21
|
+
attr_reader :valid_formats
|
33
22
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
23
|
+
# An array of keys that will be used to provide a hash of options to
|
24
|
+
# {Haml::Buffer}.
|
25
|
+
# @return Hash
|
26
|
+
attr_reader :buffer_option_keys
|
39
27
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
28
|
+
# Returns a subset of defaults: those that {Haml::Buffer} cares about.
|
29
|
+
# @return [{Symbol => Object}] The options hash
|
30
|
+
def buffer_defaults
|
31
|
+
@buffer_defaults ||= buffer_option_keys.inject({}) do |hash, key|
|
32
|
+
hash.merge(key => defaults[key])
|
33
|
+
end
|
34
|
+
end
|
45
35
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
36
|
+
def wrap(options)
|
37
|
+
if options.is_a?(Options)
|
38
|
+
options
|
39
|
+
else
|
40
|
+
Options.new(options)
|
41
|
+
end
|
42
|
+
end
|
51
43
|
end
|
52
44
|
|
53
45
|
# The character that should wrap element attributes. This defaults to `'`
|
@@ -63,7 +55,6 @@ module Haml
|
|
63
55
|
attr_accessor :autoclose
|
64
56
|
|
65
57
|
# The encoding to use for the HTML output.
|
66
|
-
# Only available on Ruby 1.9 or higher.
|
67
58
|
# This can be a string or an `Encoding` Object. Note that Haml **does not**
|
68
59
|
# automatically re-encode Ruby values; any strings coming from outside the
|
69
60
|
# application should be converted before being passed into the Haml
|
@@ -91,6 +82,13 @@ module Haml
|
|
91
82
|
# Defaults to false.
|
92
83
|
attr_accessor :escape_html
|
93
84
|
|
85
|
+
# Sets whether or not to escape HTML-sensitive characters in interpolated strings.
|
86
|
+
# See also {file:REFERENCE.md#escaping_html Escaping HTML} and
|
87
|
+
# {file:REFERENCE.md#unescaping_html Unescaping HTML}.
|
88
|
+
#
|
89
|
+
# Defaults to the current value of `escape_html`.
|
90
|
+
attr_accessor :escape_filter_interpolations
|
91
|
+
|
94
92
|
# The name of the Haml file being parsed.
|
95
93
|
# This is only used as information when exceptions are raised. This is
|
96
94
|
# automatically assigned when working through ActionView, so it's really
|
@@ -137,7 +135,7 @@ module Haml
|
|
137
135
|
# formatting errors.
|
138
136
|
#
|
139
137
|
# Defaults to `false`.
|
140
|
-
|
138
|
+
attr_accessor :remove_whitespace
|
141
139
|
|
142
140
|
# Whether or not attribute hashes and Ruby scripts designated by `=` or `~`
|
143
141
|
# should be evaluated. If this is `true`, said scripts are rendered as empty
|
@@ -146,13 +144,6 @@ module Haml
|
|
146
144
|
# Defaults to `false`.
|
147
145
|
attr_accessor :suppress_eval
|
148
146
|
|
149
|
-
# If set to `true`, Haml makes no attempt to properly indent or format the
|
150
|
-
# HTML output. This significantly improves rendering performance but makes
|
151
|
-
# viewing the source unpleasant.
|
152
|
-
#
|
153
|
-
# Defaults to `true` in Rails production mode, and `false` everywhere else.
|
154
|
-
attr_accessor :ugly
|
155
|
-
|
156
147
|
# Whether to include CDATA sections around javascript and css blocks when
|
157
148
|
# using the `:javascript` or `:css` filters.
|
158
149
|
#
|
@@ -169,9 +160,20 @@ module Haml
|
|
169
160
|
# The compiler class to use. Defaults to Haml::Compiler.
|
170
161
|
attr_accessor :compiler_class
|
171
162
|
|
172
|
-
|
163
|
+
# Enable template tracing. If true, it will add a 'data-trace' attribute to
|
164
|
+
# each tag generated by Haml. The value of the attribute will be the
|
165
|
+
# source template name and the line number from which the tag was generated,
|
166
|
+
# separated by a colon. On Rails applications, the path given will be a
|
167
|
+
# relative path as from the views directory. On non-Rails applications,
|
168
|
+
# the path will be the full path.
|
169
|
+
attr_accessor :trace
|
170
|
+
|
171
|
+
# Key is filter name in String and value is Class to use. Defaults to {}.
|
172
|
+
attr_accessor :filters
|
173
|
+
|
174
|
+
def initialize(values = {})
|
173
175
|
defaults.each {|k, v| instance_variable_set :"@#{k}", v}
|
174
|
-
values.
|
176
|
+
values.each {|k, v| send("#{k}=", v) if defaults.has_key?(k) && !v.nil?}
|
175
177
|
yield if block_given?
|
176
178
|
end
|
177
179
|
|
@@ -188,8 +190,7 @@ module Haml
|
|
188
190
|
send "#{key}=", value
|
189
191
|
end
|
190
192
|
|
191
|
-
[:escape_attrs, :hyphenate_data_attrs, :remove_whitespace, :suppress_eval
|
192
|
-
:ugly].each do |method|
|
193
|
+
[:escape_attrs, :hyphenate_data_attrs, :remove_whitespace, :suppress_eval].each do |method|
|
193
194
|
class_eval(<<-END)
|
194
195
|
def #{method}?
|
195
196
|
!! @#{method}
|
@@ -240,22 +241,13 @@ module Haml
|
|
240
241
|
xhtml? || @cdata
|
241
242
|
end
|
242
243
|
|
243
|
-
def
|
244
|
-
|
245
|
-
@
|
244
|
+
def encoding=(value)
|
245
|
+
return unless value
|
246
|
+
@encoding = value.is_a?(Encoding) ? value.name : value.to_s
|
247
|
+
@encoding = "UTF-8" if @encoding.upcase == "US-ASCII"
|
246
248
|
end
|
247
249
|
|
248
|
-
|
249
|
-
attr_writer :encoding
|
250
|
-
else
|
251
|
-
def encoding=(value)
|
252
|
-
return unless value
|
253
|
-
@encoding = value.is_a?(Encoding) ? value.name : value.to_s
|
254
|
-
@encoding = "UTF-8" if @encoding.upcase == "US-ASCII"
|
255
|
-
end
|
256
|
-
end
|
257
|
-
|
258
|
-
# Returns a subset of options: those that {Haml::Buffer} cares about.
|
250
|
+
# Returns a non-default subset of options: those that {Haml::Buffer} cares about.
|
259
251
|
# All of the values here are such that when `#inspect` is called on the hash,
|
260
252
|
# it can be `Kernel#eval`ed to get the same result back.
|
261
253
|
#
|
@@ -264,7 +256,10 @@ module Haml
|
|
264
256
|
# @return [{Symbol => Object}] The options hash
|
265
257
|
def for_buffer
|
266
258
|
self.class.buffer_option_keys.inject({}) do |hash, key|
|
267
|
-
|
259
|
+
value = public_send(key)
|
260
|
+
if self.class.buffer_defaults[key] != value
|
261
|
+
hash[key] = value
|
262
|
+
end
|
268
263
|
hash
|
269
264
|
end
|
270
265
|
end
|
@@ -274,6 +269,5 @@ module Haml
|
|
274
269
|
def defaults
|
275
270
|
self.class.defaults
|
276
271
|
end
|
277
|
-
|
278
272
|
end
|
279
273
|
end
|