Module: Refinery::Admin::PagesHelper

Defined in:
app/helpers/refinery/admin/pages_helper.rb

Instance Method Summary collapse

Instance Method Details

#default_layout_template(current_page) ⇒ Object



35
36
37
# File 'app/helpers/refinery/admin/pages_helper.rb', line 35

def default_layout_template(current_page)
  "application"
end

#default_view_template(current_page) ⇒ Object



31
32
33
# File 'app/helpers/refinery/admin/pages_helper.rb', line 31

def default_view_template(current_page)
  current_page.link_url == "/" ? "home" : "show"
end

#page_icon(number_of_children) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/helpers/refinery/admin/pages_helper.rb', line 62

def page_icon(number_of_children)
  # 1. has_children 'folder|folderopen', 'toggle'
  # 2. no_children 'page'

  # .toggle scss handles adding icons to pages with children
  classes = ['icon']
  if number_of_children.zero?
    classes.push icon_class('page')
    title = ::I18n.t('edit', scope: 'refinery.admin.pages.page')
  else
    expanded_class = Refinery::Pages.auto_expand_admin_tree ? 'expanded' : ''
    classes.push 'toggle', expanded_class
    title = ::I18n.t('expand_collapse', scope: 'refinery.admin.pages')
  end

  tag.span(class: classes.join(' '), title: title)
end

#page_meta_information(page) ⇒ Object

In the admin area we use a slightly different title to inform the which pages are draft or hidden pages



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/helpers/refinery/admin/pages_helper.rb', line 41

def page_meta_information(page)
  meta_information = ActiveSupport::SafeBuffer.new
  meta_information << (:span, :class => 'label') do
    ::I18n.t('hidden', :scope => 'refinery.admin.pages.page')
  end unless page.show_in_menu?

  meta_information << (:span, :class => 'label') do
    ::I18n.t('skip_to_first_child', :scope => 'refinery.admin.pages.page')
  end if page.skip_to_first_child?

  meta_information << (:span, :class => 'label') do
    ::I18n.t('redirected', :scope => 'refinery.admin.pages.page')
  end if page.link_url?

  meta_information << (:span, :class => 'label notice') do
    ::I18n.t('draft', :scope => 'refinery.admin.pages.page')
  end if page.draft?

  tag.span meta_information, class: :meta
end

#parent_id_nested_set_options(current_page) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/helpers/refinery/admin/pages_helper.rb', line 4

def parent_id_nested_set_options(current_page)
  pages = []
  nested_set_options(::Refinery::Page, current_page) { |page| pages << page }
  # page.title needs the :translations association, doing something like
  # nested_set_options(::Refinery::Page.includes(:translations), page) doesn't work, yet.
  # See https://github.com/collectiveidea/awesome_nested_set/pull/123
  if Rails::VERSION::MAJOR >= 7
    ActiveRecord::Associations::Preloader.new(records: pages, associations: :translations).call
  else
    ActiveRecord::Associations::Preloader.new.preload(pages, :translations)
  end
  pages.map { |page| ["#{'-' * page.level} #{page.title}", page.id] }
end

#template_options(template_type, current_page) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/helpers/refinery/admin/pages_helper.rb', line 18

def template_options(template_type, current_page)
  html_options = { selected: send("default_#{template_type}", current_page) }

  if (template = current_page.send(template_type).presence)
    html_options.update selected: template
  elsif current_page.parent_id? && !current_page.send(template_type).presence
    template = current_page.parent.send(template_type).presence
    html_options.update selected: template if template
  end

  html_options
end