haml 5.0.4 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +1 -0
  3. data/.github/workflows/test.yml +40 -0
  4. data/.gitignore +16 -15
  5. data/CHANGELOG.md +62 -1
  6. data/Gemfile +18 -14
  7. data/MIT-LICENSE +2 -2
  8. data/README.md +4 -5
  9. data/REFERENCE.md +46 -12
  10. data/Rakefile +93 -103
  11. data/bin/bench +66 -0
  12. data/bin/console +11 -0
  13. data/bin/ruby +3 -0
  14. data/bin/setup +7 -0
  15. data/bin/stackprof +27 -0
  16. data/bin/test +24 -0
  17. data/exe/haml +6 -0
  18. data/ext/haml/extconf.rb +10 -0
  19. data/ext/haml/haml.c +537 -0
  20. data/ext/haml/hescape.c +108 -0
  21. data/ext/haml/hescape.h +20 -0
  22. data/haml.gemspec +39 -30
  23. data/lib/haml/ambles.rb +20 -0
  24. data/lib/haml/attribute_builder.rb +140 -128
  25. data/lib/haml/attribute_compiler.rb +86 -181
  26. data/lib/haml/attribute_parser.rb +86 -124
  27. data/lib/haml/cli.rb +154 -0
  28. data/lib/haml/compiler/children_compiler.rb +126 -0
  29. data/lib/haml/compiler/comment_compiler.rb +39 -0
  30. data/lib/haml/compiler/doctype_compiler.rb +46 -0
  31. data/lib/haml/compiler/script_compiler.rb +116 -0
  32. data/lib/haml/compiler/silent_script_compiler.rb +24 -0
  33. data/lib/haml/compiler/tag_compiler.rb +76 -0
  34. data/lib/haml/compiler.rb +64 -298
  35. data/lib/haml/dynamic_merger.rb +67 -0
  36. data/lib/haml/engine.rb +43 -219
  37. data/lib/haml/error.rb +29 -27
  38. data/lib/haml/escapable.rb +6 -42
  39. data/lib/haml/filters/base.rb +12 -0
  40. data/lib/haml/filters/cdata.rb +20 -0
  41. data/lib/haml/filters/coffee.rb +17 -0
  42. data/lib/haml/filters/css.rb +33 -0
  43. data/lib/haml/filters/erb.rb +10 -0
  44. data/lib/haml/filters/escaped.rb +22 -0
  45. data/lib/haml/filters/javascript.rb +33 -0
  46. data/lib/haml/filters/less.rb +20 -0
  47. data/lib/haml/filters/markdown.rb +11 -0
  48. data/lib/haml/filters/plain.rb +29 -0
  49. data/lib/haml/filters/preserve.rb +22 -0
  50. data/lib/haml/filters/ruby.rb +10 -0
  51. data/lib/haml/filters/sass.rb +15 -0
  52. data/lib/haml/filters/scss.rb +15 -0
  53. data/lib/haml/filters/text_base.rb +25 -0
  54. data/lib/haml/filters/tilt_base.rb +49 -0
  55. data/lib/haml/filters.rb +55 -378
  56. data/lib/haml/force_escapable.rb +29 -0
  57. data/lib/haml/helpers.rb +4 -696
  58. data/lib/haml/html.rb +22 -0
  59. data/lib/haml/identity.rb +13 -0
  60. data/lib/haml/object_ref.rb +30 -0
  61. data/lib/haml/parser.rb +208 -43
  62. data/lib/haml/rails_helpers.rb +51 -0
  63. data/lib/haml/rails_template.rb +55 -0
  64. data/lib/haml/railtie.rb +7 -40
  65. data/lib/haml/ruby_expression.rb +32 -0
  66. data/lib/haml/string_splitter.rb +20 -0
  67. data/lib/haml/template.rb +15 -33
  68. data/lib/haml/temple_line_counter.rb +2 -0
  69. data/lib/haml/util.rb +23 -21
  70. data/lib/haml/version.rb +1 -1
  71. data/lib/haml.rb +8 -19
  72. metadata +222 -50
  73. data/.gitmodules +0 -3
  74. data/.travis.yml +0 -54
  75. data/.yardopts +0 -23
  76. data/TODO +0 -24
  77. data/benchmark.rb +0 -66
  78. data/bin/haml +0 -9
  79. data/lib/haml/.gitattributes +0 -1
  80. data/lib/haml/buffer.rb +0 -235
  81. data/lib/haml/exec.rb +0 -348
  82. data/lib/haml/generator.rb +0 -41
  83. data/lib/haml/helpers/action_view_extensions.rb +0 -59
  84. data/lib/haml/helpers/action_view_mods.rb +0 -129
  85. data/lib/haml/helpers/action_view_xss_mods.rb +0 -59
  86. data/lib/haml/helpers/safe_erubi_template.rb +0 -19
  87. data/lib/haml/helpers/safe_erubis_template.rb +0 -32
  88. data/lib/haml/helpers/xss_mods.rb +0 -110
  89. data/lib/haml/options.rb +0 -273
  90. data/lib/haml/plugin.rb +0 -34
  91. data/lib/haml/sass_rails_filter.rb +0 -46
  92. data/lib/haml/template/options.rb +0 -26
  93. data/lib/haml/temple_engine.rb +0 -121
  94. data/yard/default/.gitignore +0 -1
  95. data/yard/default/fulldoc/html/css/common.sass +0 -15
  96. data/yard/default/layout/html/footer.erb +0 -12
data/lib/haml/exec.rb DELETED
@@ -1,348 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'optparse'
3
- require 'rbconfig'
4
- require 'pp'
5
-
6
- module Haml
7
- # This module handles the various Haml executables (`haml` and `haml-convert`).
8
- module Exec
9
- # An abstract class that encapsulates the executable code for all three executables.
10
- class Generic
11
- # @param args [Array<String>] The command-line arguments
12
- def initialize(args)
13
- @args = args
14
- @options = {:for_engine => {}}
15
- end
16
-
17
- # Parses the command-line arguments and runs the executable.
18
- # Calls `Kernel#exit` at the end, so it never returns.
19
- #
20
- # @see #parse
21
- def parse!
22
- begin
23
- parse
24
- rescue Exception => e
25
- raise e if @options[:trace] || e.is_a?(SystemExit)
26
-
27
- $stderr.print "#{e.class}: " unless e.class == RuntimeError
28
- $stderr.puts "#{e.message}"
29
- $stderr.puts " Use --trace for backtrace."
30
- exit 1
31
- end
32
- exit 0
33
- end
34
-
35
- # Parses the command-line arguments and runs the executable.
36
- # This does not handle exceptions or exit the program.
37
- #
38
- # @see #parse!
39
- def parse
40
- @opts = OptionParser.new(&method(:set_opts))
41
- @opts.parse!(@args)
42
-
43
- process_result
44
-
45
- @options
46
- end
47
-
48
- # @return [String] A description of the executable
49
- def to_s
50
- @opts.to_s
51
- end
52
-
53
- protected
54
-
55
- # Finds the line of the source template
56
- # on which an exception was raised.
57
- #
58
- # @param exception [Exception] The exception
59
- # @return [String] The line number
60
- def get_line(exception)
61
- # SyntaxErrors have weird line reporting
62
- # when there's trailing whitespace,
63
- # which there is for Haml documents.
64
- return (exception.message.scan(/:(\d+)/).first || ["??"]).first if exception.is_a?(::SyntaxError)
65
- (exception.backtrace[0].scan(/:(\d+)/).first || ["??"]).first
66
- end
67
-
68
- # Tells optparse how to parse the arguments
69
- # available for all executables.
70
- #
71
- # This is meant to be overridden by subclasses
72
- # so they can add their own options.
73
- #
74
- # @param opts [OptionParser]
75
- def set_opts(opts)
76
- opts.on('-s', '--stdin', :NONE, 'Read input from standard input instead of an input file') do
77
- @options[:input] = $stdin
78
- end
79
-
80
- opts.on('--trace', :NONE, 'Show a full traceback on error') do
81
- @options[:trace] = true
82
- end
83
-
84
- opts.on('--unix-newlines', 'Use Unix-style newlines in written files.') do
85
- # Note that this is the preferred way to check for Windows, since
86
- # JRuby and Rubinius also run there.
87
- if RbConfig::CONFIG['host_os'] =~ /mswin|windows|mingw/i
88
- @options[:unix_newlines] = true
89
- end
90
- end
91
-
92
- opts.on_tail("-?", "-h", "--help", "Show this message") do
93
- puts opts
94
- exit
95
- end
96
-
97
- opts.on_tail("-v", "--version", "Print version") do
98
- puts("Haml #{::Haml::VERSION}")
99
- exit
100
- end
101
- end
102
-
103
- # Processes the options set by the command-line arguments.
104
- # In particular, sets `@options[:input]` and `@options[:output]`
105
- # to appropriate IO streams.
106
- #
107
- # This is meant to be overridden by subclasses
108
- # so they can run their respective programs.
109
- def process_result
110
- input, output = @options[:input], @options[:output]
111
- args = @args.dup
112
- input ||=
113
- begin
114
- filename = args.shift
115
- @options[:filename] = filename
116
- open_file(filename) || $stdin
117
- end
118
- output ||= open_file(args.shift, 'w') || $stdout
119
-
120
- @options[:input], @options[:output] = input, output
121
- end
122
-
123
- COLORS = { :red => 31, :green => 32, :yellow => 33 }
124
-
125
- # Prints a status message about performing the given action,
126
- # colored using the given color (via terminal escapes) if possible.
127
- #
128
- # @param name [#to_s] A short name for the action being performed.
129
- # Shouldn't be longer than 11 characters.
130
- # @param color [Symbol] The name of the color to use for this action.
131
- # Can be `:red`, `:green`, or `:yellow`.
132
- def puts_action(name, color, arg)
133
- return if @options[:for_engine][:quiet]
134
- printf color(color, "%11s %s\n"), name, arg
135
- end
136
-
137
- # Same as `Kernel.puts`, but doesn't print anything if the `--quiet` option is set.
138
- #
139
- # @param args [Array] Passed on to `Kernel.puts`
140
- def puts(*args)
141
- return if @options[:for_engine][:quiet]
142
- Kernel.puts(*args)
143
- end
144
-
145
- # Wraps the given string in terminal escapes
146
- # causing it to have the given color.
147
- # If terminal esapes aren't supported on this platform,
148
- # just returns the string instead.
149
- #
150
- # @param color [Symbol] The name of the color to use.
151
- # Can be `:red`, `:green`, or `:yellow`.
152
- # @param str [String] The string to wrap in the given color.
153
- # @return [String] The wrapped string.
154
- def color(color, str)
155
- raise "[BUG] Unrecognized color #{color}" unless COLORS[color]
156
-
157
- # Almost any real Unix terminal will support color,
158
- # so we just filter for Windows terms (which don't set TERM)
159
- # and not-real terminals, which aren't ttys.
160
- return str if ENV["TERM"].nil? || ENV["TERM"].empty? || !STDOUT.tty?
161
- return "\e[#{COLORS[color]}m#{str}\e[0m"
162
- end
163
-
164
- private
165
-
166
- def open_file(filename, flag = 'r')
167
- return if filename.nil?
168
- flag = 'wb' if @options[:unix_newlines] && flag == 'w'
169
- File.open(filename, flag)
170
- end
171
-
172
- def handle_load_error(err)
173
- dep = err.message[/^no such file to load -- (.*)/, 1]
174
- raise err if @options[:trace] || dep.nil? || dep.empty?
175
- $stderr.puts <<MESSAGE
176
- Required dependency #{dep} not found!
177
- Run "gem install #{dep}" to get it.
178
- Use --trace for backtrace.
179
- MESSAGE
180
- exit 1
181
- end
182
- end
183
-
184
- # The `haml` executable.
185
- class Haml < Generic
186
- # @param args [Array<String>] The command-line arguments
187
- def initialize(args)
188
- super
189
- @options[:for_engine] = {}
190
- @options[:requires] = []
191
- @options[:load_paths] = []
192
- end
193
-
194
- # Tells optparse how to parse the arguments.
195
- #
196
- # @param opts [OptionParser]
197
- def set_opts(opts)
198
- super
199
-
200
- opts.banner = <<END
201
- Usage: haml [options] [INPUT] [OUTPUT]
202
-
203
- Description:
204
- Converts Haml files to HTML.
205
-
206
- Options:
207
- END
208
-
209
- opts.on('-c', '--check', "Just check syntax, don't evaluate.") do
210
- require 'stringio'
211
- @options[:check_syntax] = true
212
- @options[:output] = StringIO.new
213
- end
214
-
215
- opts.on('-f', '--format NAME',
216
- 'Output format. Can be html5 (default), xhtml, or html4.') do |name|
217
- @options[:for_engine][:format] = name.to_sym
218
- end
219
-
220
- opts.on('-e', '--escape-html',
221
- 'Escape HTML characters (like ampersands and angle brackets) by default.') do
222
- @options[:for_engine][:escape_html] = true
223
- end
224
-
225
- opts.on('--no-escape-attrs',
226
- "Don't escape HTML characters (like ampersands and angle brackets) in attributes.") do
227
- @options[:for_engine][:escape_attrs] = false
228
- end
229
-
230
- opts.on('-q', '--double-quote-attributes',
231
- 'Set attribute wrapper to double-quotes (default is single).') do
232
- @options[:for_engine][:attr_wrapper] = '"'
233
- end
234
-
235
- opts.on('--remove-whitespace',
236
- 'Remove whitespace surrounding and within tags') do
237
- @options[:for_engine][:remove_whitespace] = true
238
- end
239
-
240
- opts.on('--cdata',
241
- 'Always add CDATA sections to javascript and css blocks.') do
242
- @options[:for_engine][:cdata] = true
243
- end
244
-
245
- opts.on('--autoclose LIST',
246
- 'Comma separated list of elements to be automatically self-closed.') do |list|
247
- @options[:for_engine][:autoclose] = list.split(',')
248
- end
249
-
250
- opts.on('--suppress-eval',
251
- 'Don\'t evaluate Ruby scripts.') do
252
- @options[:for_engine][:suppress_eval] = true
253
- end
254
-
255
- opts.on('-r', '--require FILE', "Same as 'ruby -r'.") do |file|
256
- @options[:requires] << file
257
- end
258
-
259
- opts.on('-I', '--load-path PATH', "Same as 'ruby -I'.") do |path|
260
- @options[:load_paths] << path
261
- end
262
-
263
- opts.on('-E ex[:in]', 'Specify the default external and internal character encodings.') do |encoding|
264
- external, internal = encoding.split(':')
265
- Encoding.default_external = external if external && !external.empty?
266
- Encoding.default_internal = internal if internal && !internal.empty?
267
- end
268
-
269
- opts.on('-d', '--debug', "Print out the precompiled Ruby source, and show syntax errors in the Ruby code.") do
270
- @options[:debug] = true
271
- end
272
-
273
- opts.on('-p', '--parse', "Print out Haml parse tree.") do
274
- @options[:parse] = true
275
- end
276
-
277
- end
278
-
279
- # Processes the options set by the command-line arguments,
280
- # and runs the Haml compiler appropriately.
281
- def process_result
282
- super
283
- @options[:for_engine][:filename] = @options[:filename]
284
- input = @options[:input]
285
- output = @options[:output]
286
-
287
- template = input.read()
288
- input.close() if input.is_a? File
289
-
290
- @options[:load_paths].each {|p| $LOAD_PATH << p}
291
- @options[:requires].each {|f| require f}
292
-
293
- begin
294
-
295
- if @options[:parse]
296
- parser = ::Haml::Parser.new(::Haml::Options.new(@options))
297
- pp parser.call(template)
298
- return
299
- end
300
-
301
- engine = ::Haml::Engine.new(template, @options[:for_engine])
302
-
303
- if @options[:check_syntax]
304
- error = validate_ruby(engine.precompiled)
305
- if error
306
- puts error.message.split("\n").first
307
- exit 1
308
- end
309
- puts "Syntax OK"
310
- return
311
- end
312
-
313
- if @options[:debug]
314
- puts engine.precompiled
315
- error = validate_ruby(engine.precompiled)
316
- if error
317
- puts '=' * 100
318
- puts error.message.split("\n")[0]
319
- exit 1
320
- end
321
- return
322
- end
323
-
324
- result = engine.to_html
325
- rescue Exception => e
326
- raise e if @options[:trace]
327
-
328
- case e
329
- when ::Haml::SyntaxError; raise "Syntax error on line #{get_line e}: #{e.message}"
330
- when ::Haml::Error; raise "Haml error on line #{get_line e}: #{e.message}"
331
- else raise "Exception on line #{get_line e}: #{e.message}"
332
- end
333
- end
334
-
335
- output.write(result)
336
- output.close() if output.is_a? File
337
- end
338
-
339
- def validate_ruby(code)
340
- begin
341
- eval("BEGIN {return nil}; #{code}", binding, @options[:filename] || "")
342
- rescue ::SyntaxError # Not to be confused with Haml::SyntaxError
343
- $!
344
- end
345
- end
346
- end
347
- end
348
- end
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: false
2
- module Haml
3
- # Ruby code generator, which is a limited version of Temple::Generator.
4
- # Limit methods since Haml doesn't need most of them.
5
- class Generator
6
- include Temple::Mixins::CompiledDispatcher
7
- include Temple::Mixins::Options
8
-
9
- define_options freeze_static: RUBY_VERSION >= '2.1'
10
-
11
- def call(exp)
12
- compile(exp)
13
- end
14
-
15
- def on_multi(*exp)
16
- exp.map { |e| compile(e) }.join('; ')
17
- end
18
-
19
- def on_static(text)
20
- concat(options[:freeze_static] ? "#{Util.inspect_obj(text)}.freeze" : Util.inspect_obj(text))
21
- end
22
-
23
- def on_dynamic(code)
24
- concat(code)
25
- end
26
-
27
- def on_code(exp)
28
- exp
29
- end
30
-
31
- def on_newline
32
- "\n"
33
- end
34
-
35
- private
36
-
37
- def concat(str)
38
- "_hamlout.buffer << (#{str});"
39
- end
40
- end
41
- end
@@ -1,59 +0,0 @@
1
- # frozen_string_literal: true
2
- module Haml
3
- module Helpers
4
- @@action_view_defined = true
5
-
6
- # This module contains various useful helper methods
7
- # that either tie into ActionView or the rest of the ActionPack stack,
8
- # or are only useful in that context.
9
- # Thus, the methods defined here are only available
10
- # if ActionView is installed.
11
- module ActionViewExtensions
12
- # Returns a value for the "class" attribute
13
- # unique to this controller/action pair.
14
- # This can be used to target styles specifically at this action or controller.
15
- # For example, if the current action were `EntryController#show`,
16
- #
17
- # %div{:class => page_class} My Div
18
- #
19
- # would become
20
- #
21
- # <div class="entry show">My Div</div>
22
- #
23
- # Then, in a stylesheet (shown here as [Sass](http://sass-lang.com)),
24
- # you could refer to this specific action:
25
- #
26
- # .entry.show
27
- # font-weight: bold
28
- #
29
- # or to all actions in the entry controller:
30
- #
31
- # .entry
32
- # color: #00f
33
- #
34
- # @return [String] The class name for the current page
35
- def page_class
36
- "#{controller.controller_name} #{controller.action_name}"
37
- end
38
- alias_method :generate_content_class_names, :page_class
39
-
40
- # Treats all input to \{Haml::Helpers#haml\_concat} within the block
41
- # as being HTML safe for Rails' XSS protection.
42
- # This is useful for wrapping blocks of code that concatenate HTML en masse.
43
- #
44
- # This has no effect if Rails' XSS protection isn't enabled.
45
- #
46
- # @yield A block in which all input to `#haml_concat` is treated as raw.
47
- # @see Haml::Util#rails_xss_safe?
48
- def with_raw_haml_concat
49
- old = instance_variable_defined?(:@_haml_concat_raw) ? @_haml_concat_raw : false
50
- @_haml_concat_raw = true
51
- yield
52
- ensure
53
- @_haml_concat_raw = old
54
- end
55
- end
56
-
57
- include ActionViewExtensions
58
- end
59
- end
@@ -1,129 +0,0 @@
1
- # frozen_string_literal: true
2
- module Haml
3
- module Helpers
4
- module ActionViewMods
5
- def render(*args, &block)
6
- options = args.first
7
-
8
- # If render :layout is used with a block, it concats rather than returning
9
- # a string so we need it to keep thinking it's Haml until it hits the
10
- # sub-render.
11
- if is_haml? && !(options.is_a?(Hash) && options[:layout] && block_given?)
12
- return non_haml { super }
13
- end
14
- super
15
- end
16
-
17
- def output_buffer
18
- return haml_buffer.buffer if is_haml?
19
- super
20
- end
21
-
22
- def output_buffer=(new_buffer)
23
- if is_haml?
24
- if Haml::Util.rails_xss_safe? && new_buffer.is_a?(ActiveSupport::SafeBuffer)
25
- new_buffer = String.new(new_buffer)
26
- end
27
- haml_buffer.buffer = new_buffer
28
- else
29
- super
30
- end
31
- end
32
- end
33
- ActionView::Base.send(:prepend, ActionViewMods)
34
- end
35
- end
36
-
37
- module ActionView
38
- module Helpers
39
- module CaptureHelper
40
- def capture_with_haml(*args, &block)
41
- if Haml::Helpers.block_is_haml?(block)
42
- #double assignment is to avoid warnings
43
- _hamlout = _hamlout = eval('_hamlout', block.binding) # Necessary since capture_haml checks _hamlout
44
-
45
- capture_haml(*args, &block)
46
- else
47
- capture_without_haml(*args, &block)
48
- end
49
- end
50
- alias_method :capture_without_haml, :capture
51
- alias_method :capture, :capture_with_haml
52
- end
53
-
54
- module TagHelper
55
- def content_tag_with_haml(name, *args, &block)
56
- return content_tag_without_haml(name, *args, &block) unless is_haml?
57
-
58
- preserve = haml_buffer.options.fetch(:preserve, %w[textarea pre code]).include?(name.to_s)
59
-
60
- if block_given? && block_is_haml?(block) && preserve
61
- return content_tag_without_haml(name, *args) do
62
- haml_buffer.fix_textareas!(Haml::Helpers.preserve(&block)).html_safe
63
- end
64
- end
65
-
66
- content = content_tag_without_haml(name, *args, &block)
67
- if preserve && content
68
- content = haml_buffer.fix_textareas!(Haml::Helpers.preserve(content)).html_safe
69
- end
70
- content
71
- end
72
-
73
- alias_method :content_tag_without_haml, :content_tag
74
- alias_method :content_tag, :content_tag_with_haml
75
- end
76
-
77
- module HamlSupport
78
- include Haml::Helpers
79
-
80
- def haml_buffer
81
- @template_object.send :haml_buffer
82
- end
83
-
84
- def is_haml?
85
- @template_object.send :is_haml?
86
- end
87
- end
88
-
89
- module Tags
90
- class TextArea
91
- include HamlSupport
92
- end
93
- end
94
-
95
- class InstanceTag
96
- include HamlSupport
97
-
98
- def content_tag(*args, &block)
99
- html_tag = content_tag_with_haml(*args, &block)
100
- return html_tag unless respond_to?(:error_wrapping)
101
- return error_wrapping(html_tag) if method(:error_wrapping).arity == 1
102
- return html_tag unless object.respond_to?(:errors) && object.errors.respond_to?(:on)
103
- return error_wrapping(html_tag, object.errors.on(@method_name))
104
- end
105
- end
106
-
107
- module FormTagHelper
108
- def form_tag_with_haml(url_for_options = {}, options = {}, *parameters_for_url, &proc)
109
- if is_haml?
110
- wrap_block = block_given? && block_is_haml?(proc)
111
- if wrap_block
112
- oldproc = proc
113
- proc = haml_bind_proc do |*args|
114
- concat "\n"
115
- with_tabs(1) {oldproc.call(*args)}
116
- end
117
- end
118
- res = form_tag_without_haml(url_for_options, options, *parameters_for_url, &proc) << "\n"
119
- res << "\n" if wrap_block
120
- res
121
- else
122
- form_tag_without_haml(url_for_options, options, *parameters_for_url, &proc)
123
- end
124
- end
125
- alias_method :form_tag_without_haml, :form_tag
126
- alias_method :form_tag, :form_tag_with_haml
127
- end
128
- end
129
- end
@@ -1,59 +0,0 @@
1
- # frozen_string_literal: true
2
- module ActionView
3
- module Helpers
4
- module CaptureHelper
5
- def with_output_buffer_with_haml_xss(*args, &block)
6
- res = with_output_buffer_without_haml_xss(*args, &block)
7
- case res
8
- when Array; res.map {|s| Haml::Util.html_safe(s)}
9
- when String; Haml::Util.html_safe(res)
10
- else; res
11
- end
12
- end
13
- alias_method :with_output_buffer_without_haml_xss, :with_output_buffer
14
- alias_method :with_output_buffer, :with_output_buffer_with_haml_xss
15
- end
16
-
17
- module FormTagHelper
18
- def form_tag_with_haml_xss(*args, &block)
19
- res = form_tag_without_haml_xss(*args, &block)
20
- res = Haml::Util.html_safe(res) unless block_given?
21
- res
22
- end
23
- alias_method :form_tag_without_haml_xss, :form_tag
24
- alias_method :form_tag, :form_tag_with_haml_xss
25
- end
26
-
27
- module FormHelper
28
- def form_for_with_haml_xss(*args, &block)
29
- res = form_for_without_haml_xss(*args, &block)
30
- return Haml::Util.html_safe(res) if res.is_a?(String)
31
- return res
32
- end
33
- alias_method :form_for_without_haml_xss, :form_for
34
- alias_method :form_for, :form_for_with_haml_xss
35
- end
36
-
37
- module TextHelper
38
- def concat_with_haml_xss(string)
39
- if is_haml?
40
- haml_buffer.buffer.concat(haml_xss_html_escape(string))
41
- else
42
- concat_without_haml_xss(string)
43
- end
44
- end
45
- alias_method :concat_without_haml_xss, :concat
46
- alias_method :concat, :concat_with_haml_xss
47
-
48
- def safe_concat_with_haml_xss(string)
49
- if is_haml?
50
- haml_buffer.buffer.concat(string)
51
- else
52
- safe_concat_without_haml_xss(string)
53
- end
54
- end
55
- alias_method :safe_concat_without_haml_xss, :safe_concat
56
- alias_method :safe_concat, :safe_concat_with_haml_xss
57
- end
58
- end
59
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'action_view'
3
-
4
- module Haml
5
- class ErubiTemplateHandler < ActionView::Template::Handlers::ERB::Erubi
6
-
7
- def initialize(*args, &blk)
8
- @newline_pending = 0
9
- super
10
- end
11
- end
12
-
13
- class SafeErubiTemplate < Tilt::ErubiTemplate
14
- def prepare
15
- @options.merge! engine_class: Haml::ErubiTemplateHandler
16
- super
17
- end
18
- end
19
- end
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'action_view'
3
-
4
- module Haml
5
-
6
- class ErubisTemplateHandler < ActionView::Template::Handlers::Erubis
7
-
8
- def initialize(*args, &blk)
9
- @newline_pending = 0
10
- super
11
- end
12
- end
13
-
14
- class SafeErubisTemplate < Tilt::ErubisTemplate
15
-
16
- def initialize_engine
17
- end
18
-
19
- def prepare
20
- @options.merge! :engine_class => Haml::ErubisTemplateHandler
21
- super
22
- end
23
-
24
- def precompiled_preamble(locals)
25
- [super, "@output_buffer = ActionView::OutputBuffer.new;"].join("\n")
26
- end
27
-
28
- def precompiled_postamble(locals)
29
- [super, '@output_buffer.to_s'].join("\n")
30
- end
31
- end
32
- end