Sha256: 7c42fdc9027c9b86e33720b39dd7ad8186877af0df94b84ec53a5fd851eb8151

Contents?: true

Size: 1.6 KB

Versions: 9

Compression:

Stored size: 1.6 KB

Contents

# encoding: utf-8
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

    # 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)
      fail 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
          fail WiceGridException.new("No filter with Detached ID '#{detach_with_id}'!")
        end
      end

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

9 entries across 9 versions & 2 rubygems

Version Path
wice_grid_ms-3.6.2 lib/wice/grid_output_buffer.rb
wice_grid_ms-3.6.1 lib/wice/grid_output_buffer.rb
wice_grid_ms-3.6.0 lib/wice/grid_output_buffer.rb
wice_grid-3.6.0 lib/wice/grid_output_buffer.rb
wice_grid-3.6.0.pre5 lib/wice/grid_output_buffer.rb
wice_grid-3.6.0.pre4 lib/wice/grid_output_buffer.rb
wice_grid-3.6.0.pre3 lib/wice/grid_output_buffer.rb
wice_grid-3.6.0.pre2 lib/wice/grid_output_buffer.rb
wice_grid-3.6.0.pre1 lib/wice/grid_output_buffer.rb