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



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

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



75
76
77
# File 'app/helpers/workarea/admin/content_helper.rb', line 75

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


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

def layout_footer_area_id
  @layout_footer_area_id ||= begin
    content = Admin::ContentViewModel.wrap(
      current_system_page_content_for(:layout)
    )

    content.areas.find { |a| a =~ /footer/i }
  end
end

#options_for_category(category_id) ⇒ Object



46
47
48
49
50
51
52
# File 'app/helpers/workarea/admin/content_helper.rb', line 46

def options_for_category(category_id)
  model = Catalog::Category.where(id: category_id).first

  return '' unless model.present?

  options_for_select({ model.name => model.id }, model.id)
end

#options_for_products(product_ids) ⇒ Object



54
55
56
57
58
59
# File 'app/helpers/workarea/admin/content_helper.rb', line 54

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



69
70
71
72
73
# File 'app/helpers/workarea/admin/content_helper.rb', line 69

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



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/helpers/workarea/admin/content_helper.rb', line 19

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



34
35
36
37
38
39
40
41
42
43
44
# File 'app/helpers/workarea/admin/content_helper.rb', line 34

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