/ Published in: Ruby

Sample snip for my diu helper.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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
Comments
