Sha256: a4bdf71c6e0c5c95755819f5ba70d74e6052d3aeabf00654c53b5d66bebf2152

Contents?: true

Size: 1.49 KB

Versions: 2

Compression:

Stored size: 1.49 KB

Contents

require 'action_view'
require 'action_view/helpers'
require 'action_view/helpers/asset_tag_helper'
require 'flexa_lib/helpers/other_helpers'
require 'action_pack'

module TableHelper
  class Table # :nodoc:

    def boolean_column(*args, &block)
      col_options = args.extract_options!
      res = nil

      col_options[:html] = { :th => { :width => "1%",:style=>"text-align: center;" }, 
                  :td => { :style=>"text-align: center;" }}

      attr = args.shift or nil

      if block_given?
        col_options[:callback] = block
        @columns << (res = CallbackColumn.new(@template, @records, attr, col_options))
      elsif attr
        @columns << (res = BooleanColumn.new(@template, @records, attr, col_options))
      else
        raise ArgumentError, "Attribute name or block should be given"
      end
      res
    end

  end #fim da classe TABLE
  
  class BooleanColumn < Column # :nodoc:

    include ActionView::Helpers
    include FlexaLib::Helpers::OtherHelpers
    include ActionView::Helpers::AssetTagHelper
    include Sprockets::Helpers::RailsHelper
    
    attr_accessor :output_buffer
    
    def config
      Rails.application.config.action_controller if Object.const_defined?("Rails")
    end

    def content_for(record)
      #@callback = Proc.new {|n| boolean(n)}
      @callback = Proc.new {|n| flexa_boolean_grid(n)}
      @attr ? @callback.call(record.kind_of?(Hash) ? record[@attr] : record.send(@attr)) : @callback.call(record)
    end
    
  end #fim da classe BooleanColumn
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
flexa_lib-0.5.2 lib/flexa_lib/table_for_boolean_column.rb
flexa_lib-0.5.1 lib/flexa_lib/table_for_boolean_column.rb