Class: Dugway::Template
- Inherits:
-
Object
- Object
- Dugway::Template
- Defined in:
- lib/dugway/template.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #content ⇒ Object
- #content_type ⇒ Object
- #extension ⇒ Object
- #html? ⇒ Boolean
-
#initialize(name) ⇒ Template
constructor
A new instance of Template.
- #render(request, variables = {}) ⇒ Object
- #standalone_html? ⇒ Boolean
Constructor Details
#initialize(name) ⇒ Template
Returns a new instance of Template.
5 6 7 |
# File 'lib/dugway/template.rb', line 5 def initialize(name) @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/dugway/template.rb', line 3 def name @name end |
Instance Method Details
#content ⇒ Object
9 10 11 |
# File 'lib/dugway/template.rb', line 9 def content Dugway.theme.file_content(name) end |
#content_type ⇒ Object
13 14 15 |
# File 'lib/dugway/template.rb', line 13 def content_type Rack::Mime.mime_type(extension) end |
#extension ⇒ Object
17 18 19 |
# File 'lib/dugway/template.rb', line 17 def extension File.extname(name) end |
#html? ⇒ Boolean
21 22 23 |
# File 'lib/dugway/template.rb', line 21 def html? extension == '.html' end |
#render(request, variables = {}) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/dugway/template.rb', line 29 def render(request, variables={}) if html? liquifier = Liquifier.new(request) content_to_render = variables[:page] && variables[:page]['content'] || content rendered_content = liquifier.render(content_to_render, variables) if standalone_html? rendered_content else liquifier.render(Dugway.theme.layout, variables.update(:page_content => rendered_content)) end else content end end |
#standalone_html? ⇒ Boolean
25 26 27 |
# File 'lib/dugway/template.rb', line 25 def standalone_html? html? && !!(content =~ /\{\{\s*head_content\s*\}\}/) end |