module Webgen::PathHandler::PageUtils
This module should be used by path handlers that need to work with paths in Webgen
Page
Format.
Note that this modules provides an implementation for the parse_meta_info!
method. If you also include the Base
module, make sure that you include it before this module! Also make sure to override this method if you need custom behaviour!
Public Instance Methods
parse_meta_info!(path)
click to toggle source
Calls parse_as_page!
to update the meta information hash of path
. Returns the found blocks which will be passed as second parameter to the create_nodes method.
# File lib/webgen/path_handler/page_utils.rb 134 def parse_meta_info!(path) 135 parse_as_page!(path) 136 end
Private Instance Methods
parse_as_page!(path)
click to toggle source
Assume that the content of the given path
is in Webgen
Page
Format and parse it. Updates 'path.meta_info' with the meta info from the page and returns the content blocks.
# File lib/webgen/path_handler/page_utils.rb 140 def parse_as_page!(path) 141 begin 142 page = Webgen::Page.from_data(path.data) 143 rescue Webgen::Page::FormatError => e 144 raise Webgen::Error.new("Error reading source path: #{e.message}", nil, path) 145 end 146 blocks = page.meta_info.delete('blocks') || {} 147 path.meta_info.merge!(page.meta_info) 148 blocks.each {|key, val| ((path.meta_info['blocks'] ||= {})[key] ||= {}).merge!(val)} 149 page.blocks 150 end
set_blocks(node, blocks)
click to toggle source
Set the blocks (see parse_as_page!
) for the node.
# File lib/webgen/path_handler/page_utils.rb 154 def set_blocks(node, blocks) 155 node.node_info[:blocks] = blocks 156 end