Sha256: 4a9b82c21aaa392aed2ee0dface01009f68adf8e21f4521f6acd2c1df90904dc

Contents?: true

Size: 1.48 KB

Versions: 2

Compression:

Stored size: 1.48 KB

Contents

# * George Moschovitis  <gm@navel.gr>
# (c) 2005 Navel, all rights reserved.
# $Id$

# WARNING: unfinished code, do NOT use yet.

require 'nitro/builders/xml'

module Nitro

# Build Atom represenations of ruby object collections.
# Utilize duck typing to grab the attributes to render.
# Add this mixin to you classes to support Atom 
# syndication.

module AtomBuilderMixin
	include XmlBuilderMixin

	# Build Atom syndication stream.
	#
	# === Options
	#
	# [+:description+]
	#		Description of the feed.
	# [+:encoding+]
	#		Character encoding.
	# [+:base+]
	#		Base url of the feed.
	# [+:link+]
	#		Link of the Feed.
	
	def build_atom(objects, options = {})
		c = {
			:description => 'Syndication',
			:encoding => 'utf-8'
		}.update(options)

		c[:base] ||= c[:link]

		raise "Option ':base' cannot be infered!" unless c[:base] 

		pi! :xml, :version => '1.0', :encoding => o[:encoding]
		feed(:version => '0.3') do 
			for obj in objects
				entry do
					if obj.respond_to?(:author)
						author { name(obj.author) }
					end
				
					issued obj.create_time.xmlschema
					modified obj.update_time.xmlschema
					title obj.title
					
					if obj.respond_to?(:categories)
						for category in categories
							dc :subject => category.name
						end
					end
				end
			end
		end
	end

end

# Abstract class for the AtomBuilderMixin.

class AtomBuilder < String
	include AtomBuilderMixin

	class << self
		def build(objects, options = {})
			AtomBuilder.new.build_atom(objects, options)
		end
	end
end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nitro-0.16.0 lib/nitro/builders/atom.rb
nitro-0.17.0 lib/nitro/builders/atom.rb