Class: Imgix::Rails::PictureTag

Inherits:
Tag
  • Object
show all
Includes:
ActionView::Context
Defined in:
lib/imgix/rails/picture_tag.rb

Instance Method Summary collapse

Methods inherited from Tag

available_parameters, parameters

Methods included from UrlHelper

#ix_image_url

Constructor Details

#initialize(source, options, default_options, breakpoints) ⇒ PictureTag

Returns a new instance of PictureTag.



7
8
9
10
11
12
# File 'lib/imgix/rails/picture_tag.rb', line 7

def initialize(source, options, default_options, breakpoints)
  @source = source
  @options = options
  @default_options = default_options
  @breakpoints = breakpoints
end

Instance Method Details

#renderObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/imgix/rails/picture_tag.rb', line 14

def render
  (:picture, @options) do
    @breakpoints.each do |media, opts|
      html_opts = opts.except(*self.class.available_parameters)
      html_opts[:media] ||= media
      html_opts[:srcset] ||= srcset(@default_options.clone.merge(opts))


      concat((:source, nil, html_opts))
    end

    concat Imgix::Rails::ImageTag.new(@source, @default_options).render
  end
end