Class: Banzai::Filter::ImageLazyLoadFilter

Inherits:
HTML::Pipeline::Filter
  • Object
show all
Defined in:
lib/banzai/filter/image_lazy_load_filter.rb

Overview

HTML filter that moves the value of image `src` attributes to `data-src` so they can be lazy loaded.

Instance Method Summary collapse

Instance Method Details

#callObject


9
10
11
12
13
14
15
16
17
# File 'lib/banzai/filter/image_lazy_load_filter.rb', line 9

def call
  doc.xpath('descendant-or-self::img').each do |img|
    img.add_class('lazy')
    img['data-src'] = img['src']
    img['src'] = LazyImageTagHelper.placeholder_image
  end

  doc
end