Class: Spree::Image

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

Defined Under Namespace

Modules: Configuration

Instance Method Summary collapse

Methods inherited from Base

belongs_to_required_by_default, page, spree_base_scopes

Methods included from Preferences::Preferable

#clear_preferences, #default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference

Instance Method Details

#plp_urlObject



61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/models/spree/image.rb', line 61

def plp_url
  size = self.class.styles[:plp_and_carousel]
  variant = attachment.variant(
    gravity: 'center',
    resize: size,
    extent: size,
    background: 'snow2',
    quality: 80
  )

  polymorphic_path(variant, only_path: true)
end

#style(name) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/models/spree/image.rb', line 31

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

  width, height = size.chop.split('x')

  {
    url: polymorphic_path(attachment.variant(combine_options: {
                                               gravity: 'center',
                                               resize: size,
                                               extent: size,
                                               background: 'snow2',
                                               quality: 80
                                             }), only_path: true),
    size: size,
    width: width,
    height: height
  }
end

#style_dimensions(name) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'app/models/spree/image.rb', line 51

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

  {
    width: width,
    height: height
  }
end

#stylesObject



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

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

    {
      url: polymorphic_path(attachment.variant(combine_options: {
                                                 gravity: 'center',
                                                 resize: size,
                                                 extent: size,
                                                 background: 'snow2',
                                                 quality: 80
                                               }), only_path: true),
      width: width,
      height: height
    }
  end
end