Class: EZML::Escapable
- Defined in:
- lib/ezml/escapable.rb
Instance Method Summary collapse
-
#initialize ⇒ Escapable
constructor
A new instance of Escapable.
- #on_dynamic(value) ⇒ Object
- #on_escape(flag, exp) ⇒ Object
- #on_static(value) ⇒ Object
Constructor Details
#initialize ⇒ Escapable
Returns a new instance of Escapable.
4 5 6 7 8 9 10 11 |
# File 'lib/ezml/escapable.rb', line 4 def initialize(*) super @escape_code = "::EZML::Helpers.html_escape((%s))" @escaper = eval("proc {|v| #{@escape_code % 'v'} }") @once_escape_code = "::EZML::Helpers.escape_once((%s))" @once_escaper = eval("proc {|v| #{@once_escape_code % 'v'} }") @escape = false end |
Instance Method Details
#on_dynamic(value) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ezml/escapable.rb', line 33 def on_dynamic(value) [:dynamic, if @escape == :once @once_escape_code % value elsif @escape @escape_code % value else "(#{value}).to_s" end ] end |
#on_escape(flag, exp) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/ezml/escapable.rb', line 13 def on_escape(flag, exp) old = @escape @escape = flag compile(exp) ensure @escape = old end |
#on_static(value) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ezml/escapable.rb', line 21 def on_static(value) [:static, if @escape == :once @once_escaper[value] elsif @escape @escaper[value] else value end ] end |