DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Part Of A Chump Parser / Viewer

08.21.2006
| 2330 views |
  • submit to reddit
        
require 'rubygems'
require 'rexml/document'
require 'markaby'
class Chump
  chump = REXML::Document.new(File.new( "chump.xml" ))
  mab = Markaby::Builder.new
  mab.html do
    head { title "The Daily Chump" }
    body do
      h1 "The Daily Chump"
      ul do
        chump.elements.each("churn/link") do |el|
          unless el.attributes['type'] == 'blurb'
            title = el.elements['title'] ? el.elements['title'].text : el.elements['url'].text
            link = a title, :href => el.elements['url'].text
            li link<< " - posted by "<< el.elements['nick'].text
          else
            li el.elements['title'].text if el.elements['title']
          end
           li "posted at "<< el.elements['time'].text
        end
      end
    end
  end
  puts mab.to_s
end