Class: Templette::Template
- Inherits:
-
Object
- Object
- Templette::Template
- Defined in:
- lib/templette/template.rb
Overview
The Template acts as a layout for pages. It contains an html layout for the page and contains method calls which are answered by helper methods or the loaded yaml of a page.
Templates now support ERB or Haml for rendering.
-
template.html.haml
-
template.html.erb
-
template.html -> defaults to ERB
Constant Summary collapse
- TEMPLATE_DIR =
'templates'
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
-
#helpers ⇒ Object
Provides the names of helper_modules to be loaded for a template.
-
#initialize(name, default_engine = Templette::config[:default_engine]) ⇒ Template
constructor
The name parameter refers to the actual filename of the template.
-
#render(the_binding) ⇒ Object
Generates the final HTML.
-
#to_yaml ⇒ Object
Generates the yaml necessary to render empty page yaml files.
Constructor Details
#initialize(name, default_engine = Templette::config[:default_engine]) ⇒ Template
The name parameter refers to the actual filename of the template. To load templates/foo.html, a template_name of ‘foo’ should be given.
18 19 20 21 |
# File 'lib/templette/template.rb', line 18 def initialize(name, default_engine = Templette::config[:default_engine]) @name = name @default_engine = default_engine end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
14 15 16 |
# File 'lib/templette/template.rb', line 14 def name @name end |
Instance Method Details
#helpers ⇒ Object
Provides the names of helper_modules to be loaded for a template.
29 30 31 |
# File 'lib/templette/template.rb', line 29 def helpers ["default_helper","#{name}_helper"] end |
#render(the_binding) ⇒ Object
Generates the final HTML.
34 35 36 37 38 39 |
# File 'lib/templette/template.rb', line 34 def render(the_binding) raise TemplateError.new(self, "Template rendering failed. File not found.") unless File.exists?(path) Engineer.engine_for(type).render(to_html, the_binding) rescue RenderError => e raise TemplateError.new(self, e.) end |
#to_yaml ⇒ Object
Generates the yaml necessary to render empty page yaml files.
24 25 26 |
# File 'lib/templette/template.rb', line 24 def to_yaml {'template_name' => @name, 'sections' => MethodCollector.new(self).to_hash}.to_yaml end |