Class: Howl::Template
- Inherits:
-
Object
- Object
- Howl::Template
- Defined in:
- lib/howl/template.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#extension ⇒ Object
Returns the value of attribute extension.
-
#path ⇒ Object
Returns the value of attribute path.
-
#relative_path ⇒ Object
Returns the value of attribute relative_path.
-
#site ⇒ Object
Returns the value of attribute site.
-
#view ⇒ Object
Returns the value of attribute view.
-
#view_yaml ⇒ Object
Returns the value of attribute view_yaml.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #converter ⇒ Object
-
#initialize(path, site) ⇒ Template
constructor
A new instance of Template.
- #output_filename ⇒ Object
- #render(render_view = nil) ⇒ Object
Constructor Details
#initialize(path, site) ⇒ Template
Returns a new instance of Template.
13 14 15 16 17 18 19 |
# File 'lib/howl/template.rb', line 13 def initialize(path, site) @site = site @path = Pathname.new(path) @relative_path = path.to_s.gsub(/^#{site.root}/, '') @extension = @path.extname load_file unless @path.binary? end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
11 12 13 |
# File 'lib/howl/template.rb', line 11 def content @content end |
#extension ⇒ Object
Returns the value of attribute extension.
11 12 13 |
# File 'lib/howl/template.rb', line 11 def extension @extension end |
#path ⇒ Object
Returns the value of attribute path.
11 12 13 |
# File 'lib/howl/template.rb', line 11 def path @path end |
#relative_path ⇒ Object
Returns the value of attribute relative_path.
11 12 13 |
# File 'lib/howl/template.rb', line 11 def relative_path @relative_path end |
#site ⇒ Object
Returns the value of attribute site.
11 12 13 |
# File 'lib/howl/template.rb', line 11 def site @site end |
#view ⇒ Object
Returns the value of attribute view.
11 12 13 |
# File 'lib/howl/template.rb', line 11 def view @view end |
#view_yaml ⇒ Object
Returns the value of attribute view_yaml.
11 12 13 |
# File 'lib/howl/template.rb', line 11 def view_yaml @view_yaml end |
Class Method Details
.can_view(*viewables) ⇒ Object
7 8 9 |
# File 'lib/howl/template.rb', line 7 def self.can_view(*viewables) viewables.push(*viewables) end |
.viewables ⇒ Object
3 4 5 |
# File 'lib/howl/template.rb', line 3 def self.viewables @viewables ||= [] end |
Instance Method Details
#==(other) ⇒ Object
21 22 23 |
# File 'lib/howl/template.rb', line 21 def ==(other) self.path == other.path && self.class == other.class end |
#converter ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/howl/template.rb', line 29 def converter unless @converter converter_class = Converter.subclasses.find do |converter| converter.matches? @extension end converter_class ||= Converter @converter = converter_class.new(self) end @converter end |
#output_filename ⇒ Object
25 26 27 |
# File 'lib/howl/template.rb', line 25 def output_filename path.basename.sub(/#{extension}$/, converter.extension) end |
#render(render_view = nil) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/howl/template.rb', line 42 def render(render_view = nil) render_view ||= site.view render_view = render_view.dup render_view.merge!(@view) rendered = converter.convert(Mustache.render(@content, render_view)) template_name = render_view.delete("template") if template_name template = find_template(template_name) if template && template != self rendered = template.render( render_view.merge("content" => rendered)) else puts "Warning: Template #{template_name} does not exist in file #{path}" rendered end end rendered end |