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(path) ⇒ Object
Create atom and/or rss feed files from
path
. -
#entry_content(node, entry) ⇒ Object
Return the content of an
entry
of the feednode
. -
#feed_entries(node) ⇒ Object
Return the entries for the feed
node
. -
#feed_link(node) ⇒ Object
Return the feed link URL for the feed
node
. -
#initialize ⇒ Feed
constructor
:nodoc:.
Methods included from Base
#node_exists?, #output_path, #page_from_path, #parent_node
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 54 |
# 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.alcn} 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::Context.new(:chain => [node])).content else chain = [node.resolve("/templates/#{node.node_info[:feed_type]}_feed.template"), node] node.node_info[:used_nodes] << chain.first.alcn chain.first.node_info[:page].blocks['content'].render(Webgen::Context.new(:chain => chain)).content end end |
#create_node(path) ⇒ Object
Create atom and/or rss feed files from 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(path) page = page_from_path(path) path.['link'] ||= path.parent_path 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(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 |
#entry_content(node, entry) ⇒ Object
Return the content of an entry
of the feed node
.
72 73 74 |
# File 'lib/webgen/sourcehandler/feed.rb', line 72 def entry_content(node, entry) entry.node_info[:page].blocks[node['content_block_name'] || 'content'].render(Webgen::Context.new(:chain => [entry])).content end |
#feed_entries(node) ⇒ Object
Return the entries for the feed node
.
57 58 59 60 61 62 63 64 |
# File 'lib/webgen/sourcehandler/feed.rb', line 57 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::Path.make_absolute(node.parent.alcn, pat)} 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 |