Class: Rack::LazyLoad

Inherits:
Plastic
  • Object
show all
Defined in:
lib/rack/lazy-load.rb

Instance Method Summary collapse

Instance Method Details

#change_nokogiri_doc(doc) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 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