Module: Admin::PagesHelper

Includes:
PagesCore::Admin::PageBlocksHelper
Defined in:
app/helpers/admin/pages_helper.rb

Instance Method Summary collapse

Methods included from PagesCore::Admin::PageBlocksHelper

#page_block_field, #page_block_select, #page_block_text_field

Instance Method Details

#autopublish_notice(page) ⇒ Object



7
8
9
10
11
12
13
14
# File 'app/helpers/admin/pages_helper.rb', line 7

def autopublish_notice(page)
  return unless page.autopublish?

  tag.div(class: "autopublish-notice") do
    safe_join(["This page will be published",
               tag.b(publish_time(page.published_at))], " ")
  end
end

#available_templates_for_selectObject



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

def available_templates_for_select
  PagesCore::Templates.names.collect do |template|
    if template == "index"
      ["[Default]", "index"]
    else
      [template.humanize, template]
    end
  end
end

#file_embed_code(file) ⇒ Object



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

def file_embed_code(file)
  "[file:#{file.id}]"
end

#news_section_name(page, news_pages) ⇒ Object



30
31
32
33
34
35
36
# File 'app/helpers/admin/pages_helper.rb', line 30

def news_section_name(page, news_pages)
  if news_pages.select { |p| p.name == page.name }.length > 1
    page_name(page, include_parents: true)
  else
    page_name(page)
  end
end

#page_authors(page) ⇒ Object



38
39
40
# File 'app/helpers/admin/pages_helper.rb', line 38

def page_authors(page)
  ([page.author] + User.activated).uniq
end

#page_list_row(page) ⇒ Object



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

def page_list_row(page, &)
  classes = [page.status_label.downcase]
  classes << "autopublish" if page.autopublish?
  classes << "pinned" if page.pinned?

  tag.tr(capture(&), class: classes.join(" "))
end

#page_name(page, options = {}) ⇒ Object



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

def page_name(page, options = {})
  page_names = if options[:include_parents]
                 page.self_and_ancestors.reverse
               else
                 [page]
               end
  safe_join(page_names.map { |p| page_name_with_fallback(p) }, " ยป ")
end

#page_published_date(page) ⇒ Object



66
67
68
69
70
71
72
# File 'app/helpers/admin/pages_helper.rb', line 66

def page_published_date(page)
  if page.published_at.year == Time.zone.now.year
    l(page.published_at, format: :pages_date)
  else
    l(page.published_at, format: :pages_full)
  end
end

#page_published_status(page) ⇒ Object



59
60
61
62
63
64
# File 'app/helpers/admin/pages_helper.rb', line 59

def page_published_status(page)
  return page_published_date(page) if page.published?
  return tag.em("Not published") if page.status_label == "Published"

  tag.em(page.status_label)
end

#publish_time(time) ⇒ Object



74
75
76
77
78
79
80
81
82
# File 'app/helpers/admin/pages_helper.rb', line 74

def publish_time(time)
  if time.year != Time.zone.now.year
    time.strftime("on %b %d %Y at %H:%M")
  elsif time.to_date != Time.zone.now.to_date
    time.strftime("on %b %d at %H:%M")
  else
    time.strftime("at %H:%M")
  end
end