Class: Webgen::SourceHandler::Page

Inherits:
Object
  • Object
show all
Includes:
Base, WebsiteAccess
Defined in:
lib/webgen/sourcehandler/page.rb

Overview

Source handler for handling content files in Webgen Page Format.

Instance Method Summary collapse

Methods included from Base

#node_exists?, #output_path, #page_from_path

Methods included from Base::OutputPathHelpers

#standard_output_path

Methods included from Loggable

#log, #puts

Methods included from WebsiteAccess

included, website

Constructor Details

#initializePage

:nodoc:



12
13
14
# File 'lib/webgen/sourcehandler/page.rb', line 12

def initialize #:nodoc:
  website.blackboard.add_listener(:node_meta_info_changed?, method(:meta_info_changed?))
end

Instance Method Details

#create_node(parent, path) ⇒ Object

Create a page file from parent and path.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/webgen/sourcehandler/page.rb', line 17

def create_node(parent, path)
  page = page_from_path(path)
  path.meta_info['lang'] ||= website.config['website.lang']
  path.ext = 'html' if path.ext == 'page'

  super(parent, path) do |node|
    website.cache[[:sh_page_node_mi, node.absolute_lcn]] = node.meta_info.dup

    node.node_info[:page] = page
    tmp_logger = website.logger
    website.logger = nil    # disabling logging whiling creating fragment nodes

    website.cache.permanent[:page_sections] ||= {}
    sections = if path.changed? || !website.cache.permanent[:page_sections][node.absolute_lcn]
                 website.blackboard.invoke(:parse_html_headers, render_node(node, 'content', []))
               else
                 website.cache.permanent[:page_sections][node.absolute_lcn]
               end
    website.cache.permanent[:page_sections][node.absolute_lcn] = sections
    website.blackboard.invoke(:create_fragment_nodes,
                              sections,
                              node, website.blackboard.invoke(:source_paths)[path.path],
                              node.meta_info['fragments_in_menu'])
    website.logger = tmp_logger
  end
end

#render_node(node, block_name = 'content', templates = website.blackboard.invoke(:templates_for_node, node)) ⇒ Object Also known as: content

Render the block called block_name of the given node. The parameter templates is set to the default template chain for the given node but you can assign a custom template chain (an array of template nodes) if need arises. Return nil if an error occurred.



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/webgen/sourcehandler/page.rb', line 47

def render_node(node, block_name = 'content', templates = website.blackboard.invoke(:templates_for_node, node))
  chain = [templates, node].flatten

  if chain.first.node_info[:page].blocks.has_key?(block_name)
    node.node_info[:used_nodes] << chain.first.absolute_lcn
    context = chain.first.node_info[:page].blocks[block_name].render(Webgen::ContentProcessor::Context.new(:chain => chain))
    context.content
  else
    raise "Error rendering <#{node.absolute_lcn}>: no block named '#{block_name}' in <#{chain.first.absolute_lcn}>"
  end
end