Class: Flay::Erubi
- Inherits:
-
Erubi::Engine
- Object
- Erubi::Engine
- Flay::Erubi
- Defined in:
- lib/flay_erb.rb
Overview
stolen (and munged) from lib/action_view/template/handlers/erb/erubi.rb this is also in the debride-erb gem, update both!
Constant Summary collapse
- BLOCK_EXPR =
/\s*((\s+|\))do|\{)(\s*\|[^|]*\|)?\s*\Z/
Instance Method Summary collapse
- #add_code(code) ⇒ Object
- #add_expression(indicator, code) ⇒ Object
- #add_postamble(_) ⇒ Object
- #add_text(text) ⇒ Object
- #flush_newline_if_pending(src) ⇒ Object
-
#initialize(input, properties = {}) ⇒ Erubi
constructor
:nodoc: all.
Constructor Details
#initialize(input, properties = {}) ⇒ Erubi
:nodoc: all
27 28 29 30 31 32 33 34 35 |
# File 'lib/flay_erb.rb', line 27 def initialize(input, properties = {}) @newline_pending = 0 properties[:postamble] = "_buf.to_s" properties[:bufvar] = "_buf" properties[:freeze_template_literals] = false super end |
Instance Method Details
#add_code(code) ⇒ Object
70 71 72 73 |
# File 'lib/flay_erb.rb', line 70 def add_code(code) flush_newline_if_pending(src) super end |
#add_expression(indicator, code) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/flay_erb.rb', line 54 def add_expression(indicator, code) flush_newline_if_pending(src) if (indicator == "==") || @escape src << "_buf.safe_expr_append=" else src << "_buf.append=" end if BLOCK_EXPR.match?(code) src << " " << code else src << "(" << code << ");" end end |
#add_postamble(_) ⇒ Object
75 76 77 78 |
# File 'lib/flay_erb.rb', line 75 def add_postamble(_) flush_newline_if_pending(src) super end |
#add_text(text) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/flay_erb.rb', line 37 def add_text(text) return if text.empty? if text == "\n" @newline_pending += 1 else src << "_buf.safe_append='" src << "\n" * @newline_pending if @newline_pending > 0 src << text.gsub(/['\\]/, '\\\\\&') src << "';" @newline_pending = 0 end end |
#flush_newline_if_pending(src) ⇒ Object
80 81 82 83 84 85 |
# File 'lib/flay_erb.rb', line 80 def flush_newline_if_pending(src) if @newline_pending > 0 src << "_buf.safe_append='#{"\n" * @newline_pending}';" @newline_pending = 0 end end |