Parent

Included Modules

Class Index [+]

Quicksearch

Webgen::SourceHandler::Feed

Source handler for creating atom and/or rss feeds.

Constants

MANDATORY_INFOS

The mandatory keys that need to be set in a feed file.

Public Instance Methods

content(node) click to toggle source

Return the rendered feed represented by node.

    # File lib/webgen/sourcehandler/feed.rb, line 44
44:     def content(node)
45:       website.cache[[:sourcehandler_feed, node.node_info[:src]]] = feed_entries(node).map {|n| n.alcn}
46: 
47:       block_name = node.node_info[:feed_type] + '_template'
48:       if node.node_info[:feed].blocks.has_key?(block_name)
49:         node.node_info[:feed].blocks[block_name].render(Webgen::Context.new(:chain => [node])).content
50:       else
51:         chain = [node.resolve("/templates/#{node.node_info[:feed_type]}_feed.template"), node]
52:         node.node_info[:used_nodes] << chain.first.alcn
53:         chain.first.node_info[:page].blocks['content'].render(Webgen::Context.new(:chain => chain)).content
54:       end
55:     end
create_node(path) click to toggle source

Create atom and/or rss feed files from path.

    # File lib/webgen/sourcehandler/feed.rb, line 19
19:     def create_node(path)
20:       page = page_from_path(path)
21:       path.meta_info['link'] ||= path.parent_path
22: 
23:       if MANDATORY_INFOS.any? {|t| path.meta_info[t].nil?}
24:         raise Webgen::NodeCreationError.new("At least one of #{MANDATORY_INFOS.join('/')} is missing",
25:                                             self.class.name, path)
26:       end
27: 
28:       create_feed_node = lambda do |type|
29:         path.ext = type
30:         super(path) do |node|
31:           node.node_info[:feed] = page
32:           node.node_info[:feed_type] = type
33:         end
34:       end
35: 
36:       nodes = []
37:       nodes << create_feed_node['atom'] if path.meta_info['atom']
38:       nodes << create_feed_node['rss'] if path.meta_info['rss']
39: 
40:       nodes
41:     end
entry_content(node, entry) click to toggle source

Return the content of an entry of the feed node.

    # File lib/webgen/sourcehandler/feed.rb, line 73
73:     def entry_content(node, entry)
74:       entry.node_info[:page].blocks[node['content_block_name'] || 'content'].render(Webgen::Context.new(:chain => [entry])).content
75:     end
feed_entries(node) click to toggle source

Return the entries for the feed node.

    # File lib/webgen/sourcehandler/feed.rb, line 58
58:     def feed_entries(node)
59:       nr_items = (node['number_of_entries'].to_i == 0 ? 10 : node['number_of_entries'].to_i)
60:       patterns = [node['entries']].flatten.map {|pat| Webgen::Path.make_absolute(node.parent.alcn, pat)}
61: 
62:       node.tree.node_access[:alcn].values.
63:         select {|node| patterns.any? {|pat| node =~ pat} && node.node_info[:page]}.
64:         sort {|a,b| a['modified_at'] <=> b['modified_at']}.reverse[0, nr_items]
65:     end

Private Instance Methods

node_changed?(node) click to toggle source

Check if the any of the nodes used by this feed node have changed and then mark the node as dirty.

    # File lib/webgen/sourcehandler/feed.rb, line 83
83:     def node_changed?(node)
84:       return if node.node_info[:processor] != self.class.name
85:       entries = node.feed_entries
86:       node.flag(:dirty) if entries.map {|n| n.alcn } != website.cache[[:sourcehandler_feed, node.node_info[:src]]] ||
87:         entries.any? {|n| n.changed?}
88:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.