Module: LazyImageTag::ImageHelper

Defined in:
lib/lazy_image_tag/helpers/image_helper.rb

Instance Method Summary collapse

Instance Method Details

#container_options(options) ⇒ Object



8
9
10
11
12
# File 'lib/lazy_image_tag/helpers/image_helper.rb', line 8

def container_options(options)
  container_options = {}
  container_options[:class] = "lazy-image-container"
  container_options
end

#image_helper(source, options) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/lazy_image_tag/helpers/image_helper.rb', line 24

def image_helper(source, options)
  custom_opts = options.dup
  custom_opts[:data] ||= {}
  custom_opts[:data][:original] = source = path_to_image(source)
  custom_opts[:class].blank? ? custom_opts[:class] = "lazy" : custom_opts[:class] << " lazy"
  custom_source = path_to_image("blank.png")
  content = image_tag(custom_source, custom_opts)
  content << (:noscript, image_tag(source, options)) if Rails.application.config.lazy_image_tag.js_disabled == :noscript
  (:div, content, container_options(options))
end

#image_tag_with_lazy(source, options = {}) ⇒ Object



4
5
6
# File 'lib/lazy_image_tag/helpers/image_helper.rb', line 4

def image_tag_with_lazy(source, options={})
  Rails.application.config.lazy_image_tag.js_disabled == :link ? link_helper(source, options) : image_helper(source, options)
end


14
15
16
17
18
19
20
21
22
# File 'lib/lazy_image_tag/helpers/image_helper.rb', line 14

def link_helper(source, options)
  options[:class].blank? ? options[:class] = "lazy-image-link" : options[:class] << " lazy-image-link"
  options[:data] ||= {}
  options[:data][:width] = options[:width]
  options[:data][:height] = options[:height]
  options[:data][:id] = options[:id]
  options[:alt] = options[:width] = options[:height] = options[:id] = nil
  (:div, link_to(options[:alt], path_to_image(source), options), container_options(options))
end