Archive for November, 2008

Rfeedparser and Hpricot

RFeedParser is one of the ruby gems to parse rss feeds. Its a translation of Mark Pilgrims's Universal Feed Parser from Python into Ruby. It has a few dependencies and requires you to install a few other gems. The installation instructions are simple and the usage is simple.

One of the dependencies for this was hpricot. Everything was working fine till one day, I updated my hpricot gem and did a cleanup of my rubygems. I started getting an error:

balpreet-pankajs-macbook:digg balpreetpankaj$ ruby bloo.rb
/Library/Ruby/Site/1.8/rubygems.rb:142:in `activate': can't activate hpricot (= 0.6, runtime), already activated hpricot-0.6.164 (Gem::Exception)
from /Library/Ruby/Site/1.8/rubygems.rb:158:in `activate'
from /Library/Ruby/Site/1.8/rubygems.rb:157:in `each'
from /Library/Ruby/Site/1.8/rubygems.rb:157:in `activate'
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.2/lib/active_support/dependencies.rb:510:in `require'
from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.2/lib/active_support/dependencies.rb:355:in `new_constants_in'
from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.2/lib/active_support/dependencies.rb:510:in `require'

After a little digging arnd with rubygems, I figured out that the rfeedparser has a requirement of running with a hpricot gem with version = 0.6. I changed that to >= 0.6 and things started working fine. I was using version 0.9.951 of rfeedparser. If you use rfeedparser and run into a similar problem, this is how you fix it:

1) Update the gemspec for rfeedparser. Go to your gem installation dir. You can find this by doing:
gem env gempath
Then edit the $gemPATH/specifications/rfeedparser0.9.951.gemspec and update all references of hpricot from "=0.6" to ">=0.6".
2). Go to $GEMPATH/gems/rfeedparser-0.9.951/lib/rfeedparser.rb and again update the reference of hpricot.

This should get you rolling with all new versions of hpricot.

Comments (1)

Creating a headline rotator

I was recently reading the book Learning Jquery by Jonathan Chaffer and Karl Swedberg . After reading the chapter on Rotators and Shufflers, which shows how you can create a headline rotator, I decided to implement one for my own website, adevelopedworld.com. adevelopedworld.com is a website which features social entrepreneurs from all around the world. We constantly get updates from the social entrepreneurs that we have featured, and we had to manually update the homepage to show these updates. After implementing the headline rotator, we just keep adding the updates to a text file, and the homepage gets automatically updated. And to top it, the homepage looks all the more dynamic.

The tutorial on how to create the rotator in the book is very complete. I just had to make one change. The tutorial is based on an old version of jQuery which supported XPath expressions. XPath expressions are no longer a part of JQuery. But there are two solutions :
a). Either add the XPath plugin for jQuery, OR
b). Change the XPath expression to a normal jQuery selector expression.

I used the latter.

A live demo of the headline rotator can be found at adevelopedworld.com.

Comments (2)