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, line 134 def parse_meta_info!(path) parse_as_page!(path) 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, line 140 def parse_as_page!(path) begin page = Webgen::Page.from_data(path.data) rescue Webgen::Page::FormatError => e raise Webgen::Error.new("Error reading source path: #{e.message}", nil, path) end blocks = page.meta_info.delete('blocks') || {} path.meta_info.merge!(page.meta_info) blocks.each {|key, val| ((path.meta_info['blocks'] ||= {})[key] ||= {}).merge!(val)} page.blocks 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, line 154 def set_blocks(node, blocks) node.node_info[:blocks] = blocks end