Sha256: 36d6d36984f180887b01f3dbdbe5b457039fa6d7d12909e0ddfd39c9cc8e7192

Contents?: true

Size: 1.2 KB

Versions: 2

Compression:

Stored size: 1.2 KB

Contents

# How to setup a predefined filter?
# ---------------------------------
#
# On your controllers:
#
#     def index
#       # Added predefined filter takes any argument, but in the views we
#       # expected the following:
#       #
#       #     add_predefined_filter(filter_name, action, scope)
#       #
#       ...
#       add_predefined_filter("Trash", "trash", "deleted")
#       ...
#     end
#
# On your views:
#
#     <% predefined_filters.each do |filter_name, action, scope| %>
#       ...
#     <% end %>
#
module Typus
  module Controller
    module Filters

      def self.included(base)
        base.helper_method :predefined_filters
      end

      protected

      def add_predefined_filter(*args)
        predefined_filters
        @predefined_filters << args unless args.empty?
      end

      def prepend_predefined_filter(*args)
        predefined_filters
        @predefined_filters = @predefined_filters.unshift(args) unless args.empty?
      end

      def append_predefined_filter(*args)
        predefined_filters
        @predefined_filters = @predefined_filters.concat([args]) unless args.empty?
      end

      def predefined_filters
        @predefined_filters ||= []
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
typus-3.1.10 lib/typus/controller/filters.rb
typus-3.1.9 lib/typus/controller/filters.rb