Sha256: d274edaf671805482c5e886bee225a545bb35cc91d073239558eceabbb691a64

Contents?: true

Size: 1.4 KB

Versions: 3

Compression:

Stored size: 1.4 KB

Contents

# WARNING: unfinished code, do NOT use yet.

require 'nitro/builder/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

3 entries across 3 versions & 1 rubygems

Version Path
nitro-0.18.0 lib/nitro/builder/atom.rb
nitro-0.18.1 lib/nitro/builder/atom.rb
nitro-0.19.0 lib/nitro/builder/atom.rb