Sha256: 62b845bf3ed88b6d5b76bad840781cc4e9ab029f87d94b218628076a022e1385

Contents?: true

Size: 1.16 KB

Versions: 7

Compression:

Stored size: 1.16 KB

Contents

class Datagrid::Columns::Column

  attr_accessor :grid, :options, :block, :name

  def initialize(grid, name, options = {}, &block)
    self.grid = grid
    self.name = name.to_sym
    self.options = options
    self.block = block
    if format
      ::Datagrid::Utils.warn_once(":format column option is deprecated. Use :url or :html option instead.")
    end
  end

  def value(model, grid)
    value_for(model, grid)
  end

  def value_for(model, grid)
    if self.block.arity == 1
      self.block.call(model)
    elsif self.block.arity == 2
      self.block.call(model, grid)
    else
      model.instance_eval(&self.block)
    end
  end

  def format
    self.options[:format]
  end

  def label
    self.options[:label]
  end

  def header
    self.options[:header] || 
      I18n.translate(self.name, :scope => "datagrid.#{self.grid.param_name}.columns", :default => self.name.to_s.humanize )
  end

  def order
    if options.has_key?(:order)
      self.options[:order]
    else
      grid.driver.default_order(grid.scope, name)
    end
  end

  def order_desc
    return nil unless order
    self.options[:order_desc]  
  end


  def html?
    !! self.options[:html]
  end
  

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
datagrid-0.6.2 lib/datagrid/columns/column.rb
datagrid-0.6.0 lib/datagrid/columns/column.rb
datagrid-0.5.4 lib/datagrid/columns/column.rb
datagrid-0.5.3 lib/datagrid/columns/column.rb
datagrid-0.5.2 lib/datagrid/columns/column.rb
datagrid-0.5.1 lib/datagrid/columns/column.rb
datagrid-0.5.0 lib/datagrid/columns/column.rb