Class: Webgen::SourceHandler::Feed
- Inherits:
-
Object
- Object
- Webgen::SourceHandler::Feed
- Includes:
- Base, WebsiteAccess
- Defined in:
- lib/webgen/sourcehandler/feed.rb
Overview
Source handler for creating atom and/or rss feeds.
Constant Summary collapse
- MANDATORY_INFOS =
The mandatory keys that need to be set in a feed file.
%W[site_url author entries]
Instance Method Summary collapse
-
#content(node) ⇒ Object
Return the rendered feed represented by
node. -
#create_node(parent, path) ⇒ Object
Create atom and/or rss feed files from
parentandpath. -
#feed_entries(node) ⇒ Object
Helper method for returning the entries for the feed node
node. -
#initialize ⇒ Feed
constructor
:nodoc:.
Methods included from Base
#node_exists?, #output_path, #page_from_path
Methods included from Base::OutputPathHelpers
Methods included from Loggable
Methods included from WebsiteAccess
Constructor Details
#initialize ⇒ Feed
:nodoc:
15 16 17 |
# File 'lib/webgen/sourcehandler/feed.rb', line 15 def initialize # :nodoc: website.blackboard.add_listener(:node_changed?, method(:node_changed?)) end |
Instance Method Details
#content(node) ⇒ Object
Return the rendered feed represented by node.
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/webgen/sourcehandler/feed.rb', line 44 def content(node) website.cache[[:sourcehandler_feed, node.node_info[:src]]] = feed_entries(node).map {|n| n.absolute_lcn} block_name = node.node_info[:feed_type] + '_template' if node.node_info[:feed].blocks.has_key?(block_name) node.node_info[:feed].blocks[block_name]. render(Webgen::ContentProcessor::Context.new(:chain => [node])).content else feed = (website.cache.volatile[:sourcehandler_feed] ||= {})[node.node_info[:src]] ||= build_feed_for(node) feed.feed_type = node.node_info[:feed_type] feed.build_xml end end |
#create_node(parent, path) ⇒ Object
Create atom and/or rss feed files from parent and path.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/webgen/sourcehandler/feed.rb', line 20 def create_node(parent, path) page = page_from_path(path) path.['link'] ||= parent.absolute_lcn if MANDATORY_INFOS.any? {|t| path.[t].nil?} raise "One of #{MANDATORY_INFOS.join('/')} information missing for feed <#{path}>" end create_feed_node = lambda do |type| path.ext = type super(parent, path) do |node| node.node_info[:feed] = page node.node_info[:feed_type] = type end end nodes = [] nodes << create_feed_node['atom'] if path.['atom'] nodes << create_feed_node['rss'] if path.['rss'] nodes end |
#feed_entries(node) ⇒ Object
Helper method for returning the entries for the feed node node.
58 59 60 61 62 63 64 65 66 |
# File 'lib/webgen/sourcehandler/feed.rb', line 58 def feed_entries(node) nr_items = (node['number_of_entries'].to_i == 0 ? 10 : node['number_of_entries'].to_i) patterns = [node['entries']].flatten.map {|pat| Pathname.new(pat =~ /^\// ? pat : File.join(node.parent.absolute_lcn, pat)).cleanpath.to_s} node.tree.node_access[:alcn].values. select {|node| patterns.any? {|pat| node =~ pat} && node.node_info[:page]}. sort {|a,b| a['modified_at'] <=> b['modified_at']}. reverse[0, nr_items] end |