Skip to content

Commit 89d456c

Browse files
committed
Merge branch 'main' into version-2
2 parents a26aa1a + 0229b35 commit 89d456c

File tree

7 files changed

+87
-89
lines changed

7 files changed

+87
-89
lines changed

.document

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
1-
lib/**/*.rb
21
bin/*
3-
-
4-
features/**/*.feature
5-
LICENSE.txt
2+
lib/**/*.rb

.yardopts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--markup=markdown
2+
--readme=README.md

lib/datagrid.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ def self.included(base)
1919
end
2020
end
2121

22+
def self.configuration
23+
@configuration ||= Configuration.new
24+
end
25+
26+
# Configure
27+
def self.configure(&block)
28+
block.call(configuration)
29+
end
30+
2231
class ConfigurationError < StandardError; end
2332
class ArgumentError < ::ArgumentError; end
2433
class ColumnUnavailableError < StandardError; end

lib/datagrid/columns.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ module Datagrid
3939
# # ]
4040
# }
4141
#
42-
# == Column Value
42+
# ## Column Value
4343
#
4444
# The value of a column can be defined by passing a block to `Datagrid.column`.
4545
#
46-
# === Basic Column Value
46+
# ### Basic Column Value
4747
#
4848
# If no block is provided, the column value is generated automatically by sending the column name method to the model.
4949
#
@@ -57,7 +57,7 @@ module Datagrid
5757
#
5858
# column(:completed) { |asset| asset.completed? }
5959
#
60-
# === Advanced Column Value
60+
# ### Advanced Column Value
6161
#
6262
# You can also pass the Datagrid object itself to define more complex column values.
6363
#
@@ -83,14 +83,14 @@ module Datagrid
8383
# row.total_sales / row.number_of_sales
8484
# end
8585
#
86-
# == Using Database Expressions
86+
# ## Using Database Expressions
8787
#
8888
# Columns can use database expressions to directly manipulate data in the database.
8989
#
9090
# column(:count_of_users, 'count(user_id)')
9191
# column(:uppercase_name, 'upper(name)')
9292
#
93-
# == HTML Columns
93+
# ## HTML Columns
9494
#
9595
# Columns can have different formats for HTML and non-HTML representations.
9696
#
@@ -100,13 +100,13 @@ module Datagrid
100100
# end
101101
# end
102102
#
103-
# == Column Value Cache
103+
# ## Column Value Cache
104104
#
105105
# Enables grid-level caching for column values.
106106
#
107107
# self.cached = true
108108
#
109-
# == Ordering
109+
# ## Ordering
110110
#
111111
# Columns can specify SQL ordering expressions using the `:order` and `:order_desc` options.
112112
#
@@ -148,19 +148,19 @@ module Datagrid
148148
# Time.at(model.finished_at - model.accepted_at).strftime("%H:%M:%S")
149149
# end
150150
#
151-
# == Default Column Options
151+
# ## Default Column Options
152152
#
153153
# Default options for all columns in a grid can be set using `default_column_options`.
154154
#
155155
# self.default_column_options = { order: false }
156156
#
157-
# == Columns Visibility
157+
# ## Columns Visibility
158158
#
159159
# Columns can be dynamically shown or hidden based on the grid's `column_names` accessor.
160160
#
161161
# grid.column_names = [:id, :name]
162162
#
163-
# == Dynamic Columns
163+
# ## Dynamic Columns
164164
#
165165
# Columns can be defined dynamically on a grid instance or based on data.
166166
#
@@ -170,13 +170,13 @@ module Datagrid
170170
# model.extra_data
171171
# end
172172
#
173-
# == Localization
173+
# ## Localization
174174
#
175175
# Column headers can be localized using the `:header` option or through i18n files.
176176
#
177177
# column(:active, header: Proc.new { I18n.t("activated") })
178178
#
179-
# == Preloading Associations
179+
# ## Preloading Associations
180180
#
181181
# Preload database associations for better performance.
182182
#
@@ -190,7 +190,7 @@ module Datagrid
190190
#
191191
# column(:account_name, preload: { |s| s.includes(:account) })
192192
#
193-
# == Decorator
193+
# ## Decorator
194194
#
195195
# A decorator or presenter class can be used around each object in the `scope`.
196196
#

lib/datagrid/configuration.rb

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,25 @@
11
# frozen_string_literal: true
22

33
module Datagrid
4-
def self.configuration
5-
@configuration ||= Configuration.new
6-
end
7-
8-
def self.configure
9-
yield(configuration)
10-
end
11-
12-
# == Configuration
4+
# ## Configuration
135
#
146
# Datagrid provides several configuration options.
157
#
168
# Here is the API reference and a description of the available options:
179
#
18-
# Datagrid.configure do |config|
19-
#
20-
# # Defines date formats that can be used to parse dates.
21-
# # Note: Multiple formats can be specified. The first format is used to format dates as strings,
22-
# # while other formats are used only for parsing dates from strings (e.g., if your app supports multiple formats).
23-
# config.date_formats = ["%m/%d/%Y", "%Y-%m-%d"]
24-
#
25-
# # Defines timestamp formats that can be used to parse timestamps.
26-
# # Note: Multiple formats can be specified. The first format is used to format timestamps as strings,
27-
# # while other formats are used only for parsing timestamps from strings (e.g., if your app supports multiple formats).
28-
# config.datetime_formats = ["%m/%d/%Y %h:%M", "%Y-%m-%d %h:%M:%s"]
10+
# ``` ruby
11+
# Datagrid.configure do |config|
12+
# # Defines date formats that can be used to parse dates.
13+
# # Note: Multiple formats can be specified. The first format is used to format dates as strings,
14+
# # while other formats are used only for parsing dates from strings (e.g., if your app supports multiple formats).
15+
# config.date_formats = ["%m/%d/%Y", "%Y-%m-%d"]
2916
#
30-
# end
17+
# # Defines timestamp formats that can be used to parse timestamps.
18+
# # Note: Multiple formats can be specified. The first format is used to format timestamps as strings,
19+
# # while other formats are used only for parsing timestamps from strings (e.g., if your app supports multiple formats).
20+
# config.datetime_formats = ["%m/%d/%Y %h:%M", "%Y-%m-%d %h:%M:%s"]
21+
# end
22+
# ```
3123
#
3224
# These options can be set globally in your application to customize Datagrid’s behavior.
3325
class Configuration

lib/datagrid/filters.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module Datagrid
2424
# grid = UserGrid.new(posts_count: 1, name: "John")
2525
# grid.assets # SELECT * FROM users WHERE users.posts_count > 1 AND name = 'John'
2626
#
27-
# = Filter Block
27+
# # Filter Block
2828
#
2929
# Filter blocks should always return a chainable ORM object (e.g., `ActiveRecord::Relation`) rather than an `Array`.
3030
#
@@ -39,7 +39,7 @@ module Datagrid
3939
# scope.where("name #{grid.predicate} ?", "%#{value}%")
4040
# end
4141
#
42-
# = Filter Types
42+
# # Filter Types
4343
#
4444
# Filters perform automatic type conversion. Supported filter types include:
4545
#
@@ -54,52 +54,52 @@ module Datagrid
5454
# - `string`
5555
# - `dynamic`
5656
#
57-
# == Default
57+
# ## Default
5858
#
5959
# `:default` - Leaves the value as is.
6060
#
61-
# == Date
61+
# ## Date
6262
#
6363
# `:date` - Converts value to a date. Supports the `:range` option to accept date ranges.
6464
#
6565
# filter(:created_at, :date, range: true, default: proc { 1.month.ago.to_date..Date.today })
6666
#
67-
# == Datetime
67+
# ## Datetime
6868
#
6969
# `:datetime` - Converts value to a timestamp. Supports the `:range` option to accept time ranges.
7070
#
7171
# filter(:created_at, :datetime, range: true, default: proc { 1.hour.ago..Time.now })
7272
#
73-
# == Enum
73+
# ## Enum
7474
#
7575
# `:enum` - For collection selection with options like `:select` and `:multiple`.
7676
#
7777
# filter(:user_type, :enum, select: ['Admin', 'Customer', 'Manager'])
7878
# filter(:category_id, :enum, select: proc { Category.all.map { |c| [c.name, c.id] } }, multiple: true)
7979
#
80-
# == Boolean
80+
# ## Boolean
8181
#
8282
# `:boolean` - Converts value to `true` or `false`.
8383
#
84-
# == Xboolean
84+
# ## Xboolean
8585
#
8686
# `:xboolean` - Subtype of `enum` filter that provides "Yes", "No", and "Any" options.
8787
#
8888
# filter(:active, :xboolean)
8989
#
90-
# == Integer
90+
# ## Integer
9191
#
9292
# `:integer` - Converts value to an integer. Supports the `:range` option.
9393
#
9494
# filter(:posts_count, :integer, range: true, default: (1..nil))
9595
#
96-
# == String
96+
# ## String
9797
#
9898
# `:string` - Converts value to a string.
9999
#
100100
# filter(:email, :string)
101101
#
102-
# == Dynamic
102+
# ## Dynamic
103103
#
104104
# Provides a builder for dynamic SQL conditions.
105105
#
@@ -108,7 +108,7 @@ module Datagrid
108108
# UsersGrid.new(condition1: [:name, "=~", "John"], condition2: [:posts_count, ">=", 1])
109109
# UsersGrid.assets # SELECT * FROM users WHERE name like '%John%' and posts_count >= 1
110110
#
111-
# = Filter Options
111+
# # Filter Options
112112
#
113113
# Options that can be passed to any filter:
114114
#
@@ -123,7 +123,7 @@ module Datagrid
123123
# filter(:id, :integer, header: "Identifier")
124124
# filter(:created_at, :date, range: true, default: proc { 1.month.ago.to_date..Date.today })
125125
#
126-
# = Localization
126+
# # Localization
127127
#
128128
# Filter labels can be localized or specified via the `:header` option:
129129
#

0 commit comments

Comments
 (0)