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



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

def default_layout_template(current_page)
  "application"
end

#default_view_template(current_page) ⇒ Object



27
28
29
# File 'app/helpers/refinery/admin/pages_helper.rb', line 27

def default_view_template(current_page)
  current_page.link_url == "/" ? "home" : "show"
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



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/helpers/refinery/admin/pages_helper.rb', line 37

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?

  meta_information
end

#parent_id_nested_set_options(current_page) ⇒ Object



4
5
6
7
8
9
10
11
12
# 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
  ActiveRecord::Associations::Preloader.new.preload(pages, :translations)
  pages.map { |page| ["#{'-' * page.level} #{page.title}", page.id]}
end

#template_options(template_type, current_page) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/helpers/refinery/admin/pages_helper.rb', line 14

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