dsfr_accessible_skip_links 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 463e7169b07cd041b6e60fd1590f865dae3dd3589df63adaff28e3005f504a7a
4
- data.tar.gz: d660e5cb0f9cdd34e58c4db423e5f6a1ae3f6c6749dd7ea57a3e6afbbbdf96ef
3
+ metadata.gz: 1c1aa834669fc2810bad9ffe69cad4af0d1640ea1b294d514c755b72e80cea81
4
+ data.tar.gz: 57a4ffa98aa9217fd8937a137df89a810ddf04fbda942e5b1736baabbf5c3911
5
5
  SHA512:
6
- metadata.gz: 6a7b721500e9d5e31b190a9e53c2ff232f9f8d722780f10c65543fe23063e9e5e549aa2c2f0233035441c30ca5b4d4573004496b4ddf091ddba0d2819cc445d0
7
- data.tar.gz: a50f6bedb857566c476cf7cd913c17f411f6bb2f384714530b6e629b4b8abcce7443f731ac224eb349ab12507acd6959259269aa1c8a9bc59bc4ab75e26b45d5
6
+ metadata.gz: b2fa2f71d3ed56fe3dbbc9966e57ff9743a2bdc360a16fb17574396fcbb978d1659abfd5e865e5c2addb95a69dd350b9b39e9bc681a852598a2245b9a276ebd5
7
+ data.tar.gz: d4ca7582ffe46826b82801d41f673b29cbae349e01be2d0c77f54450d09f1e0ad957440b74fc0f5128b64c2ecdf2549d550ddb1eb0e631474b944f4921dfaffb
data/CHANGELOG.md CHANGED
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.1.3] - 2025-08-27
11
+ ### Fixed
12
+ - Generator now uses `copy_file` instead of `template` to avoid evaluating ERB in the partial during generation. This prevents `NameError` for `skip_links_content`.
13
+ - Ensure DsfrAccessibleSkipLinks::SkipLinks is automatically included using `ActiveSupport.on_load` hooks:
14
+ - Included into `ActionController::Base` (controller-side) and exposed as view helpers
15
+ - Included into `ActionView` (view-side) so helpers are available in templates without manual setup
16
+
17
+ ## [0.1.2] - 2025-08-27
18
+ ### Added
19
+ - Rails generator `dsfr_accessible_skip_links:install` to copy the skip links partial and inject the render call into the application layout.
20
+ - README updated with installation instructions using the generator.
21
+
10
22
  ## [0.1.0] - 2025-08-27
11
23
 
12
24
  ### Added
@@ -14,4 +26,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
14
26
  - Skip links helper methods for Rails applications
15
27
  - DSFR-compliant CSS classes and HTML structure
16
28
  - Configuration system for customizing default behavior
17
- - Accessibility features following WCAG 2.2 guidelines
29
+ - Accessibility features following WCAG 2.2 guidelines
data/README.md CHANGED
@@ -10,11 +10,15 @@ Add this line to your application's Gemfile:
10
10
  gem 'dsfr_accessible_skip_links'
11
11
  ```
12
12
 
13
- And then execute:
13
+ Then install the gem:
14
14
 
15
15
  $ bundle install
16
16
 
17
- Or install it yourself as:
17
+ Run the installer to set up the skip links in your Rails app (copies the partial and injects the render in your layout):
18
+
19
+ $ bin/rails g dsfr_accessible_skip_links:install
20
+
21
+ You can also install the gem itself directly as:
18
22
 
19
23
  $ gem install dsfr_accessible_skip_links
20
24
 
@@ -22,7 +26,7 @@ Or install it yourself as:
22
26
 
23
27
  ### Rails Integration
24
28
 
25
- The gem automatically integrates with Rails through a Rails Engine. The `SkipLinks` module is automatically included in `ApplicationController`.
29
+ The gem automatically integrates with Rails through a Rails Engine. The `SkipLinks` module is automatically included in controllers and views (via Rails on_load hooks), so you can call the helpers directly from templates and controllers.
26
30
 
27
31
  In your layout file (e.g., `app/views/layouts/application.html.erb`), add the skip links at the top:
28
32
 
@@ -131,6 +135,69 @@ This gem implements skip links following WCAG 2.2 guidelines and DSFR specificat
131
135
  - Focus management
132
136
  - Compatible with DSFR CSS for visual styling
133
137
 
138
+ ## How to test this gem
139
+
140
+ There are two main ways to test this gem:
141
+
142
+ 1) Run the gem's test suite locally (fast, no Rails app needed)
143
+ - Install dependencies:
144
+ ```bash
145
+ bundle install
146
+ ```
147
+ - Run RSpec:
148
+ ```bash
149
+ bundle exec rake spec
150
+ ```
151
+ - Run RuboCop:
152
+ ```bash
153
+ bundle exec rake rubocop
154
+ ```
155
+ - Run both (default task):
156
+ ```bash
157
+ bundle exec rake
158
+ ```
159
+
160
+ 2) Try it inside a real Rails app (to test the generator and integration)
161
+ - Create a new Rails app (or use an existing one):
162
+ ```bash
163
+ rails new demo_app --skip-javascript --skip-hotwire --skip-action-mailbox --skip-action-text --skip-active-storage --skip-active-job --skip-system-test
164
+ cd demo_app
165
+ ```
166
+ - Point the app to your local copy of this gem. In demo_app/Gemfile add:
167
+ ```ruby
168
+ gem 'dsfr_accessible_skip_links', path: '../path/to/your/dsfr_accessible_skip_links'
169
+ ```
170
+ Then run:
171
+ ```bash
172
+ bundle install
173
+ ```
174
+ - Run the installer (copies the partial and injects a render line into your layout):
175
+ ```bash
176
+ bin/rails g dsfr_accessible_skip_links:install
177
+ ```
178
+ - Verify changes:
179
+ - The partial should exist at: app/views/shared/_skip_links.html.erb
180
+ - Your app layout (app/views/layouts/application.html.erb) should include:
181
+ ```erb
182
+ <%= render partial: 'shared/skip_links' %>
183
+ ```
184
+ - Ensure your layout has the anchor targets used by default links:
185
+ ```erb
186
+ <header id="header"></header>
187
+ <main id="content"><%= yield %></main>
188
+ <footer id="footer"></footer>
189
+ ```
190
+ - Start the server and check the skip links at the top of the page:
191
+ ```bash
192
+ bin/rails s
193
+ ```
194
+ Visit http://localhost:3000 and look for the skip links markup
195
+ ("Aller au contenu", "Menu", "Pied de page").
196
+
197
+ Notes
198
+ - The generator is idempotent: it won’t insert the render line twice if it already exists.
199
+ - You can customize the skip links in any view using `content_for :skip_links` as described below in Usage.
200
+
134
201
  ## Development
135
202
 
136
203
  After checking out the repo, run `bundle install` to install dependencies.
@@ -14,8 +14,16 @@ module DsfrAccessibleSkipLinks
14
14
  end
15
15
  end
16
16
 
17
- config.to_prepare do
18
- ApplicationController.include(DsfrAccessibleSkipLinks::SkipLinks) if defined?(ApplicationController)
17
+ # Ensure helpers are available automatically in controllers and views
18
+ initializer "dsfr_accessible_skip_links.helpers" do
19
+ ActiveSupport.on_load(:action_controller_base) do
20
+ include DsfrAccessibleSkipLinks::SkipLinks
21
+ helper DsfrAccessibleSkipLinks::SkipLinks if respond_to?(:helper)
22
+ end
23
+
24
+ ActiveSupport.on_load(:action_view) do
25
+ include DsfrAccessibleSkipLinks::SkipLinks
26
+ end
19
27
  end
20
28
  end
21
29
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DsfrAccessibleSkipLinks
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.3"
5
5
  end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators"
4
+
5
+ module DsfrAccessibleSkipLinks
6
+ module Generators
7
+ class InstallGenerator < Rails::Generators::Base
8
+ source_root File.expand_path("templates", __dir__)
9
+
10
+ desc(
11
+ "Installs DsfrAccessibleSkipLinks by copying the skip links partial " \
12
+ "and injecting the render call into the application layout."
13
+ )
14
+ def copy_partial
15
+ # Use copy_file instead of template to avoid evaluating ERB in the generator context
16
+ copy_file "_skip_links.html.erb", "app/views/shared/_skip_links.html.erb"
17
+ end
18
+
19
+ # rubocop:disable Metrics/MethodLength
20
+ def inject_into_layout
21
+ layout_path = "app/views/layouts/application.html.erb"
22
+ return unless File.exist?(layout_path)
23
+
24
+ render_snippet = " <%= render partial: 'shared/skip_links' %>\n"
25
+
26
+ content = File.read(layout_path)
27
+ if content.include?("render partial: 'shared/skip_links'") || content.include?("render 'shared/skip_links'")
28
+ return
29
+ end
30
+
31
+ if content =~ /<body[^>]*>/
32
+ insert_into_file layout_path, after: /<body[^>]*>\s*\n?/ do
33
+ render_snippet
34
+ end
35
+ else
36
+ # If <body> tag is not found, append at the beginning of the file as a fallback
37
+ prepend_to_file layout_path, render_snippet
38
+ end
39
+ end
40
+ # rubocop:enable Metrics/MethodLength
41
+
42
+ def readme
43
+ say <<~MSG
44
+ DsfrAccessibleSkipLinks installed.
45
+
46
+ - A copy of the skip links partial has been placed at app/views/shared/_skip_links.html.erb
47
+ - Your application layout has been updated to render the skip links.
48
+
49
+ Ensure your layout contains elements with ids: #header, #content, and #footer for the default links.
50
+ MSG
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,7 @@
1
+ <div class="fr-skiplinks">
2
+ <nav class="fr-container" role="navigation" aria-label="Accès rapide">
3
+ <ul class="fr-skiplinks__list">
4
+ <%= skip_links_content %>
5
+ </ul>
6
+ </nav>
7
+ </div>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dsfr_accessible_skip_links
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Isabelle Lafont
@@ -115,6 +115,8 @@ files:
115
115
  - lib/dsfr_accessible_skip_links/engine.rb
116
116
  - lib/dsfr_accessible_skip_links/skip_links.rb
117
117
  - lib/dsfr_accessible_skip_links/version.rb
118
+ - lib/generators/dsfr_accessible_skip_links/install_generator.rb
119
+ - lib/generators/dsfr_accessible_skip_links/templates/_skip_links.html.erb
118
120
  homepage: https://github.com/Isalafont/dsfr_accessible_skip_links
119
121
  licenses:
120
122
  - MIT
@@ -124,7 +126,13 @@ metadata:
124
126
  source_code_uri: https://github.com/Isalafont/dsfr_accessible_skip_links
125
127
  changelog_uri: https://github.com/Isalafont/dsfr_accessible_skip_links/blob/main/CHANGELOG.md
126
128
  rubygems_mfa_required: 'true'
127
- post_install_message:
129
+ post_install_message: |
130
+ Thank you for installing dsfr_accessible_skip_links (v0.1.3)!
131
+
132
+ To complete setup in your Rails app, run:
133
+ bin/rails g dsfr_accessible_skip_links:install
134
+
135
+ This will copy the skip links partial and inject the render call into your application layout.
128
136
  rdoc_options: []
129
137
  require_paths:
130
138
  - lib