class Nanoc::Helpers::Blogging::AtomFeedBuilder
Attributes
Public Class Methods
Source
# File lib/nanoc/helpers/blogging.rb, line 47 def initialize(config, item) @config = config @item = item end
Public Instance Methods
Source
# File lib/nanoc/helpers/blogging.rb, line 58 def build buffer = +'' xml = Builder::XmlMarkup.new(target: buffer, indent: 2) build_for_feed(xml) buffer end
Source
# File lib/nanoc/helpers/blogging.rb, line 52 def validate validate_config validate_feed_item validate_articles end
Protected Instance Methods
Source
# File lib/nanoc/helpers/blogging.rb, line 144 def build_for_article(article, xml) # Get URL url = url_for(article) return if url.nil? xml.entry do # Add primary attributes xml.id id_proc.call(article) xml.title title_proc.call(article), type: 'html' # Add dates xml.published attribute_to_time(article[:created_at]).__nanoc_to_iso8601_time xml.updated attribute_to_time(article[:updated_at] || article[:created_at]).__nanoc_to_iso8601_time # Add specific author information if article[:author_name] || article[:author_uri] xml.author do xml.name article[:author_name] || author_name xml.uri article[:author_uri] || author_uri end end # Add link xml.link(rel: 'alternate', href: url, type: 'text/html') # Add content summary = excerpt_proc.call(article) xml.content content_proc.call(article), type: 'html' xml.summary summary, type: 'html' unless summary.nil? end end
Source
# File lib/nanoc/helpers/blogging.rb, line 112 def build_for_feed(xml) root_url = @config[:base_url] + '/' xml.instruct! xml.feed(xmlns: 'http://www.w3.org/2005/Atom', 'xml:base' => root_url) do # Add primary attributes xml.id(id || root_url) xml.title title # Add date xml.updated(updated.__nanoc_to_iso8601_time) # Add links xml.link(rel: 'alternate', href: alt_link || root_url, type: 'text/html') xml.link(rel: 'self', href: feed_url, type: 'application/atom+xml') # Add author information xml.author do xml.name author_name xml.uri author_uri end # Add icon and logo xml.icon icon if icon xml.logo logo if logo # Add articles sorted_relevant_articles.each do |a| build_for_article(a, xml) end end end
Source
# File lib/nanoc/helpers/blogging.rb, line 77 def last_article sorted_relevant_articles.first end
Source
# File lib/nanoc/helpers/blogging.rb, line 67 def sorted_relevant_articles all = relevant_articles unless @preserve_order all = all.sort_by { |a| attribute_to_time(a[:created_at]) } end all.reverse.first(limit) end
Source
# File lib/nanoc/helpers/blogging.rb, line 81 def updated relevant_articles.map { |a| attribute_to_time(a[:updated_at] || a[:created_at]) }.max end
Source
# File lib/nanoc/helpers/blogging.rb, line 103 def validate_articles if relevant_articles.empty? raise Nanoc::Core::TrivialError.new('Cannot build Atom feed: no articles') end if relevant_articles.any? { |a| a[:created_at].nil? } raise Nanoc::Core::TrivialError.new('Cannot build Atom feed: one or more articles lack created_at') end end
Source
# File lib/nanoc/helpers/blogging.rb, line 85 def validate_config if @config[:base_url].nil? raise Nanoc::Core::TrivialError.new('Cannot build Atom feed: site configuration has no base_url') end end
Source
# File lib/nanoc/helpers/blogging.rb, line 91 def validate_feed_item if title.nil? raise Nanoc::Core::TrivialError.new('Cannot build Atom feed: no title in params, item or site config') end if author_name.nil? raise Nanoc::Core::TrivialError.new('Cannot build Atom feed: no author_name in params, item or site config') end if author_uri.nil? raise Nanoc::Core::TrivialError.new('Cannot build Atom feed: no author_uri in params, item or site config') end end