Class: Picombo::Controllers::Template
- Inherits:
-
Object
- Object
- Picombo::Controllers::Template
- Defined in:
- lib/controllers/template.rb
Overview
Template Controller
The template controller enables your application to take advantage of view templating and auto rendering.
To use it, simply tell your controllers to extend Picombo::Controllers::Template. You must also explicitly call the parent initialize method in your controllers:
def initialize super end
The default template view is called ‘layout’ which is located in views/layout.rb. You can change this on a per controller basis by changing the @template vartiable in the controller’s constructor:
@template = ‘foobar_template’
Now, you can use @template in your controller and it will always use the same template. The template will automatically render at the end of the controller execution, so there is no need to call @template.output manually
Instance Method Summary collapse
-
#initialize ⇒ Template
constructor
A new instance of Template.
Constructor Details
#initialize ⇒ Template
Returns a new instance of Template.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/controllers/template.rb', line 20 def initialize @template = 'layout' if @template.nil? @auto_render = true @template = Picombo::Stache::const_get(@template.capitalize).new if @template.is_a?(String) Picombo::Event.add('system.display') do |data| if @auto_render if Picombo::Core.cli return @template.render end @template.output end end end |