aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/renderable.rb
blob: 6a8a0e44fcc558533910cec69236fcad0dc26855 (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
34
35
36
37
38
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

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

    def method
      ['_run', @extension, @method_segment, local_assigns_keys].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
          end

          @prepared = true
        end
      end

      def local_assigns_keys
        if @locals && @locals.any?
          "locals_#{@locals.keys.map { |k| k.to_s }.sort.join('_')}"
        end
      end
  end
end