Module: Datagrid::Columns::ClassMethods
- Defined in:
- lib/datagrid/columns.rb
Instance Method Summary collapse
-
#column(name, query = nil, **options, &block) ⇒ Datagrid::Columns::Column
Defines a new datagrid column.
-
#column_by_name(name) ⇒ Datagrid::Columns::Column?
Returns column definition with given name.
-
#column_names ⇒ Array<Datagrid::Columns::Column>
Returns an array of all defined column names.
-
#columns(*column_names, data: false, html: false) ⇒ Array<Datagrid::Columns::Column>
Column definition objects.
-
#decorate(model = nil, &block) ⇒ void
Defines a model decorator that will be used to define a column value.
-
#format(value, &block) ⇒ Datagrid::Columns::Column::ResponseFormat
Formats column value for HTML.
Instance Method Details
#column(name, query = nil, **options, &block) ⇒ Datagrid::Columns::Column
Defines a new datagrid column
279 280 281 |
# File 'lib/datagrid/columns.rb', line 279 def column(name, query = nil, **, &block) define_column(columns_array, name, query, **, &block) end |
#column_by_name(name) ⇒ Datagrid::Columns::Column?
Returns column definition with given name
285 286 287 |
# File 'lib/datagrid/columns.rb', line 285 def column_by_name(name) find_column_by_name(columns_array, name) end |
#column_names ⇒ Array<Datagrid::Columns::Column>
Returns an array of all defined column names
291 292 293 |
# File 'lib/datagrid/columns.rb', line 291 def column_names columns.map(&:name) end |
#columns(*column_names, data: false, html: false) ⇒ Array<Datagrid::Columns::Column>
Returns column definition objects.
250 251 252 |
# File 'lib/datagrid/columns.rb', line 250 def columns(*column_names, data: false, html: false) filter_columns(columns_array, *column_names, data: data, html: html) end |
#decorate(model = nil, &block) ⇒ void
This method returns an undefined value.
Defines a model decorator that will be used to define a column value. All column blocks will be given a decorated version of the model.
332 333 334 335 336 337 338 339 340 341 342 |
# File 'lib/datagrid/columns.rb', line 332 def decorate(model = nil, &block) if !model && !block raise ArgumentError, "decorate needs either a block to define decoration or a model to decorate" end return self.decorator = block unless model return model unless decorator presenter = ::Datagrid::Utils.apply_args(model, &decorator) presenter = presenter.new(model) if presenter.is_a?(Class) block_given? ? yield(presenter) : presenter end |
#format(value, &block) ⇒ Datagrid::Columns::Column::ResponseFormat
Formats column value for HTML. Helps to distinguish formatting as plain data and HTML
310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
# File 'lib/datagrid/columns.rb', line 310 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 |