Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions lib/imgix/rails/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ def initialize(path, source: nil, tag_options: {}, url_params: {}, srcset_option

protected

def srcset(source: @source, path: @path, url_params: @url_params, srcset_options: @srcset_options, tag_options: @tag_options)
def srcset(source: @source, path: @path, url_params: @url_params, srcset_options: @srcset_options)
params = url_params.clone

width_tolerance = ::Imgix::Rails.config.imgix[:srcset_width_tolerance]
min_width = @srcset_options[:min_width]
max_width = @srcset_options[:max_width]
widths = @srcset_options[:widths]
disable_variable_quality = @srcset_options[:disable_variable_quality]
options = { widths: widths, width_tolerance: width_tolerance, min_width: min_width, max_width: max_width, disable_variable_quality: disable_variable_quality}
min_width = srcset_options[:min_width]
max_width = srcset_options[:max_width]
widths = srcset_options[:widths]
disable_variable_quality = srcset_options[:disable_variable_quality]
options = {widths: widths, width_tolerance: width_tolerance, min_width: min_width, max_width: max_width, disable_variable_quality: disable_variable_quality}

ix_image_srcset(@source, @path, params, options)
ix_image_srcset(source, path, params, options)
end
end
33 changes: 33 additions & 0 deletions spec/imgix/rails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,39 @@
expect(tag.children[1].attribute('src').value).not_to include('widths')
end
end

context 'breakpoint overrides' do
let(:tag) do
picture_tag = helper.ix_picture_tag(
'bertandernie.jpg',
srcset_options: {
widths: [100,200]
},
breakpoints: {
"800px": {
srcset_options: {
widths: [600,700]
}
}
}
)
Nokogiri::HTML.fragment(picture_tag).children[0]
end

it 'uses base settings on img tag' do
expect(tag.children[1].attribute('srcset').value).to include('100w')
expect(tag.children[1].attribute('srcset').value).to include('200w')
expect(tag.children[1].attribute('srcset').value).not_to include('600w')
expect(tag.children[1].attribute('srcset').value).not_to include('700w')
end

it 'uses breakpoint override on source tag' do
expect(tag.children[0].attribute('srcset').value).not_to include('100w')
expect(tag.children[0].attribute('srcset').value).not_to include('200w')
expect(tag.children[0].attribute('srcset').value).to include('600w')
expect(tag.children[0].attribute('srcset').value).to include('700w')
end
end
end

context 'with img_tag_options' do
Expand Down