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
parent
andpath
. -
#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:
14 15 16 |
# File 'lib/webgen/sourcehandler/feed.rb', line 14 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
.
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/webgen/sourcehandler/feed.rb', line 43 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.build_xml(node.node_info[:feed_type], (node.node_info[:feed_type] == 'rss' ? node['rss_version'] || 2.0 : nil)) end end |
#create_node(parent, path) ⇒ Object
Create atom and/or rss feed files from parent
and path
.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/webgen/sourcehandler/feed.rb', line 19 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
.
56 57 58 59 60 61 62 63 |
# File 'lib/webgen/sourcehandler/feed.rb', line 56 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| Webgen::Common.absolute_path(pat, node.parent.absolute_lcn)} 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']}[0, nr_items] end |