Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed Jun 25, 2024
2 parents b360cf5 + 54cc503 commit 5b055bb
Show file tree
Hide file tree
Showing 69 changed files with 3,049 additions and 7,590 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/Code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ body:
attributes:
label: 👀 Before submitting...
options:
- label: I upgraded to pagy version 8.4.5
- label: I upgraded to pagy version 8.5.0
required: true
- label: I searched through the [Documentation](https://ddnexus.github.io/pagy/)
required: true
Expand Down
17 changes: 10 additions & 7 deletions .github/latest_release_body.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@
- The `foundation`, `materialize`, `semantic` and `uikit` CSS extras have been discontinued and will be removed in v9 (See the [details](https://github.com/ddnexus/pagy/discussions/672#discussioncomment-9212328))
- See the [CHANGELOG](https://ddnexus.github.io/pagy/changelog) for possible breaking changes

### Changes in 8.4.5
### Changes in 8.5.0

<!-- changes start -->
- Fix pluralization rule link on locale files (#716)
- Install gems in pagy CI
- Indentation changes
- Remove :cycle false default
- Fill aria_label.nav ca pluralized entry (#715) (Fixes #581)
- Fix typos (#710)
- Improve pagy playground launcher
- Refactor calendar class structure
- Remove automatic skipping of bundle install in playground apps
- Update ruby calendar test
- Update cypress calendar test
- Refactor calendar test environment to use activerecord
- Add code for calendar counts
- Remove redundant Warning
- Convert calendar.ru to calendar_rails.ru
<!-- changes end -->

[CHANGELOG](https://ddnexus.github.io/pagy/changelog)
2 changes: 1 addition & 1 deletion .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
ruby-version: '3.3'
bundler-cache: true
- name: Install bun
uses: oven-sh/setup-bun@v1
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install Dependencies
Expand Down
10 changes: 7 additions & 3 deletions .idea/runConfigurations/Calendar.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions .idea/runConfigurations/Demo.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions .idea/runConfigurations/Rails.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions .idea/runConfigurations/Repro.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ If you upgrade from version `< 8.0.0` see the following:
- `pagy-module.d.ts`: use `pagy.d.ts`
<hr>

## Version 8.5.0

- Improve pagy playground launcher
- Refactor calendar class structure
- Remove automatic skipping of bundle install in playground apps
- Update ruby calendar test
- Update cypress calendar test
- Refactor calendar test environment to use activerecord
- Add code for calendar counts
- Remove redundant Warning
- Convert calendar.ru to calendar_rails.ru

## Version 8.4.5

- Fix pluralization rule link on locale files (#716)
Expand Down
5 changes: 4 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@ group :test do
end

group :playground do
gem 'groupdate'
gem 'puma'
gem 'rackup'
gem 'rails'
gem 'rerun'
gem 'rouge'
gem 'sinatra'
gem 'sinatra-contrib'
gem 'sqlite3', '~> 1.4.0' # actierecord/sqlite3_adapter.rb constraint !!!
# activerecord/sqlite3_adapter.rb probably useless) constraint !!!
# https://github.com/rails/rails/blame/v7.1.3.4/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb#L14
gem 'sqlite3', '~> 1.4.0'
end

# group :performance do
Expand Down
19 changes: 11 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: gem
specs:
pagy (8.4.5)
pagy (8.5.0)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -80,8 +80,8 @@ GEM
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
addressable (2.8.6)
public_suffix (>= 2.0.2, < 6.0)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
ansi (1.5.0)
ast (2.4.2)
base64 (0.2.0)
Expand All @@ -102,6 +102,8 @@ GEM
rake
globalid (1.2.1)
activesupport (>= 6.1)
groupdate (6.4.0)
activesupport (>= 6.1)
http (5.2.0)
addressable (~> 2.8)
base64 (~> 0.1)
Expand Down Expand Up @@ -135,8 +137,8 @@ GEM
net-smtp
marcel (1.0.4)
mini_mime (1.1.5)
minitest (5.23.1)
minitest-reporters (1.6.1)
minitest (5.24.0)
minitest-reporters (1.7.1)
ansi
builder
minitest (>= 5.0)
Expand All @@ -145,7 +147,7 @@ GEM
mustermann (3.0.0)
ruby2_keywords (~> 0.0.1)
mutex_m (0.2.0)
net-imap (0.4.13)
net-imap (0.4.14)
date
net-protocol
net-pop (0.1.2)
Expand All @@ -167,11 +169,11 @@ GEM
racc
psych (5.1.2)
stringio
public_suffix (5.1.1)
public_suffix (6.0.0)
puma (6.4.2)
nio4r (~> 2.0)
racc (1.8.0)
rack (3.1.3)
rack (3.1.4)
rack-protection (4.0.0)
base64 (>= 0.1.0)
rack (>= 3.0.0, < 4)
Expand Down Expand Up @@ -291,6 +293,7 @@ PLATFORMS

DEPENDENCIES
activesupport
groupdate
http
i18n
minitest
Expand Down
2 changes: 1 addition & 1 deletion README.md

Large diffs are not rendered by default.

Binary file modified bun.lockb
Binary file not shown.
107 changes: 8 additions & 99 deletions docs/api/calendar.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,114 +8,23 @@ image: "none"

# Pagy::Calendar

This is a `Pagy` subclass that provides pagination filtering by time in order to support
the [Calendar extra](/docs/extras/calendar.md).
This is a `Hash` subclass that organizes and tracks the `Calendar::Units` of the calendar system. It is used internally by the [Calendar extra](/docs/extras/calendar.md) that provides the high level API and returns the `calendar` hash (an instance of this class).

!!!warning Active Support Required
It requires the `activesupport` gem, which you have to require in your Gemfile only if your app does not use Rails.
!!!

The `Pagy::Calendar` instance is a hash containing a certain number of time units objects, keyed by their unit symbol.

!!!primary Module to be used with `pagy` classes
The `Pagy::Calendar::*` subclasses provide support for the [calendar extra](/docs/extras/calendar.md) and are meant to be used
with standard, non-calendar Pagy classes and never alone (because they could generate a very high number of items per page). The
class APIs are documented here, however you should not need to use them directly because they are required and used internally by
the extra.
!!!

## Overview

The pagy `Pagy::Calendar::*` instances split a time period into pages of equal time unit. For example: with `Pagy::Calendar::Year`
you will have one page per each different calendar year so each page can be filtered to contain all the records that fall into the
specific page/year. The `Pagy::Calendar::Quarter`, `Pagy::Calendar::Month`, `Pagy::Calendar::Week` and `Pagy::Calendar::Day`
classes have the same functions for their respective time units.

Each page is also conveniently labeled in the navigation bar with the specific `Time` period it refers to.

!!!primary Natural Calendar Unit Respected
This classes respects the natural calendar units, not the duration of a unit. If you paginate by year, each page will be a
calendar year starting January 1st and ending December 31st, not a period starting and ending at two arbitrary dates one year
apart. All the classes follow the same principle. Time units with no records are displayed as empty pages.
!!!

## Variables

Being subclasses of `Pagy`, the `Pagy::Calendar::*` classes share most of their superclass infrastructure and variables, however
they use a completely different way to paginate (e.g.: no `:count` nor `:items` variables) and they have a few extra core
variables.

The following variables are specific to `Pagy::Calendar::*` instances:

| Variable | Description | Default |
|:----------|:----------------------------------------------------------------------------------------------------------|:--------|
| `:period` | Required two items Array with the calendar starting and ending local `TimeWithZone` objects | `nil` |
| `:order` | Order of pagination: it can be`:asc` or `:desc` | `:asc` |
| `:format` | String containing the `strftime` extendable format used for labelling (each subclass has its own default) | |

**Notice**: For the `Pagy::Calendar::Quarter` the `:format` variable can contain a non-standard `%q` format which is substituted
with the quarter (1-4).

## DEFAULT variables

The calendar defaults are not part of the `Pagy::DEFAULT` variables. Each subclass has its own `Pagy::Calendar::*::DEFAULT`
variable hash that you can set independently. See the pagy initializer file for details.

## Attribute Readers

| Reader | Description |
|:--------|:----------------------------------------------------------|
| `from` | The local `TimeWithZone` of the start of the current page |
| `to` | The local `TimeWithZone` of the end of the current page |
| `order` | The `:order` variable |

### About from and to objects

- The `from` is the beginning of the current time unit. Notice that for the first page it falls BEFORE the starting of
the `:period`.
- The `to` is the beginning of the next time unit. Notice that for the last page it falls AFTER the ending of the `:period`.

The cases for first and last pages have no effect when you use the `from`/`to` as a collection filter, since the collection is
already filtered by the `:period` so there are no records outside it.

### Time conversions

This classes can use the recommended `ActiveSupport::TimeWithZone` class or the ruby `Time` class for all their time calculations.
## Methods

Since they are meant to be used in the UI, they use the user/server local time in order to make sense for the UI. For that reason
their input (the `:period` variable) and output (the `from` and `to` accessors) are always local time.
=== `showtime`

If you use `ActiveRecord`, your app should set the `Time.zone` for your user or your server. Then you can convert an UTC time from
the storage to a local `TimeWithZone` object for the calendar very easily with:
This method returns the current time of the smallest time unit shown. You can store it and retrieve the same calendar at a
later time using the `pagy_calendar_url_at`

```ruby
utc_time.in_time_zone
pagy_calendar_url_at(@calendar, retrived_calendar_showtime)
```

You can also convert from local to UTC time with `local_time.utc`, however, when you use it as an argument in a
scope, `ActiveRecord` converts it for you.

### First weekday

Set the `Date.beginning_of_week` toto the symbol of the first day of the week (e.g. `Date.beginning_of_week = :sunday`). Notice
the default is `:monday` consistently with the ISO-8601 standard (and Rails).

## Methods

==- `label(opts = {})`

This method uses the `:format` variable to generate the current page label with the specific `TimeWithZone` period it refers to. It accepts an optional `:format` keyword argument for overriding.
===

==- `label_for(page, opts = {})`

This method takes a page number argument (`Integer` or `String`) and uses the `:format` variable to generate its label with the specific `Time` period it refers to. It accepts an optional `:format` keyword argument for overriding.
===

## Custom units

You can define your own custom unit of any time length. For example you may want to add a unit of 2 months (i.e. a "bimester"
unit), which should define a `Pagy::Calendar::Bimester` class.

In order to allow its full integration, you should also insert your `:bimester` unit symbol in the `Pagy::Calendar::UNITS` list,
between `:quarter` and `:month`, which will keep the list in desc order of duration.

You can also implement your own custom substitution formats for your custom units, by overriding the `label_for(page, opts)`.
2 changes: 2 additions & 0 deletions docs/api/calendar/index.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
order: -10
image: none
Loading

0 comments on commit 5b055bb

Please sign in to comment.