Class: ActionView::Template

Inherits:
Object show all
Defined in:
lib/action_view/template.rb

Overview

:nodoc:

Direct Known Subclasses

InlineTemplate, PartialTemplate

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(view, path, use_full_path, locals = {}) ⇒ Template

Returns a new instance of Template.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/action_view/template.rb', line 7

def initialize(view, path, use_full_path, locals = {})
  @view = view
  @finder = @view.finder
  # Clear the forward slash at the beginning if exists
  @path = use_full_path ? path.sub(/^\//, '') : path
  @view.first_render ||= @path
  @source = nil # Don't read the source until we know that it is required
  set_extension_and_file_name(use_full_path)
  
  @locals = locals || {}
  @handler = self.class.handler_class_for_extension(@extension).new(@view)
end

Instance Attribute Details

#extensionObject (readonly)

Returns the value of attribute extension.



5
6
7
# File 'lib/action_view/template.rb', line 5

def extension
  @extension
end

#filenameObject (readonly)

Returns the value of attribute filename.



5
6
7
# File 'lib/action_view/template.rb', line 5

def filename
  @filename
end

#handlerObject (readonly)

Returns the value of attribute handler.



5
6
7
# File 'lib/action_view/template.rb', line 5

def handler
  @handler
end

#localsObject

Returns the value of attribute locals.



4
5
6
# File 'lib/action_view/template.rb', line 4

def locals
  @locals
end

#methodObject (readonly)

Returns the value of attribute method.



5
6
7
# File 'lib/action_view/template.rb', line 5

def method
  @method
end

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/action_view/template.rb', line 5

def path
  @path
end

#path_without_extensionObject (readonly)

Returns the value of attribute path_without_extension.



5
6
7
# File 'lib/action_view/template.rb', line 5

def path_without_extension
  @path_without_extension
end

Instance Method Details

#base_path_for_exceptionObject



45
46
47
# File 'lib/action_view/template.rb', line 45

def base_path_for_exception
  @finder.find_base_path_for("#{@path_without_extension}.#{@extension}") || @finder.view_paths.first
end

#method_keyObject



41
42
43
# File 'lib/action_view/template.rb', line 41

def method_key
  @filename
end

#prepare!Object



49
50
51
52
53
54
55
56
57
# File 'lib/action_view/template.rb', line 49

def prepare!
  @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
end

#renderObject



32
33
34
35
# File 'lib/action_view/template.rb', line 32

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

#render_templateObject



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/action_view/template.rb', line 20

def render_template
  render
rescue Exception => e
  raise e unless filename
  if TemplateError === e
    e.sub_template_of(filename)
    raise e
  else
    raise TemplateError.new(self, @view.assigns, e)
  end
end

#sourceObject



37
38
39
# File 'lib/action_view/template.rb', line 37

def source
  @source ||= File.read(self.filename)
end