Class: Spektr::Erubi

Inherits:
Erubi::Engine
  • Object
show all
Defined in:
lib/spektr/erubi.rb

Instance Method Summary collapse

Constructor Details

#initialize(input, properties = {}) ⇒ Erubi

Returns a new instance of Erubi.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/spektr/erubi.rb', line 5

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

  # Dup properties so that we don't modify argument
  properties = Hash[properties]
  properties[:preamble]   = ""
  properties[:postamble]  = "@output_buffer.to_s"
  properties[:bufvar]     = "@output_buffer"
  properties[:escapefunc] = ""

  super
end

Instance Method Details

#evaluate(action_view_erb_handler_context) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/spektr/erubi.rb', line 18

def evaluate(action_view_erb_handler_context)
  src = @src
  view = Class.new(ActionView::Base) {
    include action_view_erb_handler_context._routes.url_helpers
    class_eval("define_method(:_template) { |local_assigns, output_buffer| #{src} }", defined?(@filename) ? @filename : "(erubi)", 0)
  }.empty
  view._run(:_template, nil, {}, ActionView::OutputBuffer.new)
end