Class: ActionView::Template
Overview
:nodoc:
Direct Known Subclasses
Instance Attribute Summary collapse
-
#extension ⇒ Object
readonly
Returns the value of attribute extension.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#handler ⇒ Object
readonly
Returns the value of attribute handler.
-
#locals ⇒ Object
Returns the value of attribute locals.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#path_without_extension ⇒ Object
readonly
Returns the value of attribute path_without_extension.
Instance Method Summary collapse
- #base_path_for_exception ⇒ Object
-
#initialize(view, path, use_full_path, locals = {}) ⇒ Template
constructor
A new instance of Template.
- #method_key ⇒ Object
- #prepare! ⇒ Object
- #render ⇒ Object
- #render_template ⇒ Object
- #source ⇒ Object
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 19 |
# 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
#extension ⇒ Object (readonly)
Returns the value of attribute extension.
5 6 7 |
# File 'lib/action_view/template.rb', line 5 def extension @extension end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
5 6 7 |
# File 'lib/action_view/template.rb', line 5 def filename @filename end |
#handler ⇒ Object (readonly)
Returns the value of attribute handler.
5 6 7 |
# File 'lib/action_view/template.rb', line 5 def handler @handler end |
#locals ⇒ Object
Returns the value of attribute locals.
4 5 6 |
# File 'lib/action_view/template.rb', line 4 def locals @locals end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
5 6 7 |
# File 'lib/action_view/template.rb', line 5 def method @method end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/action_view/template.rb', line 5 def path @path end |
#path_without_extension ⇒ Object (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_exception ⇒ Object
46 47 48 |
# File 'lib/action_view/template.rb', line 46 def base_path_for_exception @finder.find_base_path_for("#{@path_without_extension}.#{@extension}") || @finder.view_paths.first end |
#method_key ⇒ Object
42 43 44 |
# File 'lib/action_view/template.rb', line 42 def method_key @filename end |
#prepare! ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/action_view/template.rb', line 50 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 |
#render ⇒ Object
33 34 35 36 |
# File 'lib/action_view/template.rb', line 33 def render prepare! @handler.render(self) end |
#render_template ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/action_view/template.rb', line 21 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 |
#source ⇒ Object
38 39 40 |
# File 'lib/action_view/template.rb', line 38 def source @source ||= File.read(self.filename) end |