Module: Admin::PagesHelper

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

Instance Method Summary collapse

Instance Method Details

#available_templates_for_selectObject


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

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


13
14
15
# File 'app/helpers/admin/pages_helper.rb', line 13

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

#news_section_name(page, news_pages) ⇒ Object


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

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


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

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

#page_block_field(form, block_name, block_options) ⇒ Object


29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/helpers/admin/pages_helper.rb', line 29

def page_block_field(form, block_name, block_options)
  labelled_field(
    if block_options[:type] == :select
      page_block_select(form, block_name, block_options)
    else
      page_block_text_field(form, block_name, block_options)
    end,
    block_options[:title],
    errors: form.object.errors[block_name],
    description: block_options[:description]
  )
end

#page_block_select(form, block_name, block_options) ⇒ Object


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

def page_block_select(form, block_name, block_options)
  opts = localize_page_select_options(form, block_options)
  opts = opts.call if opts.is_a?(Proc)
  opts = opts.map { |v| [v, v] } unless nested_array?(opts)
  opts = ([["", nil]] + opts).uniq

  value = form.object.send(block_name)
  opts << [value, value] unless opts.map(&:last).include?(value)

  form.send(:select, block_name, opts)
end

#page_block_text_field(form, block_name, block_options) ⇒ Object


54
55
56
57
58
59
60
# File 'app/helpers/admin/pages_helper.rb', line 54

def page_block_text_field(form, block_name, block_options)
  form.send(
    block_options[:size] == :field ? :text_field : :text_area,
    block_name,
    page_block_field_options(block_options)
  )
end

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


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

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) },
    raw(" &raquo; ")
  )
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