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

Inherits:
Base
  • Object
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.



25
26
27
# File 'lib/mack/rendering/type/file_base.rb', line 25

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
# File 'lib/mack/rendering/type/file_base.rb', line 12

def render_file(file, type = :action)
  Mack::Rendering::Engine::Registry.engines[type].each do |e|
    @engine = find_engine(e).new(self.view_template)
    find_file(file + ".#{@engine.extension}") do |f|
      return @engine.render(File.new(f), self._binder)
    end
  end
  raise Mack::Errors::ResourceNotFound.new(file + ".*")
end