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