Sha256: f2cbaf33ec4ddca9c1e76e260a5cdcf9414a03c30396758b30de171fdef4b431

Contents?: true

Size: 1.14 KB

Versions: 25

Compression:

Stored size: 1.14 KB

Contents

# encoding: UTF-8
module Wice

  class GridOutputBuffer < String #:nodoc:

    attr_accessor :return_empty_strings_for_nonexistent_filters

    def initialize(*attrs)
      super(*attrs)
      @filters = HashWithIndifferentAccess.new
    end

    def to_s
      super.html_safe
    end

    def add_filter(detach_with_id, filter_code)
      raise  WiceGridException.new("Detached ID #{detach_with_id} is already used!") if @filters.has_key? detach_with_id
      @filters[detach_with_id] = filter_code
    end

    def filter_for detach_with_id
      unless @filters.has_key? detach_with_id
        if @return_empty_strings_for_nonexistent_filters
          return ''
        else
          raise  WiceGridException.new("No filter with Detached ID '#{detach_with_id}'!")
        end
      end
      if @filters[detach_with_id] == false
        raise  WiceGridException.new("Filter with Detached ID '#{detach_with_id}' has already been requested once! There cannot be two instances of the same filter on one page")
      end
      res = @filters[detach_with_id]
      @filters[detach_with_id] = false
      return res
    end

    alias_method :[], :filter_for

  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
wice_grid-3.4.14 lib/wice/grid_output_buffer.rb
wice_grid-3.4.13 lib/wice/grid_output_buffer.rb
wice_grid-3.4.12 lib/wice/grid_output_buffer.rb
wice_grid-3.4.11 lib/wice/grid_output_buffer.rb
wice_grid-3.4.10 lib/wice/grid_output_buffer.rb
wice_grid-3.4.9 lib/wice/grid_output_buffer.rb
wice_grid-3.4.8 lib/wice/grid_output_buffer.rb
wice_grid-3.4.7 lib/wice/grid_output_buffer.rb
wice_grid-3.4.6 lib/wice/grid_output_buffer.rb
wice_grid-3.4.5 lib/wice/grid_output_buffer.rb
wice_grid-3.4.4 lib/wice/grid_output_buffer.rb
wice_grid-3.4.3 lib/wice/grid_output_buffer.rb
wice_grid-3.4.2 lib/wice/grid_output_buffer.rb
wice_grid-3.4.1 lib/wice/grid_output_buffer.rb
wice_grid-3.4.0 lib/wice/grid_output_buffer.rb
wice_grid-3.3.1 lib/wice/grid_output_buffer.rb
wice_grid-3.3.0 lib/wice/grid_output_buffer.rb
wice_grid-3.2.1 lib/grid_output_buffer.rb
wice_grid-3.2.1.pre3 lib/grid_output_buffer.rb
wice_grid-3.2.1.pre2 lib/grid_output_buffer.rb