Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
neoteric-archiver / lib / neoteric-archiver / archiver_controller.rb
Size: Mime:
module Neoteric
  module ArchiverController
    def self.included(base)
      base.extend ClassMethods
      base.helper_method :archive_months
    end

    def archive
      @title ||= "Posted in #{month_name} #{params[:year]}"
      set_archive_collection(params[:year], params[:month])
      render :template => "#{archiving_model_template_path}/index"
    end

    module ClassMethods
      def archiving(klass)
        @archiving_klass = klass
      end

      def archiving_klass
        @archiving_klass
      end
    end

    private
    def month_name
      if params[:month]
        Date::MONTHNAMES[params[:month].to_i]
      end
    end

    def archive_months
      @archiver_archive_months = self.class.archiving_klass.archive_months
    end

    def set_archive_collection(year, month)
      posts = if month.nil?
                self.class.archiving_klass.published.by_year(year)
              else
                self.class.archiving_klass.published.by_month(year, month)
              end
      instance_variable_set("@#{plural_archiving_model_name}", posts)
    end

    def plural_archiving_model_name
      self.class.archiving_klass.name.gsub(/\w+::/,'').tableize
    end

    def archiving_model_template_path
      self.class.archiving_klass.name.tableize
    end
  end
end