Skip to content

Commit 524f59d

Browse files
committed
Add comment for the calendar usage. Close #827.
1 parent 037e7f1 commit 524f59d

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

docs/toolbox/paginators/calendar.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ It enables cascade-filtering of the collection by time units _(year, quarter, mo
3939
- The `:year` and `:month` parameters create time unit objects (default options are used in this example).
4040
- `:offset` is the offset instance that paginates the time-filtered collection.
4141

42-
==- Example Usage
42+
==- Usage
4343

44-
You must define a few simple methods in your app to configure and coordinate the objects created by the `pagy` method.
44+
You must define a few simple methods in your app to configure and coordinate the objects created by the `pagy` method. Se the following examples and comments (adapted from the [Calendar app code](../../sandbox/playground.md/#calendar-app))
4545

4646
```ruby Controller
4747
# Note: All time values must be instances of ActiveSupport::TimeWithZone.
@@ -61,6 +61,7 @@ end
6161
# If this method is defined, pagy will add an extra 'empty-page' CSS class
6262
# to the links leading to empty pages, along with a title attribute containing information about each page link.
6363
def pagy_calendar_counts(collection, unit, from, to)
64+
# If collection is in order: :desc, add the reverse: true option to the next line
6465
collection.group_by_period(unit, :created_at, range: from...to).count.values
6566
end
6667

gem/apps/calendar.ru

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ class PagyCalendar < Sinatra::Base
6868
def pagy_calendar_counts(collection, unit, from, to)
6969
# The group_by_period method is provided by the groupdate gem
7070
# We use the :skip_counts param for testing the output in cypress
71+
# If collection is in order: :desc, add the reverse: true option to the next line
7172
collection.group_by_period(unit, :time, range: from...to).count.values \
72-
unless params[:skip_counts] == 'true'
73+
unless params[:skip_counts] == 'true'
7374
end
7475

7576
# Root route/action

0 commit comments

Comments
 (0)