Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 8517

Show
Ignore:
Timestamp:
01/01/08 19:55:40 (7 months ago)
Author:
rick
Message:

Add support for unique entry URLs. Update the id tag datestamps to use the current year of the feed or the entry. [rick]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/atom_feed_helper/CHANGELOG

    r6908 r8517  
     1* Add support for unique entry URLs.  [rick] 
     2 
     3* Update the id tag datestamps to use the current year of the feed or the entry. [rick] 
     4 
    15* id tag datestamps should just be the year the plugin is created [Sam Ruby/feedvalidator.org] 
  • plugins/atom_feed_helper/lib/atom_feed_helper.rb

    r7200 r8517  
    22# template languages). 
    33module AtomFeedHelper 
     4  # Available Options: 
     5  # 
     6  #   :root_url - Adds a <link rel="alternate" type="text/html" ... /> tag for the feed. 
     7  #   :url - Adds a <link rel="self" type="application/atom+xml" ... /> tag for the feed. 
     8  # 
    49  def atom_feed(options = {}, &block) 
    510    xml = options[:xml] || eval("xml", block.binding) 
     
    712 
    813    xml.feed "xml:lang" => "en-US", "xmlns" => 'http://www.w3.org/2005/Atom' do 
    9       xml.id("tag:#{request.host},2007:#{request.request_uri.split(".")[0].gsub("/", "")}") 
     14      xml.id("tag:#{request.host},#{Time.now.utc.year}:#{request.request_uri.split(".")[0].gsub("/", "")}") 
    1015       
    1116      if options[:root_url] || respond_to?(:root_url) 
     
    2833      end 
    2934 
    30       def entry(record) 
    31         @xml.entry do  
    32           @xml.id("tag:#{@view.request.host_with_port},2007:#{record.class}#{record.id}") 
    33           @xml.published(record.created_at.xmlschema) if record.respond_to?(:created_at) 
     35      # Available Options: 
     36      # 
     37      #   :url - Adds a <link rel="alternate" type="text/html" ... /> tag for the given record. 
     38      #   :published - Uses the given field to set the <published> tag value.  Defaults to #created_at. 
     39      def entry(record, options = {}) 
     40        published = record.created_at if record.respond_to?(:created_at) 
     41 
     42        @xml.entry do 
     43          @xml.id("tag:#{@view.request.host_with_port},#{(published || Time.now.utc).year}:#{record.class}#{record.id}") 
     44          @xml.published(published.xmlschema) if published 
    3445          @xml.updated(record.updated_at.xmlschema) if record.respond_to?(:updated_at) 
    3546 
    3647          yield @xml 
    3748 
    38           @xml.link(:rel => 'alternate', :type => 'text/html', :href => @view.polymorphic_url(record)) 
     49          @xml.link(:rel => 'alternate', :type => 'text/html', :href => options[:url] || @view.polymorphic_url(record)) 
    3950        end 
    4051      end