Class: Imgix::Rails::PictureTag
- Includes:
- ActionView::Context
- Defined in:
- lib/imgix/rails/picture_tag.rb
Instance Method Summary collapse
-
#initialize(path, source: nil, tag_options: {}, url_params: {}, breakpoints: {}, srcset_options: {}) ⇒ PictureTag
constructor
A new instance of PictureTag.
- #render ⇒ Object
Methods included from UrlHelper
Constructor Details
#initialize(path, source: nil, tag_options: {}, url_params: {}, breakpoints: {}, srcset_options: {}) ⇒ PictureTag
Returns a new instance of PictureTag.
8 9 10 11 12 13 14 15 |
# File 'lib/imgix/rails/picture_tag.rb', line 8 def initialize(path, source: nil, tag_options: {}, url_params: {}, breakpoints: {}, srcset_options: {}) @path = path @source = source = @url_params = url_params @breakpoints = breakpoints = end |
Instance Method Details
#render ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/imgix/rails/picture_tag.rb', line 17 def render content_tag(:picture, ) do @breakpoints.each do |media, opts| validate_opts(opts) source_tag_opts = opts[:tag_options] || {} source_tag_url_params = opts[:url_params] || {} = opts[:srcset_options] || {} source_tag_opts[:media] ||= media source_tag_opts[:srcset] ||= srcset(url_params: @url_params.clone.merge(source_tag_url_params), srcset_options: ) concat(content_tag(:source, nil, source_tag_opts)) end concat Imgix::Rails::ImageTag.new(@path, source: @source, url_params: @url_params, srcset_options: ).render end end |