Class: Mack::Rendering::Type::Base
- Defined in:
- lib/mack/rendering/type/base.rb
Overview
Mack::Rendering::Type objects need to extend this class.
The method ‘render’ needs to be implemented as in all subclasses.
Instance Attribute Summary collapse
-
#view_template ⇒ Object
readonly
Returns the Mack::Rendering::ViewTemplate object associated with this render.
Instance Method Summary collapse
-
#allow_layout? ⇒ Boolean
Can be overridden by subclasses to prevent layouts being used with the render.
-
#capture(*args, &block) ⇒ Object
See Mack::Rendering::ViewTemplate content_for for more details.
-
#controller_view_path ⇒ Object
Returns the directory path for the current controller.
- #find_engine(e) ⇒ Object
-
#find_file(*path) ⇒ Object
If a file is found on disk it will be yielded up.
-
#initialize(view_template) ⇒ Base
constructor
A new instance of Base.
- #method_missing(sym, *args) ⇒ Object
Constructor Details
#initialize(view_template) ⇒ Base
Returns a new instance of Base.
12 13 14 |
# File 'lib/mack/rendering/type/base.rb', line 12 def initialize(view_template) @view_template = view_template end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args) ⇒ Object
40 41 42 |
# File 'lib/mack/rendering/type/base.rb', line 40 def method_missing(sym, *args) self.view_template.send(sym, *args) end |
Instance Attribute Details
#view_template ⇒ Object (readonly)
Returns the Mack::Rendering::ViewTemplate object associated with this render.
10 11 12 |
# File 'lib/mack/rendering/type/base.rb', line 10 def view_template @view_template end |
Instance Method Details
#allow_layout? ⇒ Boolean
Can be overridden by subclasses to prevent layouts being used with the render.
32 33 34 |
# File 'lib/mack/rendering/type/base.rb', line 32 def allow_layout? true end |
#capture(*args, &block) ⇒ Object
See Mack::Rendering::ViewTemplate content_for for more details.
45 46 47 |
# File 'lib/mack/rendering/type/base.rb', line 45 def capture(*args, &block) @engine.capture(*args, &block) end |
#controller_view_path ⇒ Object
Returns the directory path for the current controller.
50 51 52 53 54 |
# File 'lib/mack/rendering/type/base.rb', line 50 def controller_view_path ivar_cache do Mack::Paths.views(self.controller.controller_name) end end |
#find_engine(e) ⇒ Object
36 37 38 |
# File 'lib/mack/rendering/type/base.rb', line 36 def find_engine(e) eval("Mack::Rendering::Engine::#{e.to_s.camelcase}") end |
#find_file(*path) ⇒ Object
If a file is found on disk it will be yielded up.
Example:
find_file("path", "to", "my", "file") do |f|
puts File.open(f).read
end
24 25 26 27 28 29 |
# File 'lib/mack/rendering/type/base.rb', line 24 def find_file(*path) f = File.join(path) if File.exists?(f) yield f end end |