aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/renderable.rb
blob: d73dc3e2dc9f9f7b3510f851bdbbce27ec9500c9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
module ActionView
  module Renderable
    # TODO: Local assigns should not be tied to template instance
    attr_accessor :locals

    # TODO: These readers should be private
    attr_reader :filename, :source, :handler, :method_key, :method

    def render
      prepare!
      @handler.render(self)
    end

    def method_name
      ['_run', @extension, method_name_path_segment].compact.join('_').to_sym
    end

    private
      def prepare!
        unless @prepared
          @view.send(:evaluate_assigns)
          @view.current_render_extension = @extension

          if @handler.compilable?
            @handler.compile_template(self) # compile the given template, if necessary
            @method = @view.method_names[method_key] # Set the method name for this template and run it
          end

          @prepared = true
        end
      end
  end
end