123456789_123456789_123456789_123456789_123456789_

Class: ActionView::Template::Handlers::ERB::Erubi

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Erubi::Engine
Instance Chain:
self, Erubi::Engine
Inherits: Erubi::Engine
  • ::Object
Defined in: actionview/lib/action_view/template/handlers/erb/erubi.rb

Constant Summary

Class Method Summary

Instance Method Summary

Constructor Details

.new(input, properties = {}) ⇒ Erubi

This method is for internal use only.
[ GitHub ]

  
# File 'actionview/lib/action_view/template/handlers/erb/erubi.rb', line 11

def initialize(input, properties = {})
  @newline_pending = 0

  # Dup properties so that we don't modify argument
  properties = Hash[properties]

  properties[:bufvar]     ||= "@output_buffer"
  properties[:preamble]   ||= ""
  properties[:postamble]  ||= "#{properties[:bufvar]}"

  # Tell Eruby that whether template will be compiled with `frozen_string_literal: true`
  properties[:freeze_template_literals] = !Template.frozen_string_literal

  properties[:escapefunc] = ""

  super
end

Instance Method Details

#add_code(code) (private)

[ GitHub ]

  
# File 'actionview/lib/action_view/template/handlers/erb/erubi.rb', line 65

def add_code(code)
  flush_newline_if_pending(src)
  super
end

#add_expression(indicator, code) (private)

[ GitHub ]

  
# File 'actionview/lib/action_view/template/handlers/erb/erubi.rb', line 47

def add_expression(indicator, code)
  flush_newline_if_pending(src)

  with_buffer do
    if (indicator == "==") || @escape
      src << ".safe_expr_append="
    else
      src << ".append="
    end

    if BLOCK_EXPR.match?(code)
      src << " " << code
    else
      src << "(" << code << ")"
    end
  end
end

#add_postamble(_) (private)

[ GitHub ]

  
# File 'actionview/lib/action_view/template/handlers/erb/erubi.rb', line 70

def add_postamble(_)
  flush_newline_if_pending(src)
  super
end

#add_text(text) (private)

[ GitHub ]

  
# File 'actionview/lib/action_view/template/handlers/erb/erubi.rb', line 30

def add_text(text)
  return if text.empty?

  if text == "\n"
    @newline_pending += 1
  else
    with_buffer do
      src << ".safe_append='"
      src << "\n" * @newline_pending if @newline_pending > 0
      src << text.gsub(/['\\]/, '\\\\\&') << @text_end
    end
    @newline_pending = 0
  end
end

#flush_newline_if_pending(src) (private)

[ GitHub ]

  
# File 'actionview/lib/action_view/template/handlers/erb/erubi.rb', line 75

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