Parent

Included Modules

Class Index [+]

Quicksearch

Webgen::Common::Sitemap

This class provides functionality for creating sitemaps and checking if a sitemap has changed.

Public Instance Methods

create_sitemap(node, lang, options) click to toggle source

Return the sitemap tree as Webgen::Tag::Menu::MenuNode created for the node in the language lang using the provided options which can be any configuration option starting with common.sitemap.

    # File lib/webgen/common/sitemap.rb, line 20
20:     def create_sitemap(node, lang, options)
21:       @options = options
22:       tree = recursive_create(nil, node.tree.root, lang).sort!
23:       @options = nil
24:       (node.node_info[:common_sitemap] ||= {})[[options.to_a.sort, lang]] = tree.to_lcn_list
25:       tree
26:     end

Private Instance Methods

in_sitemap?(child, lang, allow_index_file = false) click to toggle source

Return true if the child of the node is in the sitemap for the language lang.

    # File lib/webgen/common/sitemap.rb, line 47
47:     def in_sitemap?(child, lang, allow_index_file = false)
48:       ((option('common.sitemap.used_kinds').empty? || option('common.sitemap.used_kinds').include?(child['kind']) ||
49:         (child.routing_node(lang, false) != child && in_sitemap?(child.routing_node(lang), lang, true))) &&
50:        (option('common.sitemap.any_lang') || child.lang.nil? || child.lang == lang) &&
51:        (!option('common.sitemap.honor_in_menu') || child['in_menu']) &&
52:        (allow_index_file || child.parent == child.tree.root || child.parent.routing_node(lang) != child))
53:     end
node_changed?(node) click to toggle source

Check if the sitemaps for node have changed.

    # File lib/webgen/common/sitemap.rb, line 63
63:     def node_changed?(node)
64:       return if !node.node_info[:common_sitemap]
65: 
66:       node.node_info[:common_sitemap].each do |(options, lang), cached_tree|
67:         @options = options.to_hash
68:         tree = recursive_create(nil, node.tree.root, lang).sort!.to_lcn_list
69:         @options = nil
70: 
71:         if (tree != cached_tree) ||
72:             (tree.flatten.any? do |alcn|
73:                (n = node.tree[alcn]) && (r = n.routing_node(lang)) && r.meta_info_changed?
74:              end)
75:           node.flag(:dirty)
76:           break
77:         end
78:       end
79:     end
option(name) click to toggle source

Retrieve the configuration option value for name. The value is taken from the current configuration options hash if name is specified there or from the website configuration otherwise.

    # File lib/webgen/common/sitemap.rb, line 58
58:     def option(name)
59:       (@options && @options.has_key?(name) ? @options[name] : website.config[name])
60:     end
recursive_create(parent, node, lang, in_sitemap = true) click to toggle source

Recursively create the sitemap.

    # File lib/webgen/common/sitemap.rb, line 33
33:     def recursive_create(parent, node, lang, in_sitemap = true)
34:       mnode = Webgen::Tag::Menu::MenuNode.new(parent, node)
35:       node.children.map do |n|
36:         sub_in_sitemap = in_sitemap?(n, lang)
37:         [(!n.children.empty? || sub_in_sitemap ? n : nil), sub_in_sitemap]
38:       end.each do |n, sub_in_sitemap|
39:         next if n.nil?
40:         sub_node = recursive_create(mnode, n, lang, sub_in_sitemap)
41:         mnode.children << sub_node unless sub_node.nil?
42:       end
43:       (mnode.children.empty? && !in_sitemap ? nil : mnode)
44:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.