Class: Padrino::SafeBuffer
Overview
Padrino::SafeBuffer is based on ActiveSupport::SafeBuffer
Defined Under Namespace
Classes: SafeConcatError
Constant Summary collapse
- UNSAFE_STRING_METHODS =
%w[ capitalize chomp chop delete downcase gsub lstrip next reverse rstrip slice squeeze strip sub succ swapcase tr tr_s upcase ]
Instance Method Summary collapse
- #%(other) ⇒ Object
- #+(other) ⇒ Object
- #[](*args) ⇒ Object
- #clone_empty ⇒ Object
- #concat(value) ⇒ Object (also: #<<)
- #encode_with(coder) ⇒ Object
- #html_safe? ⇒ Boolean
-
#initialize(str = '') ⇒ SafeBuffer
constructor
A new instance of SafeBuffer.
- #initialize_copy(other) ⇒ Object
- #prepend(value) ⇒ Object
- #safe_concat(value) ⇒ Object
- #to_param ⇒ Object
- #to_s ⇒ Object
Methods inherited from String
Constructor Details
#initialize(str = '') ⇒ SafeBuffer
Returns a new instance of SafeBuffer.
37 38 39 40 |
# File 'lib/padrino/safe_buffer.rb', line 37 def initialize(str = '') @html_safe = true super end |
Instance Method Details
#%(other) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/padrino/safe_buffer.rb', line 64 def %(other) escaped_args = case other when Hash other.transform_values { |arg| html_escape_interpolated_argument(arg) } else Array(other).map { |arg| html_escape_interpolated_argument(arg) } end self.class.new(super(escaped_args)) end |
#+(other) ⇒ Object
60 61 62 |
# File 'lib/padrino/safe_buffer.rb', line 60 def +(other) dup.concat(other) end |
#[](*args) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/padrino/safe_buffer.rb', line 20 def [](*args) if args.size < 2 super elsif html_safe? new_safe_buffer = super new_safe_buffer&.instance_variable_set :@html_safe, true new_safe_buffer else to_str[*args] end end |
#clone_empty ⇒ Object
47 48 49 |
# File 'lib/padrino/safe_buffer.rb', line 47 def clone_empty self[0, 0] end |
#concat(value) ⇒ Object Also known as: <<
51 52 53 |
# File 'lib/padrino/safe_buffer.rb', line 51 def concat(value) super(html_escape_interpolated_argument(value)) end |
#encode_with(coder) ⇒ Object
88 89 90 |
# File 'lib/padrino/safe_buffer.rb', line 88 def encode_with(coder) coder.represent_object nil, to_str end |
#html_safe? ⇒ Boolean
76 77 78 |
# File 'lib/padrino/safe_buffer.rb', line 76 def html_safe? defined?(@html_safe) && @html_safe end |
#initialize_copy(other) ⇒ Object
42 43 44 45 |
# File 'lib/padrino/safe_buffer.rb', line 42 def initialize_copy(other) super @html_safe = other.html_safe? end |
#prepend(value) ⇒ Object
56 57 58 |
# File 'lib/padrino/safe_buffer.rb', line 56 def prepend(value) super(html_escape_interpolated_argument(value)) end |
#safe_concat(value) ⇒ Object
32 33 34 35 |
# File 'lib/padrino/safe_buffer.rb', line 32 def safe_concat(value) raise SafeConcatError unless html_safe? original_concat(value) end |
#to_param ⇒ Object
84 85 86 |
# File 'lib/padrino/safe_buffer.rb', line 84 def to_param to_str end |
#to_s ⇒ Object
80 81 82 |
# File 'lib/padrino/safe_buffer.rb', line 80 def to_s self end |