Class: Mack::Rendering::Type::FileBase

Inherits:
Base show all
Defined in:
lib/mack/rendering/type/file_base.rb

Direct Known Subclasses

Action, Layout, Partial, Template, Xml

Instance Attribute Summary

Attributes inherited from Base

#view_template

Instance Method Summary collapse

Methods inherited from Base

#allow_layout?, #capture, #controller_view_path, #find_engine, #find_file, #initialize, #method_missing

Constructor Details

This class inherits a constructor from Mack::Rendering::Type::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Mack::Rendering::Type::Base

Instance Method Details

#concat(txt, b) ⇒ Object

Passes concatenation messages through to the Mack::Rendering::Engine object. This should append the text, using the passed in binding, to the final output of the render.



29
30
31
# File 'lib/mack/rendering/type/file_base.rb', line 29

def concat(txt, b)
  @engine.concat(txt, b)
end

#render_file(file, type = :action) ⇒ Object

Returns a string representing the file stored on disk, once it’s be run through the first found Mack::Rendering::Engine object associated with this Mack::Rendering::Type.

Since engines are stored in an array, the are looped through until a template is found on disk. If no template is found then a Mack::Errors::ResourceNotFound exception is thrown.



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/mack/rendering/type/file_base.rb', line 12

def render_file(file, type = :action)
  # we want to look local first, hence the reverse
  Mack.search_path_local_first(:app).each do |path|
    tfile = file.gsub(Mack::Paths.app, path)
    Mack::Rendering::Engine::Registry.engines[type].each do |e|
      @engine = find_engine(e).new(self.view_template)
      find_file(tfile + ".#{@engine.extension}") do |f|
        return @engine.render(File.new(f), self._binder)
      end
    end
  end
  raise Mack::Errors::ResourceNotFound.new(file + ".*")
end