Method: Datagrid::Columns::ClassMethods#format

Defined in:
lib/datagrid/columns.rb

#format(value, &block) ⇒ Datagrid::Columns::Column::ResponseFormat

Formats column value for HTML. Helps to distinguish formatting as plain data and HTML

Examples:

column(:name) do |model|
  format(model.name) do |value|
    tag.strong(value)
  end
end

Parameters:

  • value (Object)

    Value to be formatted

Returns:



320
321
322
323
324
325
326
327
328
329
330
331
332
333
# File 'lib/datagrid/columns.rb', line 320

def format(value, &block)
  if block_given?
    respond_to do |f|
      f.data { value }
      f.html do
        instance_exec(value, &block)
      end
    end
  else
    # Ruby Object#format exists.
    # We don't want to change the behaviour and overwrite it.
    super
  end
end