Module: Spree::Admin::StoresHelper

Includes:
ImagesHelper
Defined in:
app/helpers/spree/admin/stores_helper.rb

Constant Summary collapse

DEFAULT_ICON_SIZE =
40

Instance Method Summary collapse

Instance Method Details

#first_letter_icon(name, opts = {}) ⇒ Object



28
29
30
31
32
33
34
# File 'app/helpers/spree/admin/stores_helper.rb', line 28

def first_letter_icon(name, opts = {})
  opts[:height] ||= DEFAULT_ICON_SIZE
  opts[:width] ||= DEFAULT_ICON_SIZE
  opts[:class] ||= ''
  opts[:class] += ' store-icon rounded-lg  text-gray-900 flex items-center justify-center'
  (:span, name[0].upcase, class: opts[:class], style: "height: #{opts[:height]}px; width: #{opts[:width]}px;")
end

#store_admin_icon(store, opts = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/helpers/spree/admin/stores_helper.rb', line 8

def store_admin_icon(store, opts = {})
  opts[:class] ||= 'rounded-md bg-white border store-icon'
  opts[:height] ||= DEFAULT_ICON_SIZE
  opts[:width] ||= DEFAULT_ICON_SIZE

  store ||= current_store

  return unless store

  Rails.cache.fetch(["#{store.cache_key_with_version}/admin_icon", opts.to_param]) do
    if store.&.attached? && store.&.variable?
      spree_image_tag(store., class: opts[:class], width: opts[:width], height: opts[:height])
    elsif store.respond_to?(:favicon_image) && store.favicon_image&.attached? && store.favicon_image&.variable?
      spree_image_tag(store.favicon_image, class: opts[:class], width: opts[:width], height: opts[:height])
    else
      first_letter_icon(store.name, opts)
    end
  end
end