i18n_proofreading 1.2.1 → 1.3.0

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: 44c336fff23d26e91d584879766e3f0bce2cf6d9d73af485fdae275452f7682c
4
- data.tar.gz: 92a38f638af73db3ce29ee5b822aafbb7bc8cc6fd925f2393c34ad542bab94f6
3
+ metadata.gz: 3994f49e468a07ca647ff3d634542588ed656ce3c72474f20499acfdd7eded75
4
+ data.tar.gz: aa577d188f654f1f993248a6a17cdbc8fb16d5d407a9efe85f2f4a9be6c6511c
5
5
  SHA512:
6
- metadata.gz: b47ef1083e05980617e51f1a5bfec96e065969f53d0e92ba29b3f4e962ac310e560683f37a263be1a032e1853bd28d16883acdc5fb4b0cb1e7962f15272c1abf
7
- data.tar.gz: 592a870c92d94cf50a885d5494d6fc78a3bb217dc877f36b1a89fa469a9eef6695872aca405f86b686f57adf38f248497256756e5869d7a2e1d61b7dbba51a55
6
+ metadata.gz: 0b7a039096395cf1de29d81ac2659f23467f54f805ba3e7f131ab17dd6e7824f2250573444e9a4a883e1a5ffa0be986c5a1b267d8636af594b63fc45013b120b
7
+ data.tar.gz: f98757d6e91232498d3f589cba1799d88638d7e138d7a9bcd13ab976ee5be5cd55d6fd876c603b1ae19f288bb0f516f61f5a0de6681d6f8ba5289c748d5752fb
data/AGENTS.md CHANGED
@@ -108,6 +108,7 @@ Everything is optional; a fresh install works with zero config in development. F
108
108
  | `author_label` | email, else `to_s` | Receives the user |
109
109
  | `available_locales` | `I18n.available_locales` | Callable; validates what a suggestion may target |
110
110
  | `auto_inject` | `true` | `false` = place `i18n_proofreading_tag` yourself |
111
+ | `controller_scoped` | `false` | Default pages to off until `enable_i18n_proofreading` runs before rendering |
111
112
  | `show_pill`, `pill_label` | `true`, localized | Hide the pill and use `?i18n_proofreading=true` instead; `:auto` hides it only where the page has such a link |
112
113
  | `toggle_param` | `"i18n_proofreading"` | Rename the query parameter |
113
114
  | `rate_limit` | `{ to: 30, within: 60 }` | Rails 7.2+; ignored on 7.1. `nil` disables |
@@ -159,3 +160,41 @@ Conventions this codebase holds to — follow them rather than the first thing t
159
160
  - **`lib/i18n_proofreading/dashboard.css` is half shared.** Everything above the `GEM-SPECIFIC` banner is the design system all five gems in the family ship — the same tokens, the same `.page-head`/`.tabs`/`.filters`/`.card`/`.badge`/`button`/`.status-switch`, the same `.dashboard-shell` + `.record-row` + `.detail-panel` two-pane dashboard — identical in every repo apart from the `ip` prefix. Diff it against a sibling before changing it, and carry the change to the other four. Anything only this gem has goes below the banner. New dashboard markup reuses the shared class names rather than inventing a domain-specific one.
160
161
  - Every user-facing change bumps `lib/i18n_proofreading/version.rb` and adds a `CHANGELOG.md` entry (Keep a Changelog format) that says what it costs, not only what it adds.
161
162
  - Commit messages are prose that explains the tradeoff — read `git log` before writing one.
163
+
164
+ ## Selecting pages from controllers
165
+
166
+ `config.enabled` runs before routing. When page eligibility depends on the
167
+ controller, use a `before_action` **before any translations are rendered**:
168
+
169
+ ```ruby
170
+ class PublicController < ApplicationController
171
+ before_action :disable_i18n_proofreading
172
+ end
173
+ ```
174
+
175
+ This suppresses both markers and the widget, including an explicitly placed
176
+ `i18n_proofreading_tag`. It does not change that page's cache headers.
177
+
178
+ For an allowlist instead, set `config.controller_scoped = true` in the initializer.
179
+ Pages then start with no markers or widget until an eligible controller opts in:
180
+
181
+ ```ruby
182
+ class AccountController < ApplicationController
183
+ before_action :authenticate_user!
184
+ before_action :enable_i18n_proofreading
185
+ end
186
+ ```
187
+
188
+ The environment and `config.enabled` user gates still apply. Authentication and
189
+ which controllers qualify belong to your app; Devise is not required. The
190
+ methods can also be called from your own conditional `before_action`.
191
+
192
+ Default `controller_scoped = false` preserves existing behavior. Page selection
193
+ is independent of suggestion endpoint authorization, the dashboard gate and the
194
+ toggle-cookie redirect. It is not an authorization mechanism. Do not call these
195
+ methods after rendering: disabling cannot remove markers already rendered.
196
+
197
+ This API does not isolate marking to view rendering, bypass fragment caches or
198
+ set CDN cache policy. Hosts must still keep marked fragments out of shared
199
+ caches and protect responses containing reviewer-specific widgets. Existing
200
+ render-scoping/cache safeguards should remain when replacing an injection patch.
data/CHANGELOG.md CHANGED
@@ -2,6 +2,22 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [1.3.0] - 2026-11-17
6
+
7
+ ### Added
8
+
9
+ - Controller methods `disable_i18n_proofreading` and `enable_i18n_proofreading`
10
+ select pages before rendering, suppressing both key markers and automatic or
11
+ manually placed widgets without overriding middleware internals. The optional
12
+ `controller_scoped = true` setting defaults pages to off until opted in.
13
+ - Existing installs retain their behavior. Environment and user gates still
14
+ apply; suggestion endpoints, dashboard authorization and toggle redirects are
15
+ unchanged. No migration or new dependency.
16
+ - Costs: hosts must call these methods before rendering, and still own fragment
17
+ and response cache safeguards. This does not narrow marking to view rendering
18
+ or undo markers already emitted. Excluded pages keep their cache headers.
19
+ - Request and real Turbo browser tests cover page transitions and gate behavior.
20
+
5
21
  ## [1.2.1] - 2026-10-30
6
22
 
7
23
  ### Fixed
data/README.md CHANGED
@@ -112,6 +112,7 @@ Everything is optional — the defaults work out of the box in development. In
112
112
  | `author_label` | the user's `email` | Label shown for the author |
113
113
  | `available_locales` | `I18n.available_locales` | Which locales a suggestion may target |
114
114
  | `auto_inject` | `true` | Inject the widget into HTML responses |
115
+ | `controller_scoped` | `false` | Default pages to off until `enable_i18n_proofreading` runs before rendering |
115
116
  | `show_pill` | `true` | The floating "Improve translation" pill. `:auto` shows it only on pages without a toggle link of your own |
116
117
  | `pill_label` | `nil` | Fixed pill text. `nil` uses the localized default |
117
118
  | `toggle_param` | `"i18n_proofreading"` | Query param that toggles suggest mode |
@@ -200,6 +201,44 @@ It renders nothing unless the tool is available for the request.
200
201
 
201
202
  </details>
202
203
 
204
+ ## Selecting pages from controllers
205
+
206
+ `config.enabled` runs before routing. When page eligibility depends on the
207
+ controller, use a `before_action` **before any translations are rendered**:
208
+
209
+ ```ruby
210
+ class PublicController < ApplicationController
211
+ before_action :disable_i18n_proofreading
212
+ end
213
+ ```
214
+
215
+ This suppresses both markers and the widget, including an explicitly placed
216
+ `i18n_proofreading_tag`. It does not change that page's cache headers.
217
+
218
+ For an allowlist instead, set `config.controller_scoped = true` in the initializer.
219
+ Pages then start with no markers or widget until an eligible controller opts in:
220
+
221
+ ```ruby
222
+ class AccountController < ApplicationController
223
+ before_action :authenticate_user!
224
+ before_action :enable_i18n_proofreading
225
+ end
226
+ ```
227
+
228
+ The environment and `config.enabled` user gates still apply. Authentication and
229
+ which controllers qualify belong to your app; Devise is not required. The
230
+ methods can also be called from your own conditional `before_action`.
231
+
232
+ Default `controller_scoped = false` preserves existing behavior. Page selection
233
+ is independent of suggestion endpoint authorization, the dashboard gate and the
234
+ toggle-cookie redirect. It is not an authorization mechanism. Do not call these
235
+ methods after rendering: disabling cannot remove markers already rendered.
236
+
237
+ This API does not isolate marking to view rendering, bypass fragment caches or
238
+ set CDN cache policy. Hosts must still keep marked fragments out of shared
239
+ caches and protect responses containing reviewer-specific widgets. Existing
240
+ render-scoping/cache safeguards should remain when replacing an injection patch.
241
+
203
242
  ## Reviewing suggestions
204
243
 
205
244
  The engine root (default `/i18n_proofreading`) is a **read-only** board:
@@ -291,6 +330,7 @@ deprecation normally ships in a preceding minor release.
291
330
  - `I18nProofreading.configure` and the configuration options listed above.
292
331
  - `mount_i18n_proofreading at:` and the mounted dashboard root.
293
332
  - `i18n_proofreading_tag` for hosts that disable automatic injection.
333
+ - `enable_i18n_proofreading` and `disable_i18n_proofreading` controller callbacks.
294
334
  - The configured toggle parameter and its `true` / `false` behavior.
295
335
  - `I18nProofreading::Suggestion` fields documented under Reviewing
296
336
  suggestions, `STATUSES`, prefixed status helpers/scopes, and `newest_first`.
@@ -52,6 +52,12 @@ I18nProofreading.configure do |config|
52
52
  #
53
53
  # config.auto_inject = true
54
54
 
55
+ # Default pages to off until a before_action calls enable_i18n_proofreading.
56
+ # With the default false, disable_i18n_proofreading excludes individual pages.
57
+ # Call before rendering; both markers and automatic/manual widgets obey it.
58
+ # User/environment gates and suggestion endpoint authorization are unchanged.
59
+ # config.controller_scoped = false
60
+
55
61
  # Show the floating "Improve translation" pill. Set false to hide it and toggle
56
62
  # suggest mode from your own link instead, e.g.
57
63
  # `<%= link_to "Proofread", "?i18n_proofreading=true" %>`. "?i18n_proofreading=false"
@@ -61,6 +61,9 @@ module I18nProofreading
61
61
  # yourself with `<%= i18n_proofreading_tag %>` in your layout.
62
62
  attr_accessor :auto_inject
63
63
 
64
+ # Default pages to off until a controller calls enable_i18n_proofreading.
65
+ attr_accessor :controller_scoped
66
+
64
67
  # Where the engine is mounted. The widget posts suggestions to
65
68
  # "#{mount_path}/suggestions", so keep this in sync with the `mount` line in
66
69
  # your routes.
@@ -101,6 +104,7 @@ module I18nProofreading
101
104
  @author_label = ->(user) { user.respond_to?(:email) ? user.email : user&.to_s }
102
105
  @available_locales = -> { I18n.available_locales.map(&:to_s) }
103
106
  @auto_inject = true
107
+ @controller_scoped = false
104
108
  @mount_path = '/i18n_proofreading'
105
109
  @show_pill = true
106
110
  @pill_label = nil
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module I18nProofreading
4
+ # Call from a before_action, before any translations are rendered. Page scope
5
+ # never grants access: the middleware's environment/user gate remains required.
6
+ module ControllerMethods
7
+ private
8
+
9
+ def enable_i18n_proofreading
10
+ request.env[PageScope::ENABLED] = true
11
+ Marking.enabled = request.env[PageScope::MARKING] == true
12
+ end
13
+
14
+ def disable_i18n_proofreading
15
+ request.env[PageScope::ENABLED] = false
16
+ Marking.enabled = false
17
+ end
18
+ end
19
+
20
+ module PageScope
21
+ ENABLED = 'i18n_proofreading.page_enabled'
22
+ MARKING = 'i18n_proofreading.marking_allowed'
23
+
24
+ def self.enabled?(request)
25
+ request.env.fetch(ENABLED) { !I18nProofreading.config.controller_scoped }
26
+ end
27
+ end
28
+ end
@@ -32,6 +32,12 @@ module I18nProofreading
32
32
  end
33
33
  end
34
34
 
35
+ initializer 'i18n_proofreading.controller_methods' do
36
+ ActiveSupport.on_load(:action_controller_base) do
37
+ include I18nProofreading::ControllerMethods
38
+ end
39
+ end
40
+
35
41
  initializer 'i18n_proofreading.helper' do
36
42
  ActiveSupport.on_load(:action_view) do
37
43
  include I18nProofreading::TagHelper
@@ -27,11 +27,13 @@ module I18nProofreading
27
27
  end
28
28
 
29
29
  marking = available && cookie_on?(request)
30
- Marking.enabled = marking
30
+ env[PageScope::MARKING] = marking
31
+ Marking.enabled = marking && PageScope.enabled?(request)
31
32
 
32
33
  status, headers, body = @app.call(env)
33
34
 
34
- if available && I18nProofreading.config.auto_inject && html?(headers) && !request.xhr?
35
+ if available && PageScope.enabled?(request) && I18nProofreading.config.auto_inject &&
36
+ html?(headers) && !request.xhr?
35
37
  status, headers, body = inject(status, headers, body, marking, csp_nonce(env))
36
38
  end
37
39
 
@@ -8,7 +8,7 @@ module I18nProofreading
8
8
  # autoloaders, when an app/helpers constant cannot be resolved yet.
9
9
  module TagHelper
10
10
  def i18n_proofreading_tag
11
- return ''.html_safe unless I18nProofreading.available?(request)
11
+ return ''.html_safe unless I18nProofreading.available?(request) && PageScope.enabled?(request)
12
12
 
13
13
  Widget.snippet(
14
14
  endpoint: I18nProofreading.config.suggestions_endpoint,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module I18nProofreading
4
- VERSION = '1.2.1'
4
+ VERSION = '1.3.0'
5
5
  end
@@ -5,6 +5,7 @@ require 'i18n_proofreading/configuration'
5
5
  require 'i18n_proofreading/ractor_support'
6
6
  require 'i18n_proofreading/marking'
7
7
  require 'i18n_proofreading/widget'
8
+ require 'i18n_proofreading/controller_methods'
8
9
  require 'i18n_proofreading/tag_helper'
9
10
  require 'i18n_proofreading/middleware'
10
11
  require 'i18n_proofreading/seeds'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n_proofreading
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yaroslav Shmarov
@@ -103,6 +103,7 @@ files:
103
103
  - lib/generators/i18n_proofreading/migration_helpers.rb
104
104
  - lib/i18n_proofreading.rb
105
105
  - lib/i18n_proofreading/configuration.rb
106
+ - lib/i18n_proofreading/controller_methods.rb
106
107
  - lib/i18n_proofreading/dashboard.css
107
108
  - lib/i18n_proofreading/engine.rb
108
109
  - lib/i18n_proofreading/marking.rb