Class: Spree::Image

Inherits:
Asset
  • Object
show all
Includes:
Configuration::ActiveStorage, ImageMethods
Defined in:
app/models/spree/image.rb,
app/models/spree/image/configuration/active_storage.rb

Defined Under Namespace

Modules: Configuration

Constant Summary

Constants inherited from Asset

Asset::EXTERNAL_URL_METAFIELD_KEY

Instance Method Summary collapse

Methods included from ImageMethods

#generate_url, #original_url

Methods inherited from Asset

#external_url, #external_url=, #product, #skip_import?

Instance Method Details

#plp_urlObject



53
54
55
# File 'app/models/spree/image.rb', line 53

def plp_url
  generate_url(size: self.class.styles[:plp_and_carousel])
end

#style(name) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/models/spree/image.rb', line 29

def style(name)
  size = self.class.styles[name]
  return unless size

  width, height = size.chop.split('x').map(&:to_i)

  {
    url: generate_url(size: size),
    size: size,
    width: width,
    height: height
  }
end

#style_dimensions(name) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'app/models/spree/image.rb', line 43

def style_dimensions(name)
  size = self.class.styles[name]
  width, height = size.chop.split('x').map(&:to_i)

  {
    width: width,
    height: height
  }
end

#stylesObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/models/spree/image.rb', line 16

def styles
  self.class.styles.map do |_, size|
    width, height = size.chop.split('x').map(&:to_i)

    {
      url: generate_url(size: size),
      size: size,
      width: width,
      height: height
    }
  end
end