Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Removed unused image helpers (#14790)

Damian Legawiec620de865a555
diff --git a/docs/developer/upgrades/5.6-to-6.0.mdx b/docs/developer/upgrades/5.6-to-6.0.mdx
index 67e92de092..32d58addb7 100644
--- a/docs/developer/upgrades/5.6-to-6.0.mdx
+++ b/docs/developer/upgrades/5.6-to-6.0.mdx
@@ -728,7 +728,7 @@ Every transactional email now renders from a Liquid template written in MJML ins
Other changes that come with it:
- **Subjects moved into the templates.** Each template's front matter holds its subject. `Spree::BaseMailer#order_email_subject` is removed.
-- **The mailer view helpers are removed.** `Spree::MailHelper` (`name_for`), `Spree::BaseHelper` (`spree_storefront_resource_url`), `Spree::FulfillmentHelper` and `Spree::DigitalAssetHelper` are gone. Templates get the same values as serializer fields, such as `order.customer_name` and `item.url`.
+- **The mailer view helpers are removed.** `Spree::MailHelper` (`name_for`), `Spree::BaseHelper` (`spree_storefront_resource_url`), `Spree::FulfillmentHelper` and `Spree::DigitalAssetHelper` are gone, and so are `spree_image_tag` and `spree_asset_aspect_ratio` from `Spree::ImagesHelper` (`spree_image_url` stays). Templates get the same values as serializer fields, such as `order.customer_name` and `item.url`.
- **Every email has a plain-text part**, generated from the HTML. Seven emails that had none now have one.
- **Alba moved into `spree_core`**, with its configuration, so core's staff emails render in installations without `spree_api`.
- **Your own mailers keep working.** A mailer that inherits `Spree::BaseMailer` and calls `mail` with its own ERB views is wrapped in the new email layout, and the `spree/shared/mailer_hero` and `mailer_button` partials remain for its views. See [Your own mailers](/developer/customization/emails#your-own-mailers).
diff --git a/spree/core/app/helpers/spree/images_helper.rb b/spree/core/app/helpers/spree/images_helper.rb
index af7e450c69..80e059cf3a 100644
--- a/spree/core/app/helpers/spree/images_helper.rb
+++ b/spree/core/app/helpers/spree/images_helper.rb
@@ -1,30 +1,5 @@
module Spree
module ImagesHelper
- # render an image tag with a spree image variant
- # it also automatically scales the width and height by 2x to look great on retina screens
- #
- # @param image [ActiveStorage::Attachment] the image to render
- # @param options [Hash] options for the image tag
- # @option options [Integer] :width the width of the image
- # @option options [Integer] :height the height of the image
- # @option options [Symbol] :variant use a preprocessed named variant (e.g., :mini, :small, :medium, :large, :xlarge)
- def spree_image_tag(image, options = {})
- return unless image
- return unless image.variable?
- return if image.respond_to?(:attached?) && !image.attached?
-
- url_options = if options[:variant].present?
- { variant: options[:variant] }
- else
- { width: options[:width], height: options[:height], format: options[:format] }
- end
-
- image_tag(
- spree_image_url(image, url_options),
- options.except(:variant, :format)
- )
- end
-
def spree_image_url(image, options = {})
return unless image
return unless image.variable?
@@ -56,38 +31,6 @@ module Spree
end
end
- def spree_asset_aspect_ratio(attachment)
- return unless attachment.present?
- return unless attachment.analyzed?
-
- metadata = attachment.metadata
- aspect_ratio = metadata['aspect_ratio'].presence
-
- return aspect_ratio if aspect_ratio
-
- width = metadata['width']&.to_f
- return unless width
-
- height = metadata['height']&.to_f
- return unless height
- return if height.zero?
-
- w = width.to_f
- h = height.to_f
-
- # Always return width / height, flipping if needed
- ratio = if h > w
- h / w
- elsif h < w
- w / h
- else
- # h == w, square image
- 1.0
- end
-
- ratio.round(3)
- end
-
# convert images to webp with some sane optimization defaults
# it also automatically scales the width and height by 2x to look great on retina screens
#
diff --git a/spree/core/lib/spree/core/configuration.rb b/spree/core/lib/spree/core/configuration.rb
index e0217d5dc8..2bdd6cb7ce 100644
--- a/spree/core/lib/spree/core/configuration.rb
+++ b/spree/core/lib/spree/core/configuration.rb
@@ -60,7 +60,7 @@ module Spree
# Preprocessed product image variant sizes at 2x retina resolution.
# These variants are generated on upload to reduce runtime processing.
- # When using spree_image_tag, pass variant option instead of width and height.
+ # Pass the variant to spree_image_url instead of a width and height.
#
# Default sizes:
# mini (128x128) - admin thumbnails, checkout line items
diff --git a/spree/core/spec/helpers/images_helper_spec.rb b/spree/core/spec/helpers/images_helper_spec.rb
index 350c5ced86..d4e2fb6300 100644
--- a/spree/core/spec/helpers/images_helper_spec.rb
+++ b/spree/core/spec/helpers/images_helper_spec.rb
@@ -12,49 +12,6 @@ describe Spree::ImagesHelper, type: :helper do
)
product_image
end
- let(:attachment) { image.attachment }
-
- describe '#spree_image_tag' do
- it 'returns an image tag with the correct url' do
- expect(helper).to receive(:spree_image_url).with(image, { width: 100, height: 100, format: nil }).and_return('image_url')
- expect(helper).to receive(:image_tag).with('image_url', { width: 100, height: 100 }).and_return('image_tag')
- expect(helper.spree_image_tag(image, width: 100, height: 100)).to eq('image_tag')
- end
-
- context 'when variant option is provided' do
- it 'passes only variant to spree_image_url and excludes it from image_tag options' do
- expect(helper).to receive(:spree_image_url).with(image, { variant: :mini }).and_return('image_url')
- expect(helper).to receive(:image_tag).with('image_url', { class: 'test-class' }).and_return('image_tag')
- expect(helper.spree_image_tag(image, variant: :mini, class: 'test-class')).to eq('image_tag')
- end
-
- it 'ignores width, height, and format when variant is provided' do
- expect(helper).to receive(:spree_image_url).with(image, { variant: :small }).and_return('image_url')
- expect(helper).to receive(:image_tag).with('image_url', { width: 100, height: 100 }).and_return('image_tag')
- expect(helper.spree_image_tag(image, variant: :small, width: 100, height: 100, format: :png)).to eq('image_tag')
- end
- end
-
- context 'when image is not attached' do
- before do
- allow(image).to receive(:attached?).and_return(false)
- end
-
- it 'returns nil' do
- expect(helper.spree_image_tag(image)).to be_nil
- end
- end
-
- context 'when image is not variable' do
- before do
- allow(image).to receive_messages(attached?: true, variable?: false)
- end
-
- it 'returns nil' do
- expect(helper.spree_image_tag(image)).to be_nil
- end
- end
- end
describe '#spree_image_url' do
it 'supports blob' do
@@ -124,65 +81,4 @@ describe Spree::ImagesHelper, type: :helper do
end
end
end
-
- describe '#spree_asset_aspect_ratio' do
- context 'when attachment is not present' do
- it 'returns nil' do
- expect(helper.spree_asset_aspect_ratio(nil)).to be_nil
- end
- end
-
- context 'when attachment is not analyzed' do
- before do
- allow(attachment).to receive(:analyzed?).and_return(false)
- end
-
- it 'returns nil' do
- expect(helper.spree_asset_aspect_ratio(attachment)).to be_nil
- end
- end
-
- context 'when aspect_ratio is present in metadata' do
- before do
- allow(attachment).to receive_messages(analyzed?: true, metadata: { 'aspect_ratio' => 1.5 })
- end
-
- it 'returns the aspect ratio' do
- expect(helper.spree_asset_aspect_ratio(attachment)).to eq(1.5)
- end
- end
-
- context 'when calculating aspect ratio from dimensions' do
- before do
- allow(attachment).to receive_messages(analyzed?: true, metadata: { 'width' => width, 'height' => height })
- end
-
- context 'when height is greater than width' do
- let(:width) { 100 }
- let(:height) { 200 }
-
- it 'returns the correct ratio' do
- expect(helper.spree_asset_aspect_ratio(attachment)).to eq(2.0)
- end
- end
-
- context 'when width is greater than height' do
- let(:width) { 200 }
- let(:height) { 100 }
-
- it 'returns the correct ratio' do
- expect(helper.spree_asset_aspect_ratio(attachment)).to eq(2.0)
- end
- end
-
- context 'when width equals height' do
- let(:width) { 100 }
- let(:height) { 100 }
-
- it 'returns 1.0' do
- expect(helper.spree_asset_aspect_ratio(attachment)).to eq(1.0)
- end
- end
- end
- end
end