class Rack::LazyLoad

Public Instance Methods

change_nokogiri_doc(doc) click to toggle source
# File lib/rack/lazy-load.rb, line 7
def change_nokogiri_doc(doc)
  doc.css(".container img").each do |img|

    # Add width and height attributes if they don't exist
    size = FastImage.size(img["src"])
    unless size.nil?
      img["width"]  = size[0].to_s if img["width"].nil?
      img["height"] = size[1].to_s if img["height"].nil?
    end
    
    img["data-original"] = img["src"]
    img["src"] = "http://appelsiini.net/projects/lazyload/img/grey.gif"
  end
  doc
end