Class: Webgen::SourceHandler::Metainfo

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

Overview

Handles meta information files which provide meta information for other files.

Constant Summary collapse

CKEY =
[:metainfo, :nodes]

Instance Method Summary collapse

Methods included from WebsiteAccess

included, website

Methods included from Base

#content, #node_exists?, #output_path, #page_from_path

Methods included from Base::OutputPathHelpers

#standard_output_path

Methods included from Loggable

#log, #puts

Constructor Details

#initializeMetainfo

Upon creation the object registers itself as listener for some node hooks.



17
18
19
20
21
22
23
# File 'lib/webgen/sourcehandler/metainfo.rb', line 17

def initialize
  website.blackboard.add_listener(:node_meta_info_changed?, method(:node_meta_info_changed?))
  website.blackboard.add_listener(:before_node_created, method(:before_node_created))
  website.blackboard.add_listener(:before_node_deleted, method(:before_node_deleted))
  website.blackboard.add_listener(:after_node_created, method(:after_node_created))
  self.nodes ||= []
end

Instance Method Details

#create_node(parent, path) ⇒ Object

Create a meta info node from parent and path.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/webgen/sourcehandler/metainfo.rb', line 26

def create_node(parent, path)
  page = page_from_path(path)
  super(parent, path) do |node|
    [[:mi_paths, 'paths'], [:mi_alcn, 'alcn']].each do |mi_key, block_name|
      node.node_info[mi_key] = {}
      if page.blocks.has_key?(block_name) && (data = YAML::load(page.blocks[block_name].content))
        data.each do |key, value|
          key = Webgen::Common.absolute_path(key, parent.absolute_lcn)
          node.node_info[mi_key][key] = value
        end
      end
    end

    mark_all_matched_dirty(node, :no_old_data)

    website.cache.permanent[[:sh_metainfo_node_mi, node.absolute_lcn]] = {
      :mi_paths => node.node_info[:mi_paths],
      :mi_alcn => node.node_info[:mi_alcn]
    }

    self.nodes << node unless self.nodes.include?(node)
    self.nodes = self.nodes.sort_by {|n| n.absolute_lcn}
  end
end

#nodesObject

:nodoc:



51
52
53
# File 'lib/webgen/sourcehandler/metainfo.rb', line 51

def nodes #:nodoc:
  website.cache.permanent[CKEY]
end

#nodes=(val) ⇒ Object

:nodoc:



55
56
57
# File 'lib/webgen/sourcehandler/metainfo.rb', line 55

def nodes=(val) #:nodoc:
  website.cache.permanent[CKEY] = val
end