Skip to content

Commit 33fe700

Browse files
committed
Merge branch 'main' into version-2
2 parents ab40c07 + 8feaa06 commit 33fe700

File tree

2 files changed

+51
-70
lines changed

2 files changed

+51
-70
lines changed

lib/datagrid/filters.rb

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -192,35 +192,28 @@ def filter_by_name(attribute)
192192
# @param [Hash] options hash of options
193193
# @param [Proc] block proc to apply the filter
194194
# @return [Datagrid::Filters::BaseFilter] Filter definition object
195-
# @see https://github.com/bogdan/datagrid/wiki/Filters
196-
#
197-
# Available options:
198-
#
199-
# * <tt>:header</tt> - determines the header of the filter
200-
# * <tt>:default</tt> - the default filter value.
201-
# Can be a <tt>Proc</tt> in case default should be recalculated.
202-
# * <tt>:range</tt> - if true, filter can accept two values that are treated
203-
# as a range that will be used for filtering.
204-
# Not all of the filter types support this option. Here are the list of types that do:
205-
# <tt>:integer</tt>, <tt>:float</tt>, <tt>:date</tt>, <tt>:datetime</tt>, <tt>:string</tt>
206-
# * <tt>:multiple</tt> - if true multiple values can be assigned to this filter.
207-
# If String is assigned as a filter value, it is parsed from string using a separator symbol (`,` by default).
208-
# But you can specify a different separator as option value. Default: false.
209-
# * <tt>:allow_nil</tt> - determines if the value can be nil
210-
# * <tt>:allow_blank</tt> - determines if the value can be blank
211-
# * <tt>:before</tt> - determines the position of this filter,
212-
# by adding it before the filter passed here (when using datagrid_form_with helper)
213-
# * <tt>:after</tt> - determines the position of this filter,
214-
# by adding it after the filter passed here (when using datagrid_form_with helper)
215-
# * <tt>:dummy</tt> - if true, this filter will not be applied automatically
216-
# and will be just displayed in form. In case you may want to apply it manually.
217-
# * <tt>:if</tt> - specify the condition when the filter can be dislayed and used.
218-
# Accepts a block or a symbol with an instance method name
219-
# * <tt>:unless</tt> - specify the reverse condition when the filter can be dislayed and used.
220-
# Accepts a block or a symbol with an instance method name
221-
# * <tt>:input_options</tt> - options passed when rendering html input tag attributes.
222-
# Use <tt>input_options.type</tt> to control input type including <tt>textarea</tt>.
223-
# * <tt>:label_options</tt> - options passed when rendering html label tag attributes
195+
# @see Datagrid::Filters
196+
# @option options [String] header Determines the header of the filter.
197+
# @option options [Object, Proc] default The default filter value. Accepts a `Proc` to allow dynamic calculation.
198+
# @option options [Boolean] range Whether the filter accepts two values to define a range.
199+
# Supported by types: `:integer`, `:float`, `:date`, `:datetime`, and `:string`.
200+
# @option options [Boolean, String] multiple If true, allows multiple values for the filter.
201+
# Strings are parsed using a separator (default: `,`). Can accept a custom separator. Default: `false`.
202+
# @option options [Boolean] allow_nil Whether the filter value can be `nil`. Default: `false`.
203+
# @option options [Boolean] allow_blank Whether the filter value can be blank. Default: `false`.
204+
# @option options [Symbol] before Specifies the position of this filter by placing it before another filter.
205+
# Used with the `datagrid_form_for` helper.
206+
# @option options [Symbol] after Specifies the position of this filter by placing it after another filter.
207+
# Used with the `datagrid_form_for` helper.
208+
# @option options [Boolean] dummy If true, the filter is not applied automatically and is only displayed in the form.
209+
# Useful for manual application.
210+
# @option options [Proc, Symbol] if Specifies a condition under which the filter is displayed and used.
211+
# Accepts a block or the name of an instance method.
212+
# @option options [Proc, Symbol] unless Specifies a condition under which the filter is NOT displayed or used.
213+
# Accepts a block or the name of an instance method.
214+
# @option options [Hash] input_options Options passed to the HTML input tag for rendering attributes.
215+
# Use `input_options[:type]` to control the input type (e.g., `textarea`).
216+
# @option options [Hash] label_options Options passed to the HTML label tag for rendering attributes.
224217
def filter(name, type = :default, **options, &block)
225218
klass = type.is_a?(Class) ? type : FILTER_TYPES[type]
226219
raise ConfigurationError, "filter class #{type.inspect} not found" unless klass

lib/datagrid/helper.rb

Lines changed: 29 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -264,19 +264,16 @@ def datagrid_format_value(grid, column, model)
264264
# Renders html table with columns defined in grid class.
265265
# In the most common used you need to pass paginated collection
266266
# to datagrid table because datagrid do not have pagination compatibilities:
267-
# Supported options:
268-
#
269-
# * <tt>:html</tt> - hash of attributes for <table> tag
270-
# * <tt>:order</tt> - If false do not generate ordering controlls.
271-
# Default: true.
272-
# * <tt>:columns</tt> - Array of column names to display.
273-
# Used in case when same grid class is used in different places
274-
# and needs different columns. Default: all defined columns.
275-
# * <tt>:partials</tt> - Path for partials lookup.
276-
# Default: 'datagrid'.
277267
# @param grid [Datagrid] grid object
278268
# @param assets [Array] objects from grid scope
279269
# @param [Hash{Symbol => Object}] options HTML attributes to be passed to `<table>` tag
270+
# @option options [Hash] html A hash of attributes for the `<table>` tag.
271+
# @option options [Boolean] order Whether to generate ordering controls.
272+
# If set to `false`, ordering controls are not generated. Default: `true`.
273+
# @option options [Array<Symbol>] columns An array of column names to display.
274+
# Use this when the same grid class is used in different contexts and requires different columns.
275+
# Default: all defined columns.
276+
# @option options [String] partials The path for partials lookup. Default: `'datagrid'`.
280277
# @return [String] table tag HTML markup
281278
# @example
282279
# assets = grid.assets.page(params[:page])
@@ -294,15 +291,13 @@ def datagrid_table(grid, assets = grid.assets, **options)
294291

295292
# Renders HTML table header for given grid instance using columns defined in it
296293
#
297-
# Supported options:
298-
#
299-
# * <tt>:order</tt> - display ordering controls built-in into header
300-
# Default: true
301-
# * <tt>:columns</tt> - Array of column names to display.
302-
# Used in case when same grid class is used in different places
303-
# and needs different columns. Default: all defined columns.
304-
# * <tt>:partials</tt> - Path for partials lookup.
305-
# Default: 'datagrid'.
294+
# @option options [Boolean] order Whether to display ordering controls built into the header.
295+
# Default: `true`.
296+
# @option options [Array<Symbol,String>] columns An array of column names to display.
297+
# Use this when the same grid class is used in different contexts and requires different columns.
298+
# Default: all defined columns.
299+
# @option options [String] partials The path for partials lookup.
300+
# Default: `'datagrid'`.
306301
# @param grid [Datagrid] grid object
307302
# @param [Object] opts (deprecated) pass keyword arguments instead
308303
# @param [Hash] options
@@ -321,19 +316,16 @@ def datagrid_header(grid, opts = :__unspecified__, **options)
321316
# Renders HTML table rows using given grid definition using columns defined in it.
322317
# Allows to provide a custom layout for each for in place with a block
323318
#
324-
# Supported options:
325-
#
326-
# * <tt>:columns</tt> - Array of column names to display.
327-
# Used in case when same grid class is used in different places
328-
# and needs different columns. Default: all defined columns.
329-
# * <tt>:partials</tt> - Path for partials lookup.
330-
# Default: 'datagrid'.
331-
#
319+
# @option options [Array<Symbol>] columns An array of column names to display.
320+
# Use this when the same grid class is used in different contexts and requires different columns.
321+
# Default: all defined columns.
322+
# @option options [String] partials The path for partials lookup.
323+
# Default: `'datagrid'`.
332324
# @return [String]
333-
# @example
334-
# = datagrid_rows(grid) # Generic table rows Layout
335-
#
336-
# = datagrid_rows(grid) do |row| # Custom Layout
325+
# @example Generic table rows Layout
326+
# = datagrid_rows(grid)
327+
# @example Custom Layout
328+
# = datagrid_rows(grid) do |row|
337329
# %tr
338330
# %td= row.project_name
339331
# %td.project-status{class: row.status}= row.status
@@ -346,11 +338,8 @@ def datagrid_rows(grid, assets = grid.assets, **options, &block)
346338
end
347339

348340
# @return [String] renders ordering controls for the given column name
349-
#
350-
# Supported options:
351-
#
352-
# * <tt>:partials</tt> - Path for partials lookup.
353-
# Default: 'datagrid'.
341+
# @option options [String] partials The path for partials lookup.
342+
# Default: `'datagrid'`.
354343
def datagrid_order_for(grid, column, options = {})
355344
Datagrid::Utils.warn_once(<<~MSG)
356345
datagrid_order_for is deprecated.
@@ -414,20 +403,19 @@ def datagrid_form_for(grid, options = {})
414403
# @param block [Proc] block with Datagrid::Helper::HtmlRow as an argument returning a HTML markup as a String
415404
# @param [Hash{Symbol => Object}] options
416405
# @return [Datagrid::Helper::HtmlRow, String] captured HTML markup if block given otherwise row object
417-
# @example
418-
# # Suppose that grid has first_name and last_name columns
406+
# @example Render default layout for row
407+
# <%= datagrid_row(grid, user, columns: [:first_name, :last_name, :actions]) %>
408+
# @example Rendering custom layout for `first_name` and `last_name` columns
419409
# <%= datagrid_row(grid, user) do |row| %>
420410
# <tr>
421411
# <td><%= row.first_name %></td>
422412
# <td><%= row.last_name %></td>
423413
# </tr>
424414
# <% end %>
425-
# @example
415+
# @example Rendering custom layout passing a block
426416
# <% row = datagrid_row(grid, user) %>
427417
# First Name: <%= row.first_name %>
428418
# Last Name: <%= row.last_name %>
429-
# @example
430-
# <%= datagrid_row(grid, user, columns: [:first_name, :last_name, :actions]) %>
431419
def datagrid_row(grid, asset, **options, &block)
432420
Datagrid::Helper::HtmlRow.new(self, grid, asset, options).tap do |row|
433421
return capture(row, &block) if block_given?

0 commit comments

Comments
 (0)