Sha256: c15343fd4f7fe456127febca2239cf937610a51fe300bd91f89161223423d562

Contents?: true

Size: 1.17 KB

Versions: 17

Compression:

Stored size: 1.17 KB

Contents

##
# How predefined filters work?
#
# On your controllers ...
#
#     def index
#       # Added predefined filter takes any argumes, 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

17 entries across 17 versions & 1 rubygems

Version Path
typus-3.1.8 lib/typus/controller/filters.rb
typus-3.1.7 lib/typus/controller/filters.rb
typus-3.1.6 lib/typus/controller/filters.rb
typus-3.1.5 lib/typus/controller/filters.rb
typus-3.1.4 lib/typus/controller/filters.rb
typus-3.1.3 lib/typus/controller/filters.rb
typus-3.1.2 lib/typus/controller/filters.rb
typus-3.1.1 lib/typus/controller/filters.rb
typus-3.1.0 lib/typus/controller/filters.rb
typus-3.1.0.rc19 lib/typus/controller/filters.rb
typus-3.1.0.rc18 lib/typus/controller/filters.rb
typus-3.1.0.rc17 lib/typus/controller/filters.rb
typus-3.1.0.rc16 lib/typus/controller/filters.rb
typus-3.1.0.rc15 lib/typus/controller/filters.rb
typus-3.1.0.rc14 lib/typus/controller/filters.rb
typus-3.1.0.rc13 lib/typus/controller/filters.rb
typus-3.1.0.rc12 lib/typus/controller/filters.rb