Module: Workarea::Admin::ContentHelper

Defined in:
app/helpers/workarea/admin/content_helper.rb

Instance Method Summary collapse

Instance Method Details

#block_delete_message(block) ⇒ Object



50
51
52
53
54
55
56
# File 'app/helpers/workarea/admin/content_helper.rb', line 50

def block_delete_message(block)
  if current_release.present?
    t('workarea.admin.content.messages.delete_from_release', block_type: block.type.name, release: current_release.name)
  else
    t('workarea.admin.content.messages.delete', block_type: block.type.name)
  end
end

#color_picker_id(block, field) ⇒ Object



64
65
66
# File 'app/helpers/workarea/admin/content_helper.rb', line 64

def color_picker_id(block, field)
  "#{block.id}-#{field.name.parameterize}-colors"
end

#current_system_page_content_for(name) ⇒ Object



4
5
6
7
# File 'app/helpers/workarea/admin/content_helper.rb', line 4

def current_system_page_content_for(name)
  @tmp ||= {}
  @tmp[name.to_s.systemize] ||= Content.for(name.to_s.systemize)
end

#options_for_category(category_id) ⇒ Object



36
37
38
39
40
41
# File 'app/helpers/workarea/admin/content_helper.rb', line 36

def options_for_category(category_id)
  return nil unless category_id.present?

  model = Catalog::Category.find(category_id)
  options_for_select({ model.name => model.id }, model.id)
end

#options_for_products(product_ids) ⇒ Object



43
44
45
46
47
48
# File 'app/helpers/workarea/admin/content_helper.rb', line 43

def options_for_products(product_ids)
  return nil unless product_ids.present?

  products = Catalog::Product.find_ordered_for_display(product_ids)
  options_from_collection_for_select(products, 'id', 'name', product_ids)
end

#preview_breakpointsObject



58
59
60
61
62
# File 'app/helpers/workarea/admin/content_helper.rb', line 58

def preview_breakpoints
  Workarea.config.storefront_break_points.select do |name, size|
    name.to_s.in?(Workarea.config.content_preview_breakpoints)
  end
end

#render_content_areas(content) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/helpers/workarea/admin/content_helper.rb', line 9

def render_content_areas(content)
  partial = "workarea/admin/content/types/_#{content.slug}"
  if lookup_context.find_all(partial).any?
    render(
      partial: "workarea/admin/content/types/#{content.slug}",
      locals: { content: content }
    )
  else
    render(
      partial: 'workarea/admin/content/types/generic',
      locals: { content: content }
    )
  end
end

#storefront_content_preview_path(content) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'app/helpers/workarea/admin/content_helper.rb', line 24

def storefront_content_preview_path(content)
  return storefront.root_path unless content

  if content.layout? || content.home_page?
    storefront.root_path(draft_id: content.id)
  elsif content.contentable.is_a?(Content::Page)
    storefront.page_path(content.contentable, draft_id: content.id)
  elsif content.contentable.is_a?(Catalog::Category)
    storefront.category_path(content.contentable, draft_id: content.id)
  end
end