Class: Haml::Helpers::ErrorReturn
- Inherits:
-
Object
- Object
- Haml::Helpers::ErrorReturn
- Defined in:
- /var/build/temp/tmp.g5C1f6zb2g/4.0-0-0/ruby-haml/ruby-haml-3.1.6/lib/haml/helpers.rb,
/var/build/temp/tmp.g5C1f6zb2g/4.0-0-0/ruby-haml/ruby-haml-3.1.6/lib/haml/helpers/xss_mods.rb
Overview
An object that raises an error when #to_s is called. It’s used to raise an error when the return value of a helper is used when it shouldn’t be.
Instance Method Summary (collapse)
-
- (ErrorReturn) initialize(method)
constructor
A new instance of ErrorReturn.
-
- (String) inspect
A human-readable string representation.
-
- to_s
(also: #html_safe, #html_safe?, #html_safe!)
Raises an error.
Constructor Details
- (ErrorReturn) initialize(method)
A new instance of ErrorReturn
12 13 14 15 16 17 18 |
# File '/var/build/temp/tmp.g5C1f6zb2g/4.0-0-0/ruby-haml/ruby-haml-3.1.6/lib/haml/helpers.rb', line 12
def initialize(method)
@message = <<MESSAGE
#{method} outputs directly to the Haml template.
Disregard its return value and use the - operator,
or use capture_haml to get the value as a String.
MESSAGE
end
|
Instance Method Details
- (String) inspect
A human-readable string representation
43 44 45 |
# File '/var/build/temp/tmp.g5C1f6zb2g/4.0-0-0/ruby-haml/ruby-haml-3.1.6/lib/haml/helpers.rb', line 43
def inspect
"Haml::Helpers::ErrorReturn(#{@message.inspect})"
end
|
- to_s Also known as: html_safe, html_safe?, html_safe!
Raises an error.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File '/var/build/temp/tmp.g5C1f6zb2g/4.0-0-0/ruby-haml/ruby-haml-3.1.6/lib/haml/helpers.rb', line 23
def to_s
raise Haml::Error.new(@message)
rescue Haml::Error => e
e.backtrace.shift
# If the ErrorReturn is used directly in the template,
# we don't want Haml's stuff to get into the backtrace,
# so we get rid of the format_script line.
#
# We also have to subtract one from the Haml line number
# since the value is passed to format_script the line after
# it's actually used.
if e.backtrace.first =~ /^\(eval\):\d+:in `format_script/
e.backtrace.shift
e.backtrace.first.gsub!(/^\(haml\):(\d+)/) {|s| "(haml):#{$1.to_i - 1}"}
end
raise e
end
|