Sha256: cef31dce02522a1fcec4d1936c9c687edcde505d0d6c5eeeac5830ee224e5238

Contents?: true

Size: 1.29 KB

Versions: 42

Compression:

Stored size: 1.29 KB

Contents

module Virgo
  module Admin
    module PostHelper
      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

      def admin_post_category_options(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| "&nbsp;&nbsp;&nbsp;" }.join("")
          select_option = ["#{spaces}#{cat.name}".html_safe, cat.id]
          select_options << select_option

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

        select_options
      end

      def admin_post_status_options
        Post.status_names
      end
    end
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
virgo-0.3.17 app/helpers/virgo/admin/post_helper.rb
virgo-0.3.16 app/helpers/virgo/admin/post_helper.rb
virgo-0.3.15 app/helpers/virgo/admin/post_helper.rb
virgo-0.3.14 app/helpers/virgo/admin/post_helper.rb
virgo-0.3.13 app/helpers/virgo/admin/post_helper.rb
virgo-0.3.12 app/helpers/virgo/admin/post_helper.rb
virgo-0.3.11 app/helpers/virgo/admin/post_helper.rb
virgo-0.3.10 app/helpers/virgo/admin/post_helper.rb
virgo-0.3.9 app/helpers/virgo/admin/post_helper.rb
virgo-0.3.8 app/helpers/virgo/admin/post_helper.rb
virgo-0.3.7 app/helpers/virgo/admin/post_helper.rb
virgo-0.3.6 app/helpers/virgo/admin/post_helper.rb
virgo-0.3.4 app/helpers/virgo/admin/post_helper.rb
virgo-0.3.3 app/helpers/virgo/admin/post_helper.rb
virgo-0.3.2 app/helpers/virgo/admin/post_helper.rb
virgo-0.3.1 app/helpers/virgo/admin/post_helper.rb
virgo-0.3 app/helpers/virgo/admin/post_helper.rb
virgo-0.2.9 app/helpers/virgo/admin/post_helper.rb
virgo-0.2.8 app/helpers/virgo/admin/post_helper.rb
virgo-0.2.7 app/helpers/virgo/admin/post_helper.rb