bible270 1.18.1 → 1.20.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: e05722a707b9ded33b258dbc2636df5f1bbf93b782649f84ff8fc6efa7b2d6a3
4
- data.tar.gz: f53179ed25244dd464fe5815426543e0f32efa9ab7835713c4d99d382b17f03f
3
+ metadata.gz: 6a65a67fcc122a62da55e92fef4963276c602f49a1065aa76d9ae01465bbbb35
4
+ data.tar.gz: b105759802039f75165f009fdeb3ebcaee7d25e509da9a7a3157d2f3892b4019
5
5
  SHA512:
6
- metadata.gz: e8aab969ee632687d27b77e410448b1c41ad97b22ea79d2412e545f98d2fff39b70d01747317c15c11c0a19596ef9ba4d10edc2004841a77a2ebfc43999e1bd2
7
- data.tar.gz: 83cf6dd7f75f5d0ac3bc22260f0db6166081e3321544f80f53f00bf01ee9101782ad8ad83fc96e9cbc2f31928e749f25c0f392ff58484a4b2b04acffda5e665f
6
+ metadata.gz: 619c55ea4f70ac7c59b9170e0c10437a9cf36ec08d1989f7162a5cb6be3a2e148d3a01f6bd233cb4a95004a4e4a965a2313008e3d4ad46848e55c1ae60e2eda4
7
+ data.tar.gz: 42b46a4f1e320fd4e5bd819cf53c3f9ab533212b285bf3f4ee8aa99b3f34bb76e13618530ca7a752047f8c3c9a938061d3b2c7883c2705dabd81dafaa5b5b5c5
data/CHANGELOG.md CHANGED
@@ -6,10 +6,22 @@ Notable changes, following [Keep a Changelog](https://keepachangelog.com/en/1.1.
6
6
 
7
7
  ### Added
8
8
 
9
- - let admins link matching reader accounts for one-way progress sync, including existing completions
10
- - queue reliable delivery between trusted instances, with retries and optional immediate background jobs
9
+ - preview any Scripture frame from Admin in the current theme
11
10
 
12
- **Setup:** Install migration `20260101000028` on each instance, configure trusted connections, and schedule delivery on the primary. Progress sync is off until configured.
11
+ ### Changed
12
+
13
+ - give longer completion passages more reading time, from 5.5 to 30 seconds
14
+ - rotate Scripture frames in shuffled rounds shared by the bread popup and day completion
15
+ - speed up tests with balanced files, leaner fixtures, and CPU-aware image processing
16
+ - reuse unchanged reading-plan cache settings while preserving live configuration updates
17
+
18
+ **Upgrade:** Install migration `20260101000029` to save readers' rotation across visits and devices.
19
+
20
+ ## [1.18.1] - 2026-11-14
21
+
22
+ ### Added
23
+
24
+ - expand the bundled Scripture frame collection
13
25
 
14
26
  ### Changed
15
27
 
@@ -18,6 +30,20 @@ Notable changes, following [Keep a Changelog](https://keepachangelog.com/en/1.1.
18
30
  ### Fixed
19
31
 
20
32
  - display the last sync time in the system time zone instead of UTC
33
+ - guard sync-secret configuration in setup examples so Docker builds need no runtime secrets
34
+
35
+ ## [1.18.0] - 2026-11-14
36
+
37
+ ### Added
38
+
39
+ - let admins link matching reader accounts for one-way progress sync, including existing completions
40
+ - queue reliable delivery between trusted instances, with retries and optional immediate background jobs
41
+
42
+ **Setup:** Install migration `20260101000028` on each instance, configure trusted connections, and schedule delivery on the primary. Progress sync is off until configured.
43
+
44
+ ### Fixed
45
+
46
+ - make the sync job test adapter compatible with Rails 7.2
21
47
 
22
48
  ## [1.17.2] - 2026-11-13
23
49
 
@@ -901,7 +927,9 @@ This is the initial public release.
901
927
 
902
928
  - Email sign-in requires working Action Mailer delivery in the host application. Set `config.mailer_from`; delivery is inline by default, or set `email_sign_in_deliver_later` when a queue backend is available.
903
929
 
904
- [Unreleased]: https://github.com/avonderluft/bible270/compare/v1.17.2...main
930
+ [Unreleased]: https://github.com/avonderluft/bible270/compare/v1.18.1...main
931
+ [1.18.1]: https://github.com/avonderluft/bible270/compare/v1.18.0...v1.18.1
932
+ [1.18.0]: https://github.com/avonderluft/bible270/compare/v1.17.2...v1.18.0
905
933
  [1.17.2]: https://github.com/avonderluft/bible270/compare/v1.17.1...v1.17.2
906
934
  [1.17.1]: https://github.com/avonderluft/bible270/compare/v1.17.0...v1.17.1
907
935
  [1.17.0]: https://github.com/avonderluft/bible270/compare/v1.16.0...v1.17.0
data/README.md CHANGED
@@ -414,7 +414,9 @@ For a host Content Security Policy (CSP), add `https://www.youtube-nocookie.com`
414
414
 
415
415
  Hover over the bread icon for **3 seconds**, or open it immediately by tap, click, or Enter/Space. The random, theme-matched frame closes when you leave a hover preview, press Escape, click outside, or select the bread again.
416
416
 
417
- Completing a day shows a random frame followed by the optional dove; both fade out together. Disabling the dove keeps the frame. Reduced-motion users see a static frame, and Escape dismisses the sequence.
417
+ Completion frames stay fully visible for **5.5–30 seconds**, based on passage length, before the optional dove and shared fade. Disabling the dove keeps the frame. Reduced-motion users see a static frame, and Escape dismisses the sequence.
418
+
419
+ The popup and completion frames share a shuffled rotation: each enabled text is selected before repeating, without back-to-back repeats when alternatives exist. Changing the available texts starts a fresh round. Migration `20260101000029` saves signed-in readers' rotation across visits and devices; visitors and installations awaiting migration use browser-session rotation.
418
420
 
419
421
  The [bundled YAML catalog](config/scripture_frames.yml) supplies the defaults in biblical order. Manage texts under **Admin → Scripture frames**:
420
422
 
@@ -422,7 +424,7 @@ The [bundled YAML catalog](config/scripture_frames.yml) supplies the defaults in
422
424
  - For non-Scripture text, select **Other quotation** under Translation and enter **Author / source** and the quote. No Bible credit is attached.
423
425
  - Edit or delete custom texts; enable or disable any text. Disabled texts remain previewable but do not appear in random frames.
424
426
 
425
- Custom passages come first in biblical order, then quotations and defaults. Hover or focus a heading to preview; select it to expand. Use text you have permission to reproduce.
427
+ Custom passages come first in biblical order, then quotations and defaults. **Preview** opens the reader-facing frame in your theme, without animation or a timer. Hover or focus a heading for plain text; select it to expand. Use text you have permission to reproduce.
426
428
 
427
429
  **Custom texts are stored in the database and supplement, not change, the YAML catalog.** Texts and enable/disable choices persist across runs. Defaults start enabled and cannot be edited or deleted. Custom texts require migration `20260101000027`.
428
430
 
@@ -763,9 +765,9 @@ node --test test/javascript/*.cjs
763
765
  bundle exec rubocop --cache false
764
766
  ```
765
767
 
766
- `rake test` uses up to eight CPU-aware workers and writes coverage to `coverage/index.html`. Tests share setup in `test/support`.
768
+ `rake test` uses up to 16 CPU-aware workers and writes coverage to `coverage/index.html`. Tests share setup in `test/support`; libvips uses one thread per worker to avoid CPU contention.
767
769
 
768
- Use `PARALLEL_WORKERS=4 bundle exec rake test` to choose the count, or `bundle exec rake test:serial` for serial coverage. Logs keep warnings and errors in `test/dummy/log/test-*.log`; set `TEST_LOG_LEVEL=debug` for request, template, and SQL details.
770
+ Use `PARALLEL_WORKERS=4 bundle exec rake test` to limit CPU/memory use, or `bundle exec rake test:serial` for serial coverage. `VIPS_CONCURRENCY` overrides image-processing threads. Logs keep warnings and errors in `test/dummy/log/test-*.log`; `TEST_LOG_LEVEL=debug` adds request/SQL details and `TEST_ERROR_PAGES=1` enables developer error pages. Unexpected errors still raise.
769
771
 
770
772
  JavaScript tests require **Node.js 22+**. Chromium layout checks run when a browser is available (`CHROME_BIN` selects it). Video tests do not contact YouTube; check live playback and host CSP separately.
771
773
 
data/Rakefile CHANGED
@@ -161,13 +161,15 @@ namespace :test do
161
161
  Rake::Task['test:serial'].enhance(['test:prepare_serial'])
162
162
 
163
163
  task :parallel do
164
- workers = ENV.fetch('PARALLEL_WORKERS') { Etc.nprocessors.clamp(1, 8).to_s }
164
+ workers = ENV.fetch('PARALLEL_WORKERS') { Etc.nprocessors.clamp(1, 16).to_s }
165
165
  FileUtils.rm_rf('coverage')
166
166
  env = {
167
167
  'PARALLEL_COVERAGE' => 'true',
168
168
  'RECORD_RUNTIME' => 'true',
169
169
  'SKIP_COV' => nil,
170
170
  'NO_COLOR' => '1',
171
+ # Parallel processes already use the CPUs; avoid nested libvips thread pools.
172
+ 'VIPS_CONCURRENCY' => ENV.fetch('VIPS_CONCURRENCY', '1'),
171
173
  'TMPDIR' => ENV.fetch('BIBLE270_TEST_TMPDIR', '/tmp')
172
174
  }
173
175
  command = ['bundle', 'exec', 'parallel_test', 'test', '--type', 'test', '-n', workers]
@@ -7,7 +7,7 @@ module Bible270
7
7
  return head :not_acceptable unless request.format.json?
8
8
 
9
9
  exclude = params[:exclude] if params[:exclude].is_a?(String)
10
- frame = ScriptureFrames.random(exclude: exclude)
10
+ frame = ScriptureFrames.random(exclude: exclude, reader: current_reader, session: session)
11
11
  return head :no_content unless frame
12
12
 
13
13
  render json: frame.to_h
@@ -20,9 +20,14 @@
20
20
  <% text_id = "b270-scripture-library-#{source.downcase}-#{index}" %>
21
21
  <article class="b270-scripture-library-entry b270-scripture-library-entry--<%= source.downcase %>" data-source="<%= source.downcase %>"
22
22
  aria-label="<%= source == 'Default' ? 'Bundled' : 'Custom' %> text: <%= frame.reference %>">
23
- <%= render 'bible270/admin/scripture_text', frame: frame, source: source, text_id: text_id, return_to: 'admin' %>
24
- <% if source == 'Custom' %>
25
- <div class="b270-scripture-actions">
23
+ <%= render 'bible270/admin/scripture_text', frame: frame, source: source, text_id: text_id %>
24
+ <div class="b270-scripture-actions">
25
+ <%= button_tag 'Preview', type: 'button', class: 'b270-linkbtn',
26
+ data: { b270_scripture_preview: true, b270_preview_reference: frame.reference,
27
+ b270_preview_translation: frame.translation, b270_preview_text: frame.text,
28
+ b270_preview_attribution: frame.attribution.to_s },
29
+ aria: { haspopup: 'dialog', controls: 'b270-scripture-preview', label: "Preview #{frame.reference}" } %>
30
+ <% if source == 'Custom' %>
26
31
  <%= link_to 'Edit', edit_admin_scripture_frame_path(frame, sort: @reader_sort), aria: { label: "Edit #{frame.reference}" } %>
27
32
  <%= button_to frame.enabled? ? 'Disable' : 'Enable', admin_scripture_frame_path(frame), method: :patch,
28
33
  params: { scripture_frame: { enabled: frame.enabled? ? '0' : '1' }, sort: @reader_sort }, class: 'b270-linkbtn',
@@ -30,8 +35,14 @@
30
35
  <%= button_to 'Delete', admin_scripture_frame_path(frame), method: :delete, class: 'b270-linkbtn',
31
36
  params: { sort: @reader_sort }, aria: { label: "Delete #{frame.reference}" },
32
37
  form: { data: { b270_admin_confirm: 'Delete this custom scripture frame permanently?' } } %>
33
- </div>
34
- <% end %>
38
+ <% elsif @scripture_frame_default_settings_available %>
39
+ <% disabled = Array(@disabled_default_scripture_frame_ids).include?(frame.id) %>
40
+ <%= button_to disabled ? 'Enable' : 'Disable', admin_default_scripture_frame_path(frame.id), method: :patch,
41
+ params: { enabled: disabled ? '1' : '0', return_to: 'admin', sort: @reader_sort },
42
+ class: 'b270-linkbtn', form: { class: 'b270-scripture-default-toggle' },
43
+ aria: { label: "#{disabled ? 'Enable' : 'Disable'} #{frame.reference}" } %>
44
+ <% end %>
45
+ </div>
35
46
  </article>
36
47
  <% end %>
37
48
  </div>
@@ -3,9 +3,3 @@
3
3
  <summary aria-describedby="<%= text_id %>"><strong><%= frame.reference %></strong> · <%= Bible270::ScriptureFrames.quotation?(frame.translation) ? 'Other quotation' : frame.translation %> · <%= source %><% if disabled %> · Disabled<% end %></summary>
4
4
  <blockquote class="b270-scripture-library-text" id="<%= text_id %>" role="tooltip" tabindex="0"><%= frame.text %></blockquote>
5
5
  </details>
6
- <% if source == 'Default' && @scripture_frame_default_settings_available %>
7
- <%= button_to disabled ? 'Enable' : 'Disable', admin_default_scripture_frame_path(frame.id), method: :patch,
8
- params: { enabled: disabled ? '1' : '0', return_to: local_assigns.fetch(:return_to, 'texts'), sort: @reader_sort },
9
- class: 'b270-linkbtn', form: { class: 'b270-scripture-default-toggle' },
10
- aria: { label: "#{disabled ? 'Enable' : 'Disable'} #{frame.reference}" } %>
11
- <% end %>
@@ -226,3 +226,4 @@
226
226
  <%= render 'bible270/shared/admin_confirmations' %>
227
227
  <%= render 'bible270/shared/admin_reader_list_ui' %>
228
228
  <%= render 'bible270/shared/scripture_library_ui' %>
229
+ <%= render 'bible270/shared/scripture_preview_ui' %>
@@ -1,5 +1,5 @@
1
1
  <%# locals: (day:, reader:, completion_event_id:) %>
2
- <% frame = Bible270::ScriptureFrames.random %>
2
+ <% frame = Bible270::ScriptureFrames.random(reader: reader, session: session) %>
3
3
  <div class="b270-completion" data-b270-completion data-b270-day="<%= day %>"
4
4
  data-b270-completion-event="<%= completion_event_id %>" data-turbo-temporary hidden>
5
5
  <% if frame %>
@@ -72,6 +72,12 @@
72
72
  if (current(state) && !state.finishing) dispose(state);
73
73
  }
74
74
 
75
+ function holdDuration(state) {
76
+ const text = state.frame.querySelector("[data-b270-scripture-text]")?.textContent || "";
77
+ const wordCount = text.match(/[^\s\p{White_Space}]+/gu)?.length || 0;
78
+ return Math.min(30000, Math.max(5500, 2000 + wordCount * 250));
79
+ }
80
+
75
81
  function fly(state) {
76
82
  if (!current(state)) return;
77
83
  if (!state.dove || motion?.matches) {
@@ -109,7 +115,7 @@
109
115
  state.raf = null;
110
116
  if (!current(state)) return;
111
117
  element.classList.add("is-visible");
112
- if (state.frame) later(state, () => fly(state), fadeInDuration() + 5500);
118
+ if (state.frame) later(state, () => fly(state), fadeInDuration() + holdDuration(state));
113
119
  else fly(state);
114
120
  });
115
121
  }
@@ -0,0 +1,113 @@
1
+ <dialog id="b270-scripture-preview" class="b270-scripture-preview" aria-label="Scripture frame preview" data-b270-scripture-preview-dialog>
2
+ <form method="dialog" class="b270-scripture-preview-close">
3
+ <button type="submit" class="b270-linkbtn" aria-label="Close preview" autofocus>×</button>
4
+ </form>
5
+ <%= render partial: "bible270/shared/scripture_frame", locals: { frame: nil } %>
6
+ </dialog>
7
+
8
+ <script nonce="<%= content_security_policy_nonce %>" data-b270-scripture-preview-ui>
9
+ (() => {
10
+ if (window.Bible270ScripturePreview) {
11
+ window.Bible270ScripturePreview.reset();
12
+ return;
13
+ }
14
+
15
+ const selector = "button[data-b270-scripture-preview]";
16
+ const keys = ["reference", "translation", "text", "attribution"];
17
+ let active = null;
18
+ let backdropStart = false;
19
+
20
+ function clear(dialog) {
21
+ dialog.returnValue = "";
22
+ dialog.removeAttribute("open");
23
+ const art = dialog.querySelector("[data-b270-scripture-art]");
24
+ if (art) art.hidden = true;
25
+ keys.forEach((key) => {
26
+ const field = dialog.querySelector(`[data-b270-scripture-${key}]`);
27
+ if (!field) return;
28
+ field.textContent = "";
29
+ if (key === "translation" || key === "attribution") field.hidden = true;
30
+ });
31
+ }
32
+
33
+ function reset() {
34
+ const state = active;
35
+ active = null;
36
+ backdropStart = false;
37
+ if (!state) return;
38
+ // Native close restores its original focus target even after blur. Make
39
+ // that target briefly inert so navigation cannot refocus the departing page.
40
+ const previousFocus = state.previousFocus;
41
+ const wasInert = previousFocus?.inert;
42
+ if (previousFocus) previousFocus.inert = true;
43
+ if (state.dialog.contains(document.activeElement)) document.activeElement.blur();
44
+ if (state.dialog.open) state.dialog.close();
45
+ if (previousFocus) previousFocus.inert = wasInert;
46
+ clear(state.dialog);
47
+ }
48
+
49
+ function outside(dialog, event) {
50
+ const rect = dialog.getBoundingClientRect();
51
+ return event.clientX < rect.left || event.clientX > rect.right ||
52
+ event.clientY < rect.top || event.clientY > rect.bottom;
53
+ }
54
+
55
+ document.addEventListener("pointerdown", (event) => {
56
+ backdropStart = !!active && event.target === active.dialog && outside(active.dialog, event);
57
+ });
58
+ document.addEventListener("pointercancel", () => { backdropStart = false; });
59
+
60
+ document.addEventListener("click", (event) => {
61
+ const startedOutside = backdropStart;
62
+ backdropStart = false;
63
+ if (event.defaultPrevented) return;
64
+ const trigger = event.target.closest?.(selector);
65
+ if (!trigger) {
66
+ const dismiss = active && startedOutside && event.target === active.dialog && outside(active.dialog, event);
67
+ if (dismiss) active.dialog.close();
68
+ return;
69
+ }
70
+ const dialog = document.getElementById(trigger.getAttribute("aria-controls"));
71
+ if (!trigger.isConnected || !dialog?.matches("dialog[data-b270-scripture-preview-dialog]") ||
72
+ !dialog.isConnected || typeof dialog.showModal !== "function") return;
73
+ const art = dialog.querySelector("[data-b270-scripture-art]");
74
+ const fields = keys.map((key) => art?.querySelector(`[data-b270-scripture-${key}]`));
75
+ if (!art || fields.some((field) => !field)) return;
76
+ event.preventDefault();
77
+ if (active && active.dialog !== dialog) reset();
78
+ const previousFocus = active?.dialog === dialog && dialog.open ? active.previousFocus : document.activeElement;
79
+ active = { dialog, trigger, previousFocus };
80
+ backdropStart = false;
81
+ const quotation = trigger.getAttribute("data-b270-preview-translation") === "OTHER";
82
+ keys.forEach((key, index) => {
83
+ const value = trigger.getAttribute(`data-b270-preview-${key}`) || "";
84
+ const omit = quotation && (key === "translation" || key === "attribution");
85
+ fields[index].textContent = omit ? "" : value;
86
+ if (key === "translation" || key === "attribution") fields[index].hidden = omit || !value.trim();
87
+ });
88
+ art.hidden = false;
89
+ try {
90
+ if (!dialog.open) dialog.showModal();
91
+ dialog.scrollTop = 0;
92
+ } catch (_) {
93
+ reset();
94
+ }
95
+ });
96
+
97
+ // Native form dismissal and Escape both deliver close, which does not bubble.
98
+ document.addEventListener("close", (event) => {
99
+ const state = active;
100
+ // A queued close from an earlier session must not clear a reopened dialog.
101
+ if (!state || event.target !== state.dialog || state.dialog.open) return;
102
+ active = null;
103
+ backdropStart = false;
104
+ clear(state.dialog);
105
+ if (state.dialog.isConnected && state.trigger.isConnected) state.trigger.focus({ preventScroll: true });
106
+ }, true);
107
+
108
+ document.addEventListener("turbo:before-cache", reset);
109
+ document.addEventListener("turbo:before-render", reset);
110
+ window.addEventListener("pagehide", reset);
111
+ window.Bible270ScripturePreview = { reset };
112
+ })();
113
+ </script>
@@ -526,6 +526,11 @@
526
526
  .b270-scripture-actions>a,.b270-scripture-actions .b270-linkbtn{margin:0;font-size:12.5px;color:var(--oxblood)}
527
527
  .b270-scripture-library-entry{padding:10px 0;border-top:1px solid var(--line-soft);font-size:13px}
528
528
  .b270-scripture-library-entry--default,.b270-scripture-library-entry--custom{display:grid;grid-template-columns:minmax(0,1fr) auto;align-items:start;gap:12px}
529
+ @media(max-width:360px){
530
+ #b270-scripture-frames{padding-inline:10px}
531
+ .b270-scripture-library-entry--default,.b270-scripture-library-entry--custom{grid-template-columns:minmax(0,1fr)}
532
+ .b270-scripture-actions{justify-self:end}
533
+ }
529
534
  .b270-scripture-default-toggle{margin:0}
530
535
  .b270 .b270-scripture-default-toggle .b270-linkbtn{margin:0;font-size:12.5px;line-height:inherit;white-space:nowrap;color:var(--oxblood)}
531
536
  .b270-scripture-library-disclosure{position:relative}
@@ -561,6 +566,14 @@
561
566
  width:min(32rem,calc(100vw - 24px));max-height:calc(100vh - 24px);max-height:calc(100dvh - 24px);
562
567
  padding:10px;border:1px solid var(--line);border-radius:8px;background:var(--card);background:color-mix(in srgb,var(--card) 90%,var(--gold));color:var(--ink);
563
568
  box-shadow:var(--shadow);opacity:0;pointer-events:none;transition:opacity 180ms ease-out}
569
+ .b270-scripture-preview{box-sizing:border-box;width:min(32rem,calc(100vw - 24px));max-width:none;
570
+ max-height:calc(100vh - 24px);max-height:calc(100dvh - 24px);overflow-y:auto;overscroll-behavior:contain;
571
+ padding:10px;border:1px solid var(--line);border-radius:8px;background:var(--card);background:color-mix(in srgb,var(--card) 90%,var(--gold));color:var(--ink);box-shadow:var(--shadow)}
572
+ .b270-scripture-preview::backdrop{background:rgb(0 0 0 / .55)}
573
+ .b270-scripture-preview-close{display:flex;justify-content:flex-end;margin:0 0 8px}
574
+ .b270-scripture-preview-close .b270-linkbtn{margin:0;padding:0 6px;color:var(--ink);font-size:22px;line-height:1}
575
+ .b270-scripture-preview-close .b270-linkbtn:focus-visible{outline:2px solid var(--gold);outline-offset:2px}
576
+ .b270[data-display-mode="sage"] .b270-scripture-preview,
564
577
  .b270[data-display-mode="sage"] .b270-scripture-library-text,
565
578
  .b270[data-display-mode="sage"] .b270-scripture-art__mat,
566
579
  .b270[data-display-mode="sage"] .b270-scripture-popup{background:#d1e2ea}
@@ -13,6 +13,16 @@
13
13
  translation: ESV
14
14
  text: But the word is very near you. It is in your mouth and in your heart, so that you can do it.
15
15
  attribution: ESV © 2001 Crossway.
16
+ - id: psalm-1-1-2
17
+ reference: Psalm 1:1-2
18
+ translation: NASB95
19
+ text: |-
20
+ How blessed is the man who does not walk in the counsel of the wicked,
21
+ Nor stand in the path of sinners,
22
+ Nor sit in the seat of scoffers!
23
+ But his delight is in the law of the LORD,
24
+ And in His law he meditates day and night.
25
+ attribution: NASB 1995 © The Lockman Foundation.
16
26
  - id: psalm-19-8
17
27
  reference: Psalm 19:8
18
28
  translation: NKJV
@@ -69,6 +79,24 @@
69
79
  The unfolding of Your words gives light;
70
80
  It gives understanding to the simple.
71
81
  attribution: NASB 1995 © The Lockman Foundation.
82
+ - id: psalm-119-162
83
+ reference: Psalm 119:162
84
+ translation: NASB95
85
+ text: |-
86
+ I rejoice at Your word,
87
+ As one who finds great spoil.
88
+ attribution: NASB 1995 © The Lockman Foundation.
89
+ id: proverbs-4-20-22
90
+ reference: Proverbs 4:20-22
91
+ translation: NASB95
92
+ text: |-
93
+ My son, give attention to my words;
94
+ Incline your ear to my sayings.
95
+ Do not let them depart from your sight;
96
+ Keep them in the midst of your heart.
97
+ For they are life to those who find them
98
+ And health to all their body.
99
+ attribution: NASB 1995 © The Lockman Foundation.
72
100
  - id: proverbs-6-23
73
101
  reference: Proverbs 6:23
74
102
  translation: NASB95
@@ -83,6 +111,16 @@
83
111
  He who gives attention to the word will find good,
84
112
  And blessed is he who trusts in the LORD.
85
113
  attribution: NASB 1995 © The Lockman Foundation.
114
+ - id: isaiah-40-7-8
115
+ reference: Isaiah 40:7-8
116
+ translation: NASB95
117
+ text: |-
118
+ The grass withers, the flower fades,
119
+ When the breath of the LORD blows upon it;
120
+ Surely the people are grass.
121
+ The grass withers, the flower fades,
122
+ But the word of our God stands forever.
123
+ attribution: NASB 1995 © The Lockman Foundation.
86
124
  - id: isaiah-55-11
87
125
  reference: Isaiah 55:11
88
126
  translation: ESV
@@ -118,6 +156,11 @@
118
156
  “Is not My word like a fire?” says the LORD,
119
157
  “And like a hammer that breaks the rock in pieces?
120
158
  attribution: NKJV © 1982 Thomas Nelson.
159
+ - id: matthew-24-35
160
+ reference: Matthew 24:35
161
+ translation: NKJV
162
+ text: Heaven and earth will pass away, but My words will by no means pass away.
163
+ attribution: NKJV © 1982 Thomas Nelson.
121
164
  - id: john-6-63
122
165
  reference: John 6:63
123
166
  translation: NKJV
@@ -176,3 +219,8 @@
176
219
  translation: NASB95
177
220
  text: like newborn babies, long for the pure milk of the word, so that by it you may grow in respect to salvation, if you have tasted the kindness of the Lord.
178
221
  attribution: NASB 1995 © The Lockman Foundation.
222
+ - id: 2-peter-1-19-21
223
+ reference: 2 Peter 1:19-21
224
+ translation: NASB95
225
+ text: So we have the prophetic word made more sure, to which you do well to pay attention as to a lamp shining in a dark place, until the day dawns and the morning star arises in your hearts. But know this first of all, that no prophecy of Scripture is a matter of one’s own interpretation, for no prophecy was ever made by an act of human will, but men moved by the Holy Spirit spoke from God.
226
+ attribution: NASB 1995 © The Lockman Foundation.
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddScriptureFrameRotationToBible270Readers < ActiveRecord::Migration[7.0]
4
+ def change
5
+ add_column :bible270_readers, :scripture_frame_rotation, :json, null: false, default: {}
6
+ end
7
+ end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'json'
4
+
3
5
  module Bible270
4
6
  # Repairs schema_migrations after a database is copied without matching migration
5
7
  # bookkeeping. A migration is safe to mark only when every table, column and
@@ -38,6 +40,7 @@ module Bible270
38
40
  'AddRevertToBible270PlanRuns' => :check_run_revert,
39
41
  'CreateBible270ScriptureFrames' => :check_scripture_frames,
40
42
  'CreateBible270ProgressSync' => :check_progress_sync,
43
+ 'AddScriptureFrameRotationToBible270Readers' => :check_scripture_frame_rotation,
41
44
 
42
45
  'CreateActiveStorageTables' => :check_active_storage
43
46
  }.freeze
@@ -307,6 +310,12 @@ module Bible270
307
310
  progress_sync_relationships_missing + progress_sync_link_indexes_missing
308
311
  end
309
312
 
313
+ def check_scripture_frame_rotation
314
+ table_missing(:bible270_readers, columns: %i[scripture_frame_rotation]) +
315
+ missing_column_definitions(:bible270_readers,
316
+ scripture_frame_rotation: { type: :json, null: false, default: {} })
317
+ end
318
+
310
319
  def check_admin
311
320
  table_missing(:bible270_readers, columns: %i[admin]) +
312
321
  missing_column_definitions(:bible270_readers, admin: { type: :boolean, null: false, default: false })
@@ -489,6 +498,13 @@ module Bible270
489
498
  connection.columns(table).flat_map do |column|
490
499
  definitions.fetch(column.name.to_sym, {}).filter_map do |attribute, expected|
491
500
  actual = column.public_send(attribute)
501
+ if attribute == :default && column.type == :json && actual.is_a?(String)
502
+ begin
503
+ actual = JSON.parse(actual)
504
+ rescue JSON::ParserError
505
+ # Leave malformed defaults unmatched.
506
+ end
507
+ end
492
508
  actual = ActiveModel::Type::Boolean.new.cast(actual) if attribute == :default && column.type == :boolean
493
509
  if attribute == :default && column.type == :integer && actual.is_a?(String) && actual.match?(%r{\A[+-]?\d+\z})
494
510
  actual = Integer(actual, 10)
data/lib/bible270/plan.rb CHANGED
@@ -187,7 +187,7 @@ module Bible270
187
187
  # Validated on the way out so a typo fails loudly instead of silently
188
188
  # producing overlapping or out-of-range readings.
189
189
  def chapter_breaks_for(book, chapter)
190
- points = configured_breaks[[book, chapter]]
190
+ points = cached_configured_breaks[[book, chapter]]
191
191
  return nil if points.nil?
192
192
 
193
193
  total = verses_for(book, chapter)
@@ -197,13 +197,13 @@ module Bible270
197
197
  "verse numbers between 1 and #{total - 1}, got #{points.inspect}"
198
198
  end
199
199
 
200
- points
200
+ points.dup
201
201
  end
202
202
 
203
203
  # {index => reading count} for chapters whose breaks are set explicitly.
204
204
  def pinned_from_breaks(chapters)
205
205
  chapters.each_with_index.filter_map do |(book, chapter), idx|
206
- points = configured_breaks[[book, chapter]]
206
+ points = cached_configured_breaks[[book, chapter]]
207
207
  [idx, points.size + 1] if points
208
208
  end.to_h
209
209
  end
@@ -233,7 +233,7 @@ module Bible270
233
233
  # all at once rather than leaving a half-rebuilt plan.
234
234
 
235
235
  def memo(key)
236
- fingerprint = configured_breaks
236
+ fingerprint = cached_configured_breaks
237
237
  if @cache_fingerprint != fingerprint
238
238
  @cache = {}
239
239
  @cache_fingerprint = fingerprint
@@ -247,6 +247,10 @@ module Bible270
247
247
  def reset!
248
248
  @cache = {}
249
249
  @cache_fingerprint = nil
250
+ @break_source_fingerprint = nil
251
+ @configured_breaks = nil
252
+ @file_breaks_stamp = nil
253
+ @file_breaks = nil
250
254
  true
251
255
  end
252
256
 
@@ -257,11 +261,26 @@ module Bible270
257
261
  # Bible270.config.chapter_breaks_path. The file is re-read whenever it
258
262
  # changes, so break points can be tuned without restarting the server.
259
263
 
264
+ # Keep the public result mutable without exposing the internal cache.
260
265
  def configured_breaks
261
- base = CHAPTER_BREAKS.merge(config_breaks)
266
+ cached_configured_breaks.to_h { |(book, chapter), points| [[book.dup, chapter], points.dup] }
267
+ end
268
+
269
+ def cached_configured_breaks
270
+ # Normalization snapshots mutable override arrays on every lookup.
271
+ overrides = config_breaks
262
272
  path = breaks_file_path
263
- path ? base.merge(file_breaks(path)) : base
273
+ from_file = file_breaks(path) if path
274
+ fingerprint = [CHAPTER_BREAKS, overrides, path && @file_breaks_stamp, from_file]
275
+ return @configured_breaks if @break_source_fingerprint == fingerprint
276
+
277
+ merged = CHAPTER_BREAKS.merge(overrides)
278
+ merged.merge!(from_file) if from_file
279
+ @configured_breaks = merged.freeze
280
+ @break_source_fingerprint = fingerprint
281
+ @configured_breaks
264
282
  end
283
+ private_class_method :cached_configured_breaks
265
284
 
266
285
  def config_breaks
267
286
  return {} unless bible270_config.respond_to?(:chapter_breaks)
@@ -284,11 +303,12 @@ module Bible270
284
303
  # not re-parsed on every request.
285
304
  def file_breaks(path)
286
305
  stat = File.stat(path)
287
- stamp = [path, stat.mtime.to_f, stat.size]
306
+ stamp = [path.dup, stat.mtime.to_f, stat.size]
288
307
  return @file_breaks if @file_breaks_stamp == stamp
289
308
 
309
+ parsed = parse_breaks_file(path)
290
310
  @file_breaks_stamp = stamp
291
- @file_breaks = parse_breaks_file(path)
311
+ @file_breaks = parsed
292
312
  end
293
313
 
294
314
  def parse_breaks_file(path)
@@ -0,0 +1,109 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'digest'
4
+ require 'json'
5
+ require 'securerandom'
6
+
7
+ module Bible270
8
+ class ScriptureFrameRotation
9
+ SESSION_KEY = 'bible270_scripture_frame_rotation'
10
+ COLUMN = 'scripture_frame_rotation'
11
+ HEX_DIGEST = %r{\A[0-9a-f]{64}\z}
12
+ SEED = %r{\A[0-9a-f]{16}\z}
13
+ private_constant :COLUMN, :HEX_DIGEST, :SEED
14
+
15
+ def self.select(pool, reader: nil, session: nil, exclude: nil)
16
+ rotation = new(pool, exclude: exclude)
17
+ if reader&.persisted? && Reader.column_names.include?(COLUMN)
18
+ # Never lock the request's reader: it may carry unsaved profile changes.
19
+ locked = Reader.find(reader.id)
20
+ locked.with_lock do
21
+ frame, state = rotation.advance(locked[COLUMN])
22
+ locked.update_column(COLUMN, state) unless locked[COLUMN] == state
23
+ frame
24
+ end
25
+ else
26
+ rotation.select_from_session(session, reader)
27
+ end
28
+ end
29
+
30
+ def initialize(pool, exclude: nil)
31
+ @pool = pool.sort_by(&:id)
32
+ @catalog = Digest::SHA256.hexdigest(JSON.generate(@pool.map(&:id)))
33
+ @exclude = exclude if exclude.is_a?(String)
34
+ end
35
+
36
+ def select_from_session(session, reader)
37
+ return @pool.reject { |frame| @pool.length > 1 && frame.id == @exclude }.sample unless session
38
+
39
+ identity = reader&.id ? "reader:#{reader.id}" : 'visitor'
40
+ entry = session[SESSION_KEY]
41
+ previous = entry['state'] if entry.is_a?(Hash) && entry['identity'] == identity
42
+ frame, state = advance(previous)
43
+ session[SESSION_KEY] = { 'identity' => identity, 'state' => state }
44
+ frame
45
+ end
46
+
47
+ def advance(previous)
48
+ return [nil, {}] if @pool.empty? && !last_digest(previous)
49
+
50
+ state = valid_state?(previous) ? previous.dup : fresh_state(last_digest(previous))
51
+ state['deferred'] = state['deferred'].dup
52
+ return [nil, state] if @pool.empty?
53
+
54
+ state = fresh_state(state['last']) if state['cursor'] == @pool.length && state['deferred'].empty?
55
+ order = @pool.shuffle(random: Random.new(state['seed'].to_i(16)))
56
+ position = next_position(order, state)
57
+ frame = order[position]
58
+ state['deferred'].delete(position)
59
+ state['last'] = Digest::SHA256.hexdigest(frame.id)
60
+ [frame, state]
61
+ end
62
+
63
+ private
64
+
65
+ def fresh_state(last)
66
+ { 'version' => 1, 'catalog' => @catalog, 'seed' => SecureRandom.hex(8),
67
+ 'cursor' => 0, 'deferred' => [], 'last' => last }
68
+ end
69
+
70
+ def last_digest(state)
71
+ state['last'] if state.is_a?(Hash) && state['last'].is_a?(String) && HEX_DIGEST.match?(state['last'])
72
+ end
73
+
74
+ def valid_state?(state)
75
+ return false unless state.is_a?(Hash) && state.size == 6 && (state.keys - %w[catalog cursor deferred last seed version]).empty?
76
+ return false unless state['version'] == 1 && state['catalog'] == @catalog
77
+ return false unless state['seed'].is_a?(String) && SEED.match?(state['seed'])
78
+ return false unless state['last'].nil? || last_digest(state)
79
+
80
+ valid_positions?(state['cursor'], state['deferred'])
81
+ end
82
+
83
+ def valid_positions?(cursor, deferred)
84
+ cursor.is_a?(Integer) && cursor.between?(0, @pool.length) &&
85
+ deferred.is_a?(Array) && deferred.length <= 2 && deferred.uniq == deferred &&
86
+ deferred.all? { |position| position.is_a?(Integer) && position >= 0 && position < cursor }
87
+ end
88
+
89
+ # At most two positions can be blocked (last and exclude). Keep them unseen
90
+ # rather than dropping them, including when the next request changes exclude.
91
+ def next_position(order, state)
92
+ position = state['deferred'].find { |index| penalty(order[index], state).zero? }
93
+ return position if position
94
+
95
+ while state['cursor'] < order.length
96
+ position = state['cursor']
97
+ state['cursor'] += 1
98
+ return position if penalty(order[position], state).zero?
99
+
100
+ state['deferred'] << position
101
+ end
102
+ state['deferred'].min_by { |index| penalty(order[index], state) }
103
+ end
104
+
105
+ def penalty(frame, state)
106
+ (Digest::SHA256.hexdigest(frame.id) == state['last'] ? 2 : 0) + (frame.id == @exclude ? 1 : 0)
107
+ end
108
+ end
109
+ end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'yaml'
4
4
  require 'bible270/translations'
5
+ require 'bible270/scripture_frame_rotation'
5
6
 
6
7
  module Bible270
7
8
  module ScriptureFrames
@@ -156,7 +157,7 @@ module Bible270
156
157
  end
157
158
  private_class_method :default_disable_setting
158
159
 
159
- def random(exclude: nil)
160
+ def random(exclude: nil, reader: nil, session: nil)
160
161
  disabled_ids = disabled_default_ids
161
162
  pool = defaults.reject { |frame| disabled_ids.include?(frame.id) }
162
163
  if custom_available?
@@ -165,6 +166,8 @@ module Bible270
165
166
  translation: frame.translation, text: frame.text, attribution: frame.attribution)
166
167
  end
167
168
  end
169
+ return ScriptureFrameRotation.select(pool, reader: reader, session: session, exclude: exclude) if reader || session
170
+
168
171
  pool = pool.reject { |frame| frame.id == exclude } if pool.length > 1 && exclude.is_a?(String)
169
172
  pool.sample
170
173
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bible270
4
- VERSION = '1.18.1'
4
+ VERSION = '1.20.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bible270
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.18.1
4
+ version: 1.20.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew vonderLuft
@@ -245,6 +245,7 @@ files:
245
245
  - app/views/bible270/shared/_scripture_frame_ui.html.erb
246
246
  - app/views/bible270/shared/_scripture_library_ui.html.erb
247
247
  - app/views/bible270/shared/_scripture_popups.html.erb
248
+ - app/views/bible270/shared/_scripture_preview_ui.html.erb
248
249
  - app/views/bible270/shared/_styles.html.erb
249
250
  - app/views/bible270/shared/_theme_scenery.html.erb
250
251
  - app/views/bible270/shared/_theme_ui.html.erb
@@ -283,6 +284,7 @@ files:
283
284
  - db/migrate/20260101000026_add_revert_to_bible270_plan_runs.rb
284
285
  - db/migrate/20260101000027_create_bible270_scripture_frames.rb
285
286
  - db/migrate/20260101000028_create_bible270_progress_sync.rb
287
+ - db/migrate/20260101000029_add_scripture_frame_rotation_to_bible270_readers.rb
286
288
  - lib/bible270.rb
287
289
  - lib/bible270/avatar_backfill.rb
288
290
  - lib/bible270/avatar_images.rb
@@ -303,6 +305,7 @@ files:
303
305
  - lib/bible270/progress_sync/client.rb
304
306
  - lib/bible270/reader_consistency.rb
305
307
  - lib/bible270/reader_progress_report.rb
308
+ - lib/bible270/scripture_frame_rotation.rb
306
309
  - lib/bible270/scripture_frames.rb
307
310
  - lib/bible270/translations.rb
308
311
  - lib/bible270/versification.rb