Skip to content

Commit

Permalink
Column accessors doc
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdan committed Nov 20, 2024
1 parent ebbc385 commit b9dfa71
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions lib/datagrid/columns/column.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,52 @@ class Column
class ResponseFormat
attr_accessor :data_block, :html_block

# @!visibility private
def initialize
yield(self)
end

# @!visibility private
def data(&block)
self.data_block = block
end

# @!visibility private
def html(&block)
self.html_block = block
end

# @!visibility private
def call_data
data_block.call
end

# @!visibility private
def to_s
call_data.to_s
end

# @!visibility private
def call_html(context)
context.instance_eval(&html_block)
end
end

attr_accessor :grid_class, :options, :data_block, :name, :html_block, :query
# @attribute [r] grid_class
# @return [Class] grid class where column is defined
# @attribute [r] name
# @return [Symbol] column name
# @attribute [r] options
# @return [Hash<Symbol, Object>] column options
attr_reader :grid_class, :name, :query, :options, :data_block, :html_block

# @!visibility private
def initialize(grid_class, name, query, options = {}, &block)
self.grid_class = grid_class
self.name = name.to_sym
self.options = options
@grid_class = grid_class
@name = name.to_sym
@query = query
@options = options

if options[:class]
Datagrid::Utils.warn_once(
"column[class] option is deprecated. Use {tag_options: {class: ...}} instead.",
Expand All @@ -50,13 +64,12 @@ def initialize(grid_class, name, query, options = {}, &block)
}
end
if options[:html] == true
self.html_block = block
@html_block = block
else
self.data_block = block
@data_block = block

self.html_block = options[:html] if options[:html].is_a? Proc
@html_block = options[:html] if options[:html].is_a? Proc
end
self.query = query
end

# @deprecated Use {Datagrid::Columns#data_value} instead
Expand Down

0 comments on commit b9dfa71

Please # to comment.