Class: Webgen::SourceHandler::Template
- Inherits:
-
Object
- Object
- Webgen::SourceHandler::Template
- Includes:
- Loggable, Base, WebsiteAccess
- Defined in:
- lib/webgen/sourcehandler/template.rb
Overview
Source handler for handling template files in Webgen Page Format.
Instance Method Summary collapse
-
#create_node(parent, path) ⇒ Object
Create a template node in
parent
forpath
. -
#default_template(dir_node, lang) ⇒ Object
Return the default template for the directory node
dir
. -
#templates_for_node(node, lang = node.lang) ⇒ Object
Return the template chain for
node
.
Methods included from Base
#content, #node_exists?, #output_path, #page_from_path
Methods included from Base::OutputPathHelpers
Methods included from Loggable
Methods included from WebsiteAccess
Instance Method Details
#create_node(parent, path) ⇒ Object
Create a template node in parent
for path
.
13 14 15 16 17 18 |
# File 'lib/webgen/sourcehandler/template.rb', line 13 def create_node(parent, path) page = page_from_path(path) super(parent, path) do |node| node.node_info[:page] = page end end |
#default_template(dir_node, lang) ⇒ Object
Return the default template for the directory node dir
. If the template node is not found, the parent directories are searched.
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/webgen/sourcehandler/template.rb', line 52 def default_template(dir_node, lang) template_node = dir_node.resolve(website.config['sourcehandler.template.default_template'], lang) if template_node.nil? if dir_node.is_root? log(:warn) { "No default template in root directory found!" } else template_node = default_template(dir_node.parent, lang) end end template_node end |
#templates_for_node(node, lang = node.lang) ⇒ Object
Return the template chain for node
.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/webgen/sourcehandler/template.rb', line 21 def templates_for_node(node, lang = node.lang) cached_template = (website.cache.volatile[[node.absolute_lcn, :templates]] ||= {}) if cached_template[lang] template_node = cached_template[lang] elsif node['template'].kind_of?(String) template_node = node.resolve(node['template'], lang) if template_node.nil? log(:warn) { "Specified template '#{node['template']}' for <#{node.absolute_lcn}> not found, using default template!" } template_node = default_template(node.parent, lang) end cached_template[lang] = template_node elsif node..has_key?('template') && node['template'].nil? template_node = cached_template[lang] = nil else log(:info) { "Using default template in language '#{lang}' for <#{node.absolute_lcn}>" } template_node = default_template(node.parent, lang) if template_node == node && !node.parent.is_root? template_node = default_template(node.parent.parent, lang) end cached_template[lang] = template_node end if template_node.nil? [] else (template_node == node ? [] : templates_for_node(template_node, lang) + [template_node]) end end |