Tech - May 2008 Archives

Modifying attributes with Hpricot

If you’re processing HTML with Hpricot and want to change the attributes on a tag in a search block, beware that the attributes method on an element returns a copy of the actual attributes. In order to change the real attribute on the element, you need to set raw_attributes on it. Here’s what I had to do, boiled down to the scum on the pan:

doc = Hpricot(html)
doc.search("img").each do |element|
  # do some processing here, calculating the new attribute value
  # ...
  element.raw_attributes = element.attributes.merge("src" => new_src)
end
# now save the tweaked document
file.write(doc.to_html)

Here's what I wanted to say...

...but didn’t have the planning or eloquence to deliver during the ill-executed “panel discussion” at BarCamp KC.

“In addition, because of the magic of many of the early screencasts and hype surrounding Rails, some people came to the framework thinking of it as some sort of magical solution that would automate the entire business of creating web applications. In reality, while developers of all levels can take advantage of the power Rails and Ruby provide, the best results will still come from developers who invest the time to gain a solid foundation.” — Eldon Alameda

(emphasis added)

BarCamp KC a Success!

BarCamp was a blast yesterday. I met some really great and smart people, and my presentation went over very well. I think we’ll have some more people using Radiant in the near future. For those who didn’t get to see my presentation, or want to review what they did see, click below for a PDF of the slides (with notes).

Thanks again to Pete Thomas for doing the legwork, Ad Astra for the space, and all of the sponsors for helping make it happen!

Download the slides.