/usr/lib/ruby/vendor_ruby/slim/end_inserter.rb is in ruby-slim 2.0.2-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | module Slim
# In Slim you don't need to close any blocks:
#
# - if Slim.awesome?
# | But of course it is!
#
# However, the parser is not smart enough (and that's a good thing) to
# automatically insert end's where they are needed. Luckily, this filter
# does *exactly* that (and it does it well!)
#
# @api private
class EndInserter < Filter
BLOCK_REGEX = /\A(else|elsif|when|rescue|ensure)\b/
END_REGEX = /\Aend\b/
# Handle multi expression `[:multi, *exps]`
#
# @return [Array] Corrected Temple expression with ends inserted
def on_multi(*exps)
result = [:multi]
# This variable is true if the previous line was
# (1) a control code and (2) contained indented content.
prev_indent = false
exps.each do |exp|
if control?(exp)
raise(Temple::FilterError, 'Explicit end statements are forbidden') if exp[2] =~ END_REGEX
# Two control code in a row. If this one is *not*
# an else block, we should close the previous one.
append_end(result) if prev_indent && exp[2] !~ BLOCK_REGEX
# Indent if the control code contains something.
prev_indent = !empty_exp?(exp[3])
elsif exp[0] != :newline && prev_indent
# This is *not* a control code, so we should close the previous one.
# Ignores newlines because they will be inserted after each line.
append_end(result)
prev_indent = false
end
result << compile(exp)
end
# The last line can be a control code too.
prev_indent ? append_end(result) : result
end
private
# Appends an end
def append_end(result)
result << [:code, 'end']
end
# Checks if an expression is a Slim control code
def control?(exp)
exp[0] == :slim && exp[1] == :control
end
end
end
|