Module: Virgo::Admin::PostHelper

Defined in:
app/helpers/virgo/admin/post_helper.rb

Instance Method Summary collapse

Instance Method Details

#admin_post_category_options(category = nil, depth = 0) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/helpers/virgo/admin/post_helper.rb', line 26

def (category=nil, depth=0)
  select_options = []

  if category.nil?
    categories = Category.top_level
  else
    categories = [category]
  end

  categories.each do |cat|
    # base case
    spaces = (0..depth-1).map{|i| "   " }.join("")
    select_option = ["#{spaces}#{cat.name}".html_safe, cat.id]
    select_options << select_option

    cat.children.each do |child|
      select_options += (child, depth + 1)
    end
  end

  select_options
end

#admin_post_month_optionsObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/helpers/virgo/admin/post_helper.rb', line 4

def admin_post_month_options
  return [] if Post.where.not(publish_at: nil).empty?

  min_date = Post.minimum(:publish_at).try(:to_date)
  max_date = Time.now.to_date

  date_range = min_date..max_date

  month_names = []
  added = {}

  date_range.map {|d|
    date = Date.new(d.year, d.month, 1)
    if added[date].nil?
      month_names << [date.to_s(:month_and_year), date.to_s(:db)]
      added[date] = true
    end
  }.uniq

  month_names.reverse
end

#admin_post_status_optionsObject



49
50
51
# File 'app/helpers/virgo/admin/post_helper.rb', line 49

def admin_post_status_options
  Post.status_names
end