Sha256: dacd66905de8d36a59826a03bf53ef2d623a67542aabc36234edada47e8d52ac

Contents?: true

Size: 1.71 KB

Versions: 5

Compression:

Stored size: 1.71 KB

Contents

module Wice
  class GridOutputBuffer < String #:nodoc:

    # defines behavior for rendering nonexistent filters.
    # If return_empty_strings_for_nonexistent_filters is true, a call to render a non existent filter will raise an exception
    # If return_empty_strings_for_nonexistent_filters is false (CSV mode), no exception will be raised.
    attr_accessor :return_empty_strings_for_nonexistent_filters

    # initializes a grid output buffer
    def initialize(*attrs)
      super(*attrs)
      @filters = HashWithIndifferentAccess.new
    end

    def inspect
      "#<Wice::GridOutputBuffer #{@filters.map{|key, filter| "#{key}: #{filter.inspect}"}.join ', '}>"
    end

    # returns HTML code the grid
    def to_s
      super.html_safe
    end

    # stores HTML code for a detached filter
    def add_filter(detach_with_id, filter_code)
      raise WiceGridException.new("Detached ID #{detach_with_id} is already used!") if @filters.key? detach_with_id
      @filters[detach_with_id] = filter_code
    end

    # returns HTML code for a detached filter
    def filter_for(detach_with_id)
      unless @filters.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

      unless @filters[detach_with_id]
        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
      res
    end

    # returns HTML code for a detached filter
    alias_method :[], :filter_for
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
wice_grid-7.1.4 lib/wice/grid_output_buffer.rb
wice_grid-7.1.3 lib/wice/grid_output_buffer.rb
wice_grid-7.1.2 lib/wice/grid_output_buffer.rb
wice_grid-7.1.1 lib/wice/grid_output_buffer.rb
wice_grid-7.1.0 lib/wice/grid_output_buffer.rb