Class: ActionView::Template::Handlers::ERB::Erubis

Inherits:
Erubis::Eruby
  • Object
show all
Defined in:
lib/action_view/template/handlers/erb/erubis.rb

Constant Summary collapse

BLOCK_EXPR =
/\s*((\s+|\))do|\{)(\s*\|[^|]*\|)?\s*\Z/

Instance Method Summary collapse

Instance Method Details

#add_expr(src, code, indicator) ⇒ Object

Erubis toggles <%= and <%== behavior when escaping is enabled. We override to always treat <%== as escaped.



32
33
34
35
36
37
38
39
# File 'lib/action_view/template/handlers/erb/erubis.rb', line 32

def add_expr(src, code, indicator)
  case indicator
  when "=="
    add_expr_escaped(src, code)
  else
    super
  end
end

#add_expr_escaped(src, code) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/action_view/template/handlers/erb/erubis.rb', line 52

def add_expr_escaped(src, code)
  flush_newline_if_pending(src)
  if BLOCK_EXPR.match?(code)
    src << "@output_buffer.safe_expr_append= " << code
  else
    src << "@output_buffer.safe_expr_append=(" << code << ");"
  end
end

#add_expr_literal(src, code) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/action_view/template/handlers/erb/erubis.rb', line 43

def add_expr_literal(src, code)
  flush_newline_if_pending(src)
  if BLOCK_EXPR.match?(code)
    src << "@output_buffer.append= " << code
  else
    src << "@output_buffer.append=(" << code << ");"
  end
end

#add_postamble(src) ⇒ Object



66
67
68
69
# File 'lib/action_view/template/handlers/erb/erubis.rb', line 66

def add_postamble(src)
  flush_newline_if_pending(src)
  src << "@output_buffer.to_s"
end

#add_preamble(src) ⇒ Object

:nodoc: all



10
11
12
13
# File 'lib/action_view/template/handlers/erb/erubis.rb', line 10

def add_preamble(src)
  @newline_pending = 0
  src << "@output_buffer = output_buffer || ActionView::OutputBuffer.new;"
end

#add_stmt(src, code) ⇒ Object



61
62
63
64
# File 'lib/action_view/template/handlers/erb/erubis.rb', line 61

def add_stmt(src, code)
  flush_newline_if_pending(src)
  super
end

#add_text(src, text) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/action_view/template/handlers/erb/erubis.rb', line 15

def add_text(src, text)
  return if text.empty?

  if text == "\n"
    @newline_pending += 1
  else
    src << "@output_buffer.safe_append='"
    src << "\n" * @newline_pending if @newline_pending > 0
    src << escape_text(text)
    src << "'.freeze;"

    @newline_pending = 0
  end
end

#flush_newline_if_pending(src) ⇒ Object



71
72
73
74
75
76
# File 'lib/action_view/template/handlers/erb/erubis.rb', line 71

def flush_newline_if_pending(src)
  if @newline_pending > 0
    src << "@output_buffer.safe_append='#{"\n" * @newline_pending}'.freeze;"
    @newline_pending = 0
  end
end