Class: Hanami::View::HTMLSafeStringBuffer Private
- Inherits:
-
Temple::Generators::StringBuffer
- Object
- Temple::Generators::StringBuffer
- Hanami::View::HTMLSafeStringBuffer
- Defined in:
- lib/hanami/view/html_safe_string_buffer.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Specialized Temple buffer class that marks block-captured strings as HTML safe.
This is important for any scope or part methods that receive a string from a yielded block and then determine whether to escape that string based on its ‘.html_safe?` value.
In this case, since blocks captured templates intentionally contain HTML (this is the purpose of the template after all), it makes sense to mark the entire captured block string as HTML safe.
This is compatible with escaping of values interpolated into the template, since those will have already been automatically escaped by the template engine when they are evaluated, before the overall block is captured.
This filter is included in all three of our supported HTML template engines (ERB, Haml and Slim) to provide consistent behavior across all.
Instance Method Summary collapse
-
#call(exp) ⇒ Object
private
Replace ‘Temple::Generator::ArrayBuffer#call` (which is used via the superclass of `StringBuffer`) with the standard implementation from the base `Temple::Generator`.
-
#return_buffer ⇒ Object
private
Marks the string returned from the captured buffer as HTML safe.
Instance Method Details
#call(exp) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Replace ‘Temple::Generator::ArrayBuffer#call` (which is used via the superclass of `StringBuffer`) with the standard implementation from the base `Temple::Generator`.
This avoids certain specialisations in ‘ArrayBuffer#call` that prevent `#return_buffer` from being called. For our needs, `#return_buffer` must be called at all times in order to ensure the captured string is consistently marked as `.html_safe`.
36 37 38 |
# File 'lib/hanami/view/html_safe_string_buffer.rb', line 36 def call(exp) [preamble, compile(exp), postamble].flatten.compact.join('; ') end |
#return_buffer ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Marks the string returned from the captured buffer as HTML safe.
41 42 43 |
# File 'lib/hanami/view/html_safe_string_buffer.rb', line 41 def return_buffer "#{buffer}.html_safe" end |