Skip to content

Commit 8feaa06

Browse files
committed
Update doc
1 parent cfc639a commit 8feaa06

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
@@ -196,35 +196,28 @@ def filter_by_name(attribute)
196196
# @param [Hash] options hash of options
197197
# @param [Proc] block proc to apply the filter
198198
# @return [Datagrid::Filters::BaseFilter] Filter definition object
199-
# @see https://github.com/bogdan/datagrid/wiki/Filters
200-
#
201-
# Available options:
202-
#
203-
# * <tt>:header</tt> - determines the header of the filter
204-
# * <tt>:default</tt> - the default filter value.
205-
# Able to accept a <tt>Proc</tt> in case default should be recalculated
206-
# * <tt>:range</tt> - if true, filter can accept two values
207-
# that are treated as a range that will be used for filtering
208-
# Not all of the filter types support this option. Here are the list of types that do:
209-
# <tt>:integer</tt>, <tt>:float</tt>, <tt>:date</tt>, <tt>:datetime</tt>, <tt>:string</tt>
210-
# * <tt>:multiple</tt> - if true multiple values can be assigned to this filter.
211-
# If String is assigned as a filter value, it is parsed from string using a separator symbol (`,` by default).
212-
# But you can specify a different separator as option value. Default: false.
213-
# * <tt>:allow_nil</tt> - determines if the value can be nil
214-
# * <tt>:allow_blank</tt> - determines if the value can be blank
215-
# * <tt>:before</tt> - determines the position of this filter,
216-
# by adding it before the filter passed here (when using datagrid_form_for helper)
217-
# * <tt>:after</tt> - determines the position of this filter,
218-
# by adding it after the filter passed here (when using datagrid_form_for helper)
219-
# * <tt>:dummy</tt> - if true, this filter will not be applied automatically
220-
# and will be just displayed in form. In case you may want to apply it manually.
221-
# * <tt>:if</tt> - specify the condition when the filter can be dislayed and used.
222-
# Accepts a block or a symbol with an instance method name
223-
# * <tt>:unless</tt> - specify the reverse condition when the filter can be dislayed and used.
224-
# Accepts a block or a symbol with an instance method name
225-
# * <tt>:input_options</tt> - options passed when rendering html input tag attributes.
226-
# Use <tt>input_options.type</tt> to control input type including <tt>textarea</tt>.
227-
# * <tt>:label_options</tt> - options passed when rendering html label tag attributes
199+
# @see Datagrid::Filters
200+
# @option options [String] header Determines the header of the filter.
201+
# @option options [Object, Proc] default The default filter value. Accepts a `Proc` to allow dynamic calculation.
202+
# @option options [Boolean] range Whether the filter accepts two values to define a range.
203+
# Supported by types: `:integer`, `:float`, `:date`, `:datetime`, and `:string`.
204+
# @option options [Boolean, String] multiple If true, allows multiple values for the filter.
205+
# Strings are parsed using a separator (default: `,`). Can accept a custom separator. Default: `false`.
206+
# @option options [Boolean] allow_nil Whether the filter value can be `nil`. Default: `false`.
207+
# @option options [Boolean] allow_blank Whether the filter value can be blank. Default: `false`.
208+
# @option options [Symbol] before Specifies the position of this filter by placing it before another filter.
209+
# Used with the `datagrid_form_for` helper.
210+
# @option options [Symbol] after Specifies the position of this filter by placing it after another filter.
211+
# Used with the `datagrid_form_for` helper.
212+
# @option options [Boolean] dummy If true, the filter is not applied automatically and is only displayed in the form.
213+
# Useful for manual application.
214+
# @option options [Proc, Symbol] if Specifies a condition under which the filter is displayed and used.
215+
# Accepts a block or the name of an instance method.
216+
# @option options [Proc, Symbol] unless Specifies a condition under which the filter is NOT displayed or used.
217+
# Accepts a block or the name of an instance method.
218+
# @option options [Hash] input_options Options passed to the HTML input tag for rendering attributes.
219+
# Use `input_options[:type]` to control the input type (e.g., `textarea`).
220+
# @option options [Hash] label_options Options passed to the HTML label tag for rendering attributes.
228221
def filter(name, type = :default, **options, &block)
229222
klass = type.is_a?(Class) ? type : FILTER_TYPES[type]
230223
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
@@ -268,19 +268,16 @@ def datagrid_format_value(grid, column, model)
268268
# Renders html table with columns defined in grid class.
269269
# In the most common used you need to pass paginated collection
270270
# to datagrid table because datagrid do not have pagination compatibilities:
271-
# Supported options:
272-
#
273-
# * <tt>:html</tt> - hash of attributes for <table> tag
274-
# * <tt>:order</tt> - If false do not generate ordering controlls.
275-
# Default: true.
276-
# * <tt>:columns</tt> - Array of column names to display.
277-
# Used in case when same grid class is used in different places
278-
# and needs different columns. Default: all defined columns.
279-
# * <tt>:partials</tt> - Path for partials lookup.
280-
# Default: 'datagrid'.
281271
# @param grid [Datagrid] grid object
282272
# @param assets [Array] objects from grid scope
283273
# @param [Hash{Symbol => Object}] options HTML attributes to be passed to `<table>` tag
274+
# @option options [Hash] html A hash of attributes for the `<table>` tag.
275+
# @option options [Boolean] order Whether to generate ordering controls.
276+
# If set to `false`, ordering controls are not generated. Default: `true`.
277+
# @option options [Array<Symbol>] columns An array of column names to display.
278+
# Use this when the same grid class is used in different contexts and requires different columns.
279+
# Default: all defined columns.
280+
# @option options [String] partials The path for partials lookup. Default: `'datagrid'`.
284281
# @return [String] table tag HTML markup
285282
# @example
286283
# assets = grid.assets.page(params[:page])
@@ -291,15 +288,13 @@ def datagrid_table(grid, assets = grid.assets, **options)
291288

292289
# Renders HTML table header for given grid instance using columns defined in it
293290
#
294-
# Supported options:
295-
#
296-
# * <tt>:order</tt> - display ordering controls built-in into header
297-
# Default: true
298-
# * <tt>:columns</tt> - Array of column names to display.
299-
# Used in case when same grid class is used in different places
300-
# and needs different columns. Default: all defined columns.
301-
# * <tt>:partials</tt> - Path for partials lookup.
302-
# Default: 'datagrid'.
291+
# @option options [Boolean] order Whether to display ordering controls built into the header.
292+
# Default: `true`.
293+
# @option options [Array<Symbol,String>] columns An array of column names to display.
294+
# Use this when the same grid class is used in different contexts and requires different columns.
295+
# Default: all defined columns.
296+
# @option options [String] partials The path for partials lookup.
297+
# Default: `'datagrid'`.
303298
# @param grid [Datagrid] grid object
304299
# @param [Hash] options
305300
# @return [String] HTML table header tag markup
@@ -310,19 +305,16 @@ def datagrid_header(grid, options = {})
310305
# Renders HTML table rows using given grid definition using columns defined in it.
311306
# Allows to provide a custom layout for each for in place with a block
312307
#
313-
# Supported options:
314-
#
315-
# * <tt>:columns</tt> - Array of column names to display.
316-
# Used in case when same grid class is used in different places
317-
# and needs different columns. Default: all defined columns.
318-
# * <tt>:partials</tt> - Path for partials lookup.
319-
# Default: 'datagrid'.
320-
#
308+
# @option options [Array<Symbol>] columns An array of column names to display.
309+
# Use this when the same grid class is used in different contexts and requires different columns.
310+
# Default: all defined columns.
311+
# @option options [String] partials The path for partials lookup.
312+
# Default: `'datagrid'`.
321313
# @return [String]
322-
# @example
323-
# = datagrid_rows(grid) # Generic table rows Layout
324-
#
325-
# = datagrid_rows(grid) do |row| # Custom Layout
314+
# @example Generic table rows Layout
315+
# = datagrid_rows(grid)
316+
# @example Custom Layout
317+
# = datagrid_rows(grid) do |row|
326318
# %tr
327319
# %td= row.project_name
328320
# %td.project-status{class: row.status}= row.status
@@ -331,11 +323,8 @@ def datagrid_rows(grid, assets = grid.assets, **options, &block)
331323
end
332324

333325
# @return [String] renders ordering controls for the given column name
334-
#
335-
# Supported options:
336-
#
337-
# * <tt>:partials</tt> - Path for partials lookup.
338-
# Default: 'datagrid'.
326+
# @option options [String] partials The path for partials lookup.
327+
# Default: `'datagrid'`.
339328
def datagrid_order_for(grid, column, options = {})
340329
datagrid_renderer.order_for(grid, column, options)
341330
end
@@ -361,20 +350,19 @@ def datagrid_form_for(grid, options = {})
361350
# @param block [Proc] block with Datagrid::Helper::HtmlRow as an argument returning a HTML markup as a String
362351
# @param [Hash{Symbol => Object}] options
363352
# @return [Datagrid::Helper::HtmlRow, String] captured HTML markup if block given otherwise row object
364-
# @example
365-
# # Suppose that grid has first_name and last_name columns
353+
# @example Render default layout for row
354+
# <%= datagrid_row(grid, user, columns: [:first_name, :last_name, :actions]) %>
355+
# @example Rendering custom layout for `first_name` and `last_name` columns
366356
# <%= datagrid_row(grid, user) do |row| %>
367357
# <tr>
368358
# <td><%= row.first_name %></td>
369359
# <td><%= row.last_name %></td>
370360
# </tr>
371361
# <% end %>
372-
# @example
362+
# @example Rendering custom layout passing a block
373363
# <% row = datagrid_row(grid, user) %>
374364
# First Name: <%= row.first_name %>
375365
# Last Name: <%= row.last_name %>
376-
# @example
377-
# <%= datagrid_row(grid, user, columns: [:first_name, :last_name, :actions]) %>
378366
def datagrid_row(grid, asset, **options, &block)
379367
datagrid_renderer.row(grid, asset, **options, &block)
380368
end

0 commit comments

Comments
 (0)