Return to Snippet

Revision: 2782
at April 15, 2007 08:52 by felipec


Initial Code
require 'diu'

class Exporter
	def to_html(object)
		case object
		when Diu::Posts::Post
			str = ""
			str << "<p><a href=\"%s\">%s</a></p>\n" % [object.href, object.description]
			str << "<p>%s</p>\n" % [object.extended] if object.extended
			if object.tag
				if @tag_link
					tags = object.tag.split(" ")
					tag_str = tags.map {|tag| "<a href=\"#{@tag_link}#{tag}\">#{tag}</a>"}.join("\n")
				else
					tag_str = object.tag
				end
				str << "<p>(tags: %s)</p>\n" % [tag_str]
			end
		when Array
			"<ul>\n%s</ul>\n" % [object.map { |p| "<li>\n%s</li>\n" % [to_html(p)]}.join]
		end
	end

	attr_writer :tag_link
end

def test_diu(username, password)
	conn = Diu::Connection.new(username, password)
	res = conn.posts.find("recent", "tag" => "to-blog")
	exp = Exporter.new()
	exp.tag_link = "http://del.icio.us/#{username}/"
	print exp.to_html(res)
end

Initial URL


Initial Description
Sample snip for my diu helper.

Initial Title
Ruby del.icio.us sample

Initial Tags


Initial Language
Ruby