pagy-govuk 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9e847855109a6f48dd9d561fdd8c44d12d8f80ea6f5524009f0b23b1dd1d19a1
4
+ data.tar.gz: 36a616016d09f0b51915f55e3f9c70b154abb1b58a7c660ff3f386bc660a8054
5
+ SHA512:
6
+ metadata.gz: 8946fd6cdcd3aa0550a52948fa4d969972c2ab3951de7f7d42515942df649b730f96b674ce61d512a83e1adf43acc6755bd8b4eb722264a33c489593acdc2a71
7
+ data.tar.gz: b390d2895f138fec9b77f27ddc1b479f47055d0f1c47b6481a7b057d3e24a8d6ea697df64086d011b43bcf12c4bb16fe9cbdbb0fb9195f8e51d5314cdb95ab38
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,42 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.2
3
+ NewCops: enable
4
+ SuggestExtensions: false
5
+
6
+ Metrics/BlockLength:
7
+ Exclude:
8
+ - spec/**/*
9
+
10
+ Metrics/MethodLength:
11
+ Exclude:
12
+ - 'lib/pagy/extras/govuk.rb'
13
+ - 'spec/support/fixture_database.rb'
14
+
15
+ Style/FrozenStringLiteralComment:
16
+ Enabled: false
17
+
18
+ Style/StringLiterals:
19
+ Enabled: false
20
+
21
+ Style/StringLiteralsInInterpolation:
22
+ Enabled: true
23
+ EnforcedStyle: double_quotes
24
+ Exclude:
25
+ - 'lib/pagy/extras/govuk.rb'
26
+
27
+ Layout/LineLength:
28
+ Max: 120
29
+ Exclude:
30
+ - 'lib/pagy/extras/govuk.rb'
31
+
32
+ Layout/HashAlignment:
33
+ Exclude:
34
+ - 'lib/pagy/extras/govuk.rb'
35
+
36
+ Layout/ArgumentAlignment:
37
+ Exclude:
38
+ - 'lib/pagy/extras/govuk.rb'
39
+
40
+ Naming/MethodParameterName:
41
+ Exclude:
42
+ - 'lib/pagy/extras/govuk.rb'
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-06-26
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at rgarner@zephyros-systems.co.uk. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Russell Garner
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Pagy::GovukExtra
2
+
3
+ Provides a `pagy_govuk_nav` method that is a drop-in replacement for `pagy_nav`, using the same Pagy "extras" pattern
4
+ that already serves Bootstrap, Bulma et al
5
+
6
+ ## Installation
7
+
8
+ `gem install pagy-govuk`
9
+
10
+ ## Usage
11
+
12
+ ```ruby
13
+ # in your setup, e.g. config/initializers/pagy.rb for a Rails app
14
+ require 'pagy/extras/govuk'
15
+
16
+ # in your controller, assign a pagy instance as normal
17
+ def index
18
+ @pagy, @posts = pagy(BlogPost.all, items: 10)
19
+ end
20
+
21
+ # in your view
22
+ <%= pagy_govuk_nav(@pagy).html_safe %>
23
+ ```
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/rgarner/pagy-govuk. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/rgarner/pagy-govuk/blob/main/CODE_OF_CONDUCT.md).
34
+
35
+ ## License
36
+
37
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
38
+
39
+ ## Code of Conduct
40
+
41
+ Everyone interacting in the Pagy::Govuk project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/rgarner/pagy-govuk/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require 'rubocop/rake_task'
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,21 @@
1
+ en:
2
+ pagy:
3
+ next: |
4
+ <span class="govuk-pagination__link-title">
5
+ Next<span class="govuk-visually-hidden"> page</span>
6
+ </span>
7
+ <svg class="govuk-pagination__icon govuk-pagination__icon--next" xmlns="http://www.w3.org/2000/svg" height="13" width="15" aria-hidden="true" focusable="false" viewBox="0 0 15 13">
8
+ <path d="m8.107-0.0078125-1.4136 1.414 4.2926 4.293h-12.986v2h12.896l-4.1855 3.9766 1.377 1.4492 6.7441-6.4062-6.7246-6.7266z"></path>
9
+ </svg>
10
+ prev: |
11
+ <svg class="govuk-pagination__icon govuk-pagination__icon--prev" xmlns="http://www.w3.org/2000/svg" height="13" width="15" aria-hidden="true" focusable="false" viewBox="0 0 15 13">
12
+ <path d="m6.5938-0.0078125-6.7266 6.7266 6.7441 6.4062 1.377-1.449-4.1856-3.9768h12.896v-2h-12.984l4.2931-4.293-1.414-1.414z"></path>
13
+ </svg>
14
+ <span class="govuk-pagination__link-title">
15
+ Previous<span class="govuk-visually-hidden"> page</span>
16
+ </span>
17
+ gap: "…"
18
+ aria_label:
19
+ nav: Pagination
20
+ next: Next page
21
+ prev: Previous page
@@ -0,0 +1,67 @@
1
+ # See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/bootstrap
2
+ # frozen_string_literal: true
3
+
4
+ require 'pagy'
5
+
6
+ class Pagy # :nodoc:
7
+ # Frontend modules are specially optimized for performance.
8
+ # The resulting code may not look very elegant, but produces the best benchmarks
9
+ module GovukExtra
10
+ # Add default English translations to the I18n load_path. Copy the keys if you don't need this
11
+ def self.add_default_i18n_load_path
12
+ ::I18n.load_path << Dir[File.join(File.dirname(__FILE__), '../../../config/locales', '**', '*.{rb,yml}')]
13
+ end
14
+
15
+ # Pagination for GOV.UK adapted from Pagy's Bootstrap: it returns the html with the series of links to the pages
16
+ def pagy_govuk_nav(pagy, id: nil, classes: '', aria_label: ::I18n.t('pagy.aria_label.nav'), **vars)
17
+ id = %( id="#{id}") if id
18
+ a = pagy_anchor(pagy)
19
+
20
+ html = <<~HTML
21
+ <nav#{id} class="govuk-pagination" #{nav_aria_label(pagy, aria_label:)}>
22
+ #{govuk_prev_html(pagy, a)}
23
+ <ul class="govuk-pagination__list #{classes}">
24
+ HTML
25
+ pagy.series(**vars).each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
26
+ html << case item
27
+ when Integer
28
+ %(<li class="govuk-pagination__item">#{a.call(item,
29
+ classes: 'govuk-link govuk-pagination__link')}</li>)
30
+ when String
31
+ %(<li class="govuk-pagination__item govuk-pagination__item--current"><a role="link" class="govuk-link govuk-pagination__link" aria-current="page" aria-disabled="true">#{
32
+ pagy.label_for(item)}</a></li>)
33
+ when :gap
34
+ %(<li class="govuk-pagination__item "><a role="link" class="govuk-link govuk-pagination__link" aria-disabled="true">#{
35
+ ::I18n.t('pagy.gap')}</a></li>)
36
+ else raise InternalError,
37
+ "expected item types in series to be Integer, String or :gap; got #{item.inspect}"
38
+ end
39
+ end
40
+ html << %(</ul>#{govuk_next_html(pagy, a)}</nav>)
41
+ end
42
+
43
+ private
44
+
45
+ def govuk_prev_html(pagy, a)
46
+ if (p_prev = pagy.prev)
47
+ %(<div class="govuk-pagination__prev">#{
48
+ a.call(p_prev, ::I18n.t('pagy.prev'), classes: 'govuk-link govuk-pagination__link',
49
+ aria_label: ::I18n.t('pagy.aria_label.prev'))}</div>)
50
+ else
51
+ ''
52
+ end
53
+ end
54
+
55
+ def govuk_next_html(pagy, a)
56
+ if (p_next = pagy.next)
57
+ %(<div class="govuk-pagination__next">#{
58
+ a.call(p_next, ::I18n.t('pagy.next'), classes: 'govuk-link govuk-pagination__link',
59
+ aria_label: ::I18n.t('pagy.aria_label.next'))}</div>)
60
+ else
61
+ ''
62
+ end
63
+ end
64
+ end
65
+
66
+ Frontend.prepend GovukExtra
67
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pagy
4
+ module Govuk
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ module Pagy
2
+ module Govuk
3
+ VERSION: String
4
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+ module Pagy
2
+ module GovukExtra
3
+ def self.add_default_i18n_load_path: -> untyped
4
+
5
+ def pagy_govuk_nav: -> untyped
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pagy-govuk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Russell Garner
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-06-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pagy
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '8.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '8.5'
27
+ description: A Pagy Extra that renders GOV.UK pagination
28
+ email:
29
+ - rgarner@zephyros-systems.co.uk
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".rspec"
35
+ - ".rubocop.yml"
36
+ - CHANGELOG.md
37
+ - CODE_OF_CONDUCT.md
38
+ - LICENSE.txt
39
+ - README.md
40
+ - Rakefile
41
+ - config/locales/en.yml
42
+ - lib/pagy/extras/govuk.rb
43
+ - lib/pagy/govuk/version.rb
44
+ - sig/pagy/govuk.rbs
45
+ - sig/pagy/govuk_extra.rbs
46
+ homepage: https://github.com/rgarner/pagy-govuk
47
+ licenses:
48
+ - MIT
49
+ metadata:
50
+ allowed_push_host: https://rubygems.org
51
+ homepage_uri: https://github.com/rgarner/pagy-govuk
52
+ source_code_uri: https://github.com/rgarner/pagy-govuk
53
+ changelog_uri: https://github.com/rgarner/pagy-govuk/blob/main/CHANGELOG.md
54
+ rubygems_mfa_required: 'true'
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 3.2.0
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubygems_version: 3.5.11
71
+ signing_key:
72
+ specification_version: 4
73
+ summary: GOV.UK pagination styles for Pagy
74
+ test_files: []