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, #parent_node

Methods included from Base::OutputPathHelpers

#standard_output_path

Methods included from Loggable

#log, #puts

Methods included from WebsiteAccess

included, website

Constructor Details

#initializePage

:nodoc:



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

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

Instance Method Details

#create_node(path) ⇒ Object

Create a page file from path.



16
17
18
19
20
21
22
23
24
25
# File 'lib/webgen/sourcehandler/page.rb', line 16

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

  super(path) do |node|
    node.node_info[:sh_page_node_mi] = Webgen::Page.meta_info_from_data(path.io.data)
    node.node_info[:page] = page
  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.



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/webgen/sourcehandler/page.rb', line 30

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.alcn
    context = chain.first.node_info[:page].blocks[block_name].render(Webgen::Context.new(:chain => chain))
    context.content
  else
    raise "Error rendering <#{node.alcn}>: no block named '#{block_name}' in <#{chain.first.alcn}>"
  end
end