Module: ActionView::Renderable

Extended by:
ActiveSupport::Memoizable
Included in:
InlineTemplate, Template
Defined in:
lib/action_view/renderable.rb

Overview

NOTE: The template that this mixin is being included into is frozen so you cannot set or modify any instance variables

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object


7
8
9
# File 'lib/action_view/renderable.rb', line 7

def self.included(base)
  @@mutex = Mutex.new
end

Instance Method Details

#compiled_sourceObject


20
21
22
# File 'lib/action_view/renderable.rb', line 20

def compiled_source
  handler.call(self)
end

#filenameObject


11
12
13
# File 'lib/action_view/renderable.rb', line 11

def filename
  'compiled-template'
end

#handlerObject


15
16
17
# File 'lib/action_view/renderable.rb', line 15

def handler
  Template.handler_class_for_extension(extension)
end

#method_name(local_assigns) ⇒ Object


52
53
54
55
56
57
# File 'lib/action_view/renderable.rb', line 52

def method_name(local_assigns)
  if local_assigns && local_assigns.any?
    local_assigns_keys = "locals_#{local_assigns.keys.map { |k| k.to_s }.sort.join('_')}"
  end
  ['_run', extension, method_segment, local_assigns_keys].compact.join('_').to_sym
end

#render(view, local_assigns = {}) ⇒ Object


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/action_view/renderable.rb', line 25

def render(view, local_assigns = {})
  compile(local_assigns)

  stack = view.instance_variable_get(:@_render_stack)
  stack.push(self)

  # This is only used for TestResponse to set rendered_template
  unless is_a?(InlineTemplate) || view.instance_variable_get(:@_first_render)
    view.instance_variable_set(:@_first_render, self)
  end

  view.send(:_evaluate_assigns_and_ivars)
  view.send(:_set_controller_content_type, mime_type) if respond_to?(:mime_type)

  result = view.send(method_name(local_assigns), local_assigns) do |*names|
    ivar = :@_proc_for_layout
    if !view.instance_variable_defined?(:"@content_for_#{names.first}") && view.instance_variable_defined?(ivar) && (proc = view.instance_variable_get(ivar))
      view.capture(*names, &proc)
    elsif view.instance_variable_defined?(ivar = :"@content_for_#{names.first || :layout}")
      view.instance_variable_get(ivar)
    end
  end

  stack.pop
  result
end