Module: Admin::PagesHelper

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

Instance Method Summary collapse

Instance Method Details

#autopublish_notice(page) ⇒ Object



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

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

#news_section_name(page, news_pages) ⇒ Object



14
15
16
17
18
19
20
# File 'app/helpers/admin/pages_helper.rb', line 14

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

#page_authors(page) ⇒ Object



22
23
24
# File 'app/helpers/admin/pages_helper.rb', line 22

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

#page_list_row(page) ⇒ Object



26
27
28
29
30
31
32
# File 'app/helpers/admin/pages_helper.rb', line 26

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



34
35
36
37
38
39
40
41
# File 'app/helpers/admin/pages_helper.rb', line 34

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



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

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



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

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



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

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