lib/nanoc/helpers/blogging.rb in nanoc-3.7.4 vs lib/nanoc/helpers/blogging.rb in nanoc-3.7.5

- old
+ new

@@ -1,9 +1,8 @@ # encoding: utf-8 module Nanoc::Helpers - # Provides functionality for building blogs, such as finding articles and # constructing feeds. # # This helper has a few requirements. First, all blog articles should have # the following attributes: @@ -20,17 +19,16 @@ # parameters can either be a `Time` instance or a string in any format # parseable by `Time.parse`. # # The two main functions are {#sorted_articles} and {#atom_feed}. module Blogging - # Returns an unsorted list of articles, i.e. items where the `kind` # attribute is set to `"article"`. # # @return [Array] An array containing all articles def articles - blk = lambda { @items.select { |item| item[:kind] == 'article' } } + blk = -> { @items.select { |item| item[:kind] == 'article' } } if @items.frozen? @article_items ||= blk.call else blk.call end @@ -40,23 +38,20 @@ # attribute is set to `"article"`. Articles are sorted by descending # creation date, so newer articles appear before older articles. # # @return [Array] A sorted array containing all articles def sorted_articles - blk = lambda do - articles.sort_by { |a| attribute_to_time(a[:created_at]) }.reverse - end + blk = -> { articles.sort_by { |a| attribute_to_time(a[:created_at]) }.reverse } if @items.frozen? @sorted_article_items ||= blk.call else blk.call end end class AtomFeedBuilder - include Nanoc::Helpers::Blogging attr_accessor :site attr_accessor :limit @@ -80,11 +75,11 @@ validate_articles end def build buffer = '' - xml = Builder::XmlMarkup.new(:target => buffer, :indent => 2) + xml = Builder::XmlMarkup.new(target: buffer, indent: 2) build_for_feed(xml) buffer end protected @@ -126,23 +121,23 @@ end end def build_for_feed(xml) xml.instruct! - xml.feed(:xmlns => 'http://www.w3.org/2005/Atom') do + xml.feed(xmlns: 'http://www.w3.org/2005/Atom') do root_url = @site.config[:base_url] + '/' # Add primary attributes xml.id root_url xml.title title # Add date xml.updated(attribute_to_time(last_article[:created_at]).to_iso8601_time) # Add links - xml.link(:rel => 'alternate', :href => root_url) - xml.link(:rel => 'self', :href => feed_url) + xml.link(rel: 'alternate', href: root_url) + xml.link(rel: 'self', href: feed_url) # Add author information xml.author do xml.name author_name xml.uri author_uri @@ -165,11 +160,11 @@ return if url.nil? xml.entry do # Add primary attributes xml.id atom_tag_for(a) - xml.title a[:title], :type => 'html' + xml.title a[:title], type: 'html' # Add dates xml.published attribute_to_time(a[:created_at]).to_iso8601_time xml.updated attribute_to_time(a[:updated_at] || a[:created_at]).to_iso8601_time @@ -180,19 +175,18 @@ xml.uri a[:author_uri] || author_uri end end # Add link - xml.link(:rel => 'alternate', :href => url) + xml.link(rel: 'alternate', href: url) # Add content summary = excerpt_proc.call(a) - xml.content content_proc.call(a), :type => 'html' - xml.summary summary, :type => 'html' unless summary.nil? + xml.content content_proc.call(a), type: 'html' + xml.summary summary, type: 'html' unless summary.nil? end end - end # Returns a string representing the atom feed containing recent articles, # sorted by descending creation date. # @@ -307,12 +301,12 @@ builder = AtomFeedBuilder.new(@site, @item) # Fill builder builder.limit = params[:limit] || 5 builder.relevant_articles = params[:articles] || articles || [] - builder.content_proc = params[:content_proc] || lambda { |a| a.compiled_content(:snapshot => :pre) } - builder.excerpt_proc = params[:excerpt_proc] || lambda { |a| a[:excerpt] } + builder.content_proc = params[:content_proc] || ->(a) { a.compiled_content(snapshot: :pre) } + builder.excerpt_proc = params[:excerpt_proc] || ->(a) { a[:excerpt] } builder.title = params[:title] || @item[:title] || @site.config[:title] builder.author_name = params[:author_name] || @item[:author_name] || @site.config[:author_name] builder.author_uri = params[:author_uri] || @item[:author_uri] || @site.config[:author_uri] builder.icon = params[:icon] builder.logo = params[:logo] @@ -384,9 +378,7 @@ def attribute_to_time(time) time = Time.local(time.year, time.month, time.day) if time.is_a?(Date) time = Time.parse(time) if time.is_a?(String) time end - end - end