Module: Locomotive::PagesHelper

Defined in:
app/helpers/locomotive/pages_helper.rb

Instance Method Summary collapse

Instance Method Details

#add_children_to_options(page, children, list) ⇒ Object


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

def add_children_to_options(page, children, list)
  return list if page.parent_ids.include?(@page.id) || page == @page

  offset = '- ' * (page.depth || 0) * 2

  list << ["#{offset}#{page.title}", page.id]

  if children
    children.each { |(_page, _children)| add_children_to_options(_page, _children, list) }
  end

  list
end

#display_page_layouts?Boolean

Returns:


32
33
34
35
# File 'app/helpers/locomotive/pages_helper.rb', line 32

def display_page_layouts?
  ((@page.persisted? && @page.allow_layout? && @page.use_layout?) || !@page.persisted?) &&
  !current_site.pages.layouts.empty?
end

#display_slug?(page) ⇒ Boolean

Returns:


28
29
30
# File 'app/helpers/locomotive/pages_helper.rb', line 28

def display_slug?(page)
  !page.index? && !page.not_found? && (!page.templatized? || page.templatized_from_parent?)
end

#options_for_page_layoutsObject


37
38
39
40
41
42
43
# File 'app/helpers/locomotive/pages_helper.rb', line 37

def options_for_page_layouts
  layouts = current_site.pages.layouts.map do |_layout|
    [_layout.title, _layout._id]
  end

  @page.index? ? layouts : [[t(:no_layout, scope: 'locomotive.pages.form'), 'parent']] + layouts
end

#options_for_page_redirect_typeObject


45
46
47
48
49
50
# File 'app/helpers/locomotive/pages_helper.rb', line 45

def options_for_page_redirect_type
  [
    [t('redirect_type.permanent', scope: 'locomotive.pages.form'), 301],
    [t('redirect_type.temporary', scope: 'locomotive.pages.form'), 302]
  ]
end

#parent_pages_optionsObject


4
5
6
7
8
9
10
11
12
# File 'app/helpers/locomotive/pages_helper.rb', line 4

def parent_pages_options
  [].tap do |list|
    build_page_tree.each do |(page, children)|
      next if page.not_found?

      add_children_to_options(page, children, list)
    end
  end
end