# File lib/nanoc/helpers/blogging.rb, line 145
    def atom_feed(params={})
      require 'builder'

      # Extract parameters
      limit             = params[:limit] || 5
      relevant_articles = params[:articles] || articles || []
      content_proc      = params[:content_proc] || lambda { |a| a.compiled_content(:snapshot => :pre) }
      excerpt_proc      = params[:excerpt_proc] || lambda { |a| a[:excerpt] }

      # Check config attributes
      if @site.config[:base_url].nil?
        raise RuntimeError.new('Cannot build Atom feed: site configuration has no base_url')
      end

      # Check feed item attributes
      title = params[:title] || @item[:title] || @site.config[:title]
      if title.nil?
        raise RuntimeError.new('Cannot build Atom feed: no title in params, item or site config')
      end
      author_name = params[:author_name] || @item[:author_name] || @site.config[:author_name]
      if author_name.nil?
        raise RuntimeError.new('Cannot build Atom feed: no author_name in params, item or site config')
      end
      author_uri = params[:author_uri] || @item[:author_uri] || @site.config[:author_uri]
      if author_uri.nil?
        raise RuntimeError.new('Cannot build Atom feed: no author_uri in params, item or site config')
      end

      # Check article attributes
      if relevant_articles.empty?
        raise RuntimeError.new('Cannot build Atom feed: no articles')
      end
      if relevant_articles.any? { |a| a[:created_at].nil? }
        raise RuntimeError.new('Cannot build Atom feed: one or more articles lack created_at')
      end

      # Get sorted relevant articles
      sorted_relevant_articles = relevant_articles.sort_by do |a|
        attribute_to_time(a[:created_at])
      end.reverse.first(limit)

      # Get most recent article
      last_article = sorted_relevant_articles.first

      # Create builder
      buffer = ''
      xml = Builder::XmlMarkup.new(:target => buffer, :indent => 2)

      # Build feed
      xml.instruct!
      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)

        # Add author information
        xml.author do
          xml.name  author_name
          xml.uri   author_uri
        end

        # Add articles
        sorted_relevant_articles.each do |a|
          # Get URL
          url = url_for(a)
          next if url.nil?

          xml.entry do
            # Add primary attributes
            xml.id        atom_tag_for(a)
            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
        
            # Add specific author information
            if a[:author_name] || a[:author_uri]
              xml.author do
                xml.name  a[:author_name] || author_name
                xml.uri   a[:author_uri]  || author_uri
              end
            end

            # Add link
            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?
          end
        end
      end

      buffer
    end