Class: Temple::Filters::Escapable
- Inherits:
-
Temple::Filter
- Object
- Temple::Filter
- Temple::Filters::Escapable
- Defined in:
- lib/temple/filters/escapable.rb
Overview
Escape dynamic or static expressions. This filter must be used after Temple::HTML::* and before the generators. It can be enclosed with Temple::Filters::DynamicInliner filters to reduce calls to Temple::Utils#escape_html.
Constant Summary
Constants included from Utils
Utils::ESCAPE_HTML, Utils::ESCAPE_HTML_PATTERN
Instance Attribute Summary
Attributes included from Mixins::Options
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Escapable
constructor
A new instance of Escapable.
- #on_dynamic(value) ⇒ Object
- #on_escape(flag, exp) ⇒ Object
- #on_static(value) ⇒ Object
Methods included from Mixins::Options
Methods included from Mixins::ControlFlowDispatcher
#on_block, #on_case, #on_cond, #on_if
Methods included from Mixins::CoreDispatcher
Methods included from Mixins::CompiledDispatcher
Methods included from Utils
#empty_exp?, #escape_html, #escape_html_safe, #indent_dynamic, #unique_name
Constructor Details
#initialize(opts = {}) ⇒ Escapable
Returns a new instance of Escapable.
16 17 18 19 20 21 22 |
# File 'lib/temple/filters/escapable.rb', line 16 def initialize(opts = {}) super @escape_code = [:escape_code] || "::Temple::Utils.escape_html#{[:use_html_safe] ? '_safe' : ''}((%s))" @escaper = eval("proc {|v| #{@escape_code % 'v'} }") @escape = false end |
Instance Method Details
#on_dynamic(value) ⇒ Object
36 37 38 |
# File 'lib/temple/filters/escapable.rb', line 36 def on_dynamic(value) [:dynamic, @escape ? @escape_code % value : value] end |
#on_escape(flag, exp) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/temple/filters/escapable.rb', line 24 def on_escape(flag, exp) old = @escape @escape = flag && ![:disable_escape] compile(exp) ensure @escape = old end |
#on_static(value) ⇒ Object
32 33 34 |
# File 'lib/temple/filters/escapable.rb', line 32 def on_static(value) [:static, @escape ? @escaper[value] : value] end |