comfy_middle_seat 4.5.0 → 4.7.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.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rubyonrails.yml +21 -4
  3. data/CHANGELOG.md +31 -1
  4. data/README.md +41 -1
  5. data/app/assets/javascripts/comfy/admin/cms/diff.js +178 -10
  6. data/app/assets/stylesheets/comfy/admin/cms/base.sass +88 -0
  7. data/app/assets/stylesheets/comfy/admin/cms/harbor.sass +4 -0
  8. data/app/controllers/comfy/admin/cms/snippets_controller.rb +9 -0
  9. data/app/controllers/comfy/admin/cms/tag_usage_controller.rb +20 -0
  10. data/app/helpers/comfy/admin/cms/tag_usage_helper.rb +21 -0
  11. data/app/models/comfy/cms/layout.rb +1 -1
  12. data/app/views/comfy/admin/cms/revisions/show.html.haml +44 -35
  13. data/app/views/comfy/admin/cms/snippets/_usage.html.haml +8 -0
  14. data/app/views/comfy/admin/cms/snippets/edit.html.haml +6 -0
  15. data/app/views/comfy/admin/cms/snippets/index.html.haml +18 -10
  16. data/app/views/comfy/admin/cms/tag_usage/_source.html.haml +2 -0
  17. data/app/views/comfy/admin/cms/tag_usage/index.html.haml +54 -0
  18. data/app/views/layouts/comfy/admin/cms/_left.html.haml +3 -0
  19. data/config/initializers/comfy_middle_seat.rb +3 -3
  20. data/config/locales/ar.yml +23 -0
  21. data/config/locales/ca.yml +23 -0
  22. data/config/locales/cs.yml +23 -0
  23. data/config/locales/da.yml +23 -0
  24. data/config/locales/de.yml +23 -0
  25. data/config/locales/en.yml +23 -0
  26. data/config/locales/es.yml +23 -0
  27. data/config/locales/fi.yml +23 -0
  28. data/config/locales/fr.yml +23 -0
  29. data/config/locales/gr.yml +23 -0
  30. data/config/locales/hr.yml +23 -0
  31. data/config/locales/it.yml +23 -0
  32. data/config/locales/ja.yml +23 -0
  33. data/config/locales/nb.yml +23 -0
  34. data/config/locales/nl.yml +23 -0
  35. data/config/locales/pl.yml +23 -0
  36. data/config/locales/pt-BR.yml +23 -0
  37. data/config/locales/ru.yml +23 -0
  38. data/config/locales/sk.yml +23 -0
  39. data/config/locales/sv.yml +23 -0
  40. data/config/locales/tr.yml +23 -0
  41. data/config/locales/uk.yml +23 -0
  42. data/config/locales/zh-CN.yml +23 -0
  43. data/config/locales/zh-TW.yml +23 -0
  44. data/lib/comfy_middle_seat/configuration.rb +3 -3
  45. data/lib/comfy_middle_seat/content/snippet_usage.rb +44 -0
  46. data/lib/comfy_middle_seat/content/tag_usage.rb +129 -0
  47. data/lib/comfy_middle_seat/content/tag_usage_report.rb +83 -0
  48. data/lib/comfy_middle_seat/content/tags/helper.rb +1 -1
  49. data/lib/comfy_middle_seat/content/tags/mixins/file_content.rb +6 -10
  50. data/lib/comfy_middle_seat/content.rb +3 -0
  51. data/lib/comfy_middle_seat/routing.rb +1 -0
  52. data/lib/comfy_middle_seat/version.rb +1 -1
  53. data/lib/tasks/cms_tag_usage.rake +32 -0
  54. metadata +10 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5f6717192c25596be740e0176e1ae1f6e4b0bd5dd07a71a5f7a8271ad047fc10
4
- data.tar.gz: 7c18f5c772a0ee0a8bab66870066d515b6977a5a962484479eccf5a7c2d9525b
3
+ metadata.gz: 9aea480edb52b3ea05d811492c0b4fe541cc51d1b1ca176ec190f5401c89ff9a
4
+ data.tar.gz: c9af8b6591f8bfbbef7f5f17c12130054cdeea7b0d849eda4706c36beed36fee
5
5
  SHA512:
6
- metadata.gz: b940efa50666b34b7963839d60fa6265ce5f84566c959388e981cf9e29c02757d9e37a330c59150cebe1c09a27e8c6d2bd72f040922664e7ef39cc37aadd7195
7
- data.tar.gz: '088311053691f043a38462dd1f9b84d57c6a8fff0ae88afe97803d339dc1feceacefff99c99d6b3c52ab0627fe50d324634680e22e8878d0565df78e13be0142'
6
+ metadata.gz: b9921cfa150e2baddb3cc24e3cfc60966ed7748d2f25c679621e416fb3eb4a3d133874df0c03d233ce29790139c0ee873beced5ede7f949a1260f223013ec694
7
+ data.tar.gz: e0eca3efafc057e60b0c0750f88fb637229ad9462ea1bdcc75b4856b85dd7eb7c3ddd31561625ee01413d58162df887b845995509a65a58a1400eb2eb7cdb265
@@ -26,7 +26,7 @@ jobs:
26
26
  SKIP_COV: true
27
27
  steps:
28
28
  - name: Checkout source
29
- uses: actions/checkout@v2
29
+ uses: actions/checkout@v4
30
30
 
31
31
  - name: Install Node.js
32
32
  uses: actions/setup-node@v4
@@ -59,10 +59,27 @@ jobs:
59
59
  - name: Lint the code
60
60
  run: bin/bundle exec rubocop --parallel
61
61
 
62
- - name: Audit for security
62
+ - name: Audit application security
63
+ run: bin/bundle exec brakeman -q -w3
64
+
65
+ - name: Audit dependencies
66
+ id: dependency_audit
67
+ # Retain Rails 7.2 compatibility tests while its dependency findings remain visible.
68
+ # Restore a required audit when patched dependencies are available.
69
+ continue-on-error: ${{ matrix.rails-version == '7.2' }}
70
+ run: bin/bundle exec bundler-audit --update --gemfile-lock gemfiles/${{ matrix.rails-version }}.gemfile.lock
71
+
72
+ - name: Report Rails 7.2 dependency audit failure
73
+ if: ${{ matrix.rails-version == '7.2' && steps.dependency_audit.outcome == 'failure' }}
63
74
  run: |
64
- bin/bundle exec brakeman -q -w3
65
- bin/bundle exec bundler-audit --update --gemfile-lock gemfiles/${{ matrix.rails-version }}.gemfile.lock
75
+ echo "::warning title=Rails 7.2 dependency audit::Dependency audit did not pass. Rails 7.2 compatibility checks remain required; review the audit output and use patched Rails dependencies in production."
76
+ cat >> "$GITHUB_STEP_SUMMARY" <<'SUMMARY'
77
+ ### Rails 7.2 dependency audit did not pass
78
+
79
+ Rails 7.2 remains compatibility-tested, but its dependency audit is temporarily advisory-only because security findings currently have no patched 7.2 release. Review the audit output for findings or execution errors; a passing job does not mean these dependencies are secure.
80
+
81
+ Tests, lint, and Brakeman remain required. Dependency audits remain required on Rails 8.0 and 8.1. Restore a required Rails 7.2 audit when patched dependencies are available.
82
+ SUMMARY
66
83
 
67
84
  system_tests:
68
85
  name: System tests (Ruby 4.0, Rails 8.1)
data/CHANGELOG.md CHANGED
@@ -14,7 +14,35 @@ This changelog follows the project's lineage: **Comfortable Mexican Sofa → Com
14
14
 
15
15
  ### Added
16
16
 
17
+ - Link to layouts, pages, and snippets that use each snippet.
18
+
19
+ ### Changed
20
+
21
+ - Keep Rails 7.2 compatibility checks required, with dependency audit failures shown as warnings.
22
+ - Keep dependency audits required on Rails 8.0 and 8.1.
23
+
24
+ ## [v4.6.0] - 2026-11-07
25
+
26
+ ### Added
27
+
28
+ - List partials, helpers, and templates in the admin, with usage links and permission status.
29
+ - Audit tag usage from the command line and export candidate allowlists.
30
+
31
+ ### Fixed
32
+
33
+ - Escape labels and attributes in file links and images.
34
+ - Clear cached page content when deleting layouts.
35
+ - Check helper permissions without modifying configuration.
36
+ - Run image-processing tests on Rails 7.2 and 8.0.
37
+
38
+ **Upgrading:** Clear rendered page and translation caches to apply escaped file markup. File labels containing HTML now display as text. No database migration or permission-policy change.
39
+
40
+ ## [v4.5.0] - 2026-10-25
41
+
42
+ ### Added
43
+
17
44
  - Add `layout_asset`, `render_partial`, and `render_template` aliases; existing tags remain supported.
45
+ - Find and expand the new aliases in editor completion.
18
46
 
19
47
  ### Changed
20
48
 
@@ -286,7 +314,9 @@ First release of `comfortable_media_surfer`. This new gem is a revival of [Comfo
286
314
 
287
315
  - Rebranded **ComfortableMexicanSofa** as **ComfortableMediaSurfer** in order to publish new gem (database table names and schema have not changed).
288
316
 
289
- [Unreleased]: https://github.com/avonderluft/comfy-middle-seat/compare/v4.4.0...master
317
+ [Unreleased]: https://github.com/avonderluft/comfy-middle-seat/compare/v4.6.0...master
318
+ [v4.6.0]: https://github.com/avonderluft/comfy-middle-seat/compare/v4.5.0...v4.6.0
319
+ [v4.5.0]: https://github.com/avonderluft/comfy-middle-seat/compare/v4.4.0...v4.5.0
290
320
  [v4.4.0]: https://github.com/avonderluft/comfy-middle-seat/compare/v4.3.0...v4.4.0
291
321
  [v4.3.0]: https://github.com/avonderluft/comfy-middle-seat/compare/v4.2.0...v4.3.0
292
322
  [v4.2.0]: https://github.com/avonderluft/comfy-middle-seat/compare/v4.1.0...v4.2.0
data/README.md CHANGED
@@ -47,6 +47,10 @@ Comfy Middle Seat is best suited to Rails applications that render their own web
47
47
  - Stable `comfy_cms_*` database tables for upgrades from Sofa and Surfer.
48
48
  - CI coverage across current Ruby and Rails releases.
49
49
 
50
+ ### Rails compatibility and security
51
+
52
+ Rails 7.2 remains compatibility-tested, with tests, lint, and Brakeman required in CI. Its dependency audit is temporarily advisory-only because current security findings have no patched 7.2 release; failures remain visible in CI logs, warnings, and job summaries. Dependency audits remain required on Rails 8.0 and 8.1. Use a Rails release patched for current advisories in production; passing compatibility tests is not a security guarantee.
53
+
50
54
  ## Quick Start
51
55
 
52
56
  Add the gem to your Rails application's `Gemfile`:
@@ -132,6 +136,29 @@ These names are interchangeable; existing tags remain supported:
132
136
 
133
137
  Aliases preserve all parameters, defaults, and existing allowlist behavior. No new allowlist requirement or content migration is introduced. Asset tags still require `type: css` or `type: js`; omitting the type does not default to CSS. Their URLs follow the configured Rails routes, not an independent manual override of `public_cms_path`. HTML attributes are preserved, though formatting may differ. Check for conflicts if your application already registers custom tags with these alias names.
134
138
 
139
+ ### Tag usage audit
140
+
141
+ Open **Tag usage** in the admin navigation to list unique partials, helpers, and templates for the selected site. Expand **Used in** for source edit links. The report shows current permissions and candidate allowlists for review; it does not change permissions.
142
+
143
+ For an application-wide inventory, use the Rake task:
144
+
145
+ ```sh
146
+ bin/rails comfy:cms:tag_usage
147
+ bin/rails comfy:cms:tag_usage SITE=default
148
+ bin/rails comfy:cms:tag_usage FORMAT=json
149
+ bin/rails comfy:cms:tag_usage FORMAT=config
150
+ ```
151
+
152
+ `SITE` is a site identifier, not its numeric ID; omit it to scan all sites. `FORMAT` defaults to `text`. JSON includes source locations, scope, permissions, and warnings. Configuration output is a copyable initializer block. Both options can be combined.
153
+
154
+ The scanner reads saved layouts, snippets, page fragments, and translation fragments, including unpublished content. Aliases share one entry; counts refer to distinct source fields, not runtime executions. CMS comments are excluded. No helpers, views, ERB, or pages are executed, and caches are not read or updated.
155
+
156
+ **Review before applying candidate allowlists.** Discovered names—including currently blocked names—are not automatically safe. Allowlists are application-wide, so a single-site report is not sufficient for a multi-site installation. Replacing an allowlist blocks omitted names, including previously approved ones.
157
+
158
+ Warnings identify malformed comments or parameters. They go to stderr, and an incomplete scan exits nonzero while still emitting the partial report. JSON includes the warnings too; generated configuration marks incomplete scans. Unknown sites and unsupported formats also exit nonzero.
159
+
160
+ This is a source inventory, not runtime dependency analysis. It does not scan revisions, unsaved drafts, unimported seed files, layout CSS/JavaScript, application views, or dynamically generated tags. Restoring revisions or importing content can introduce new names; scan again afterward. Concurrent content edits are not a database snapshot, so rescan before changing permissions.
161
+
135
162
  ### Editor shortcuts
136
163
 
137
164
  In HTML and Markdown code editors, type a shortcut and press **Tab** to insert a CMS tag. The parameter placeholder is selected so you can replace it immediately. For example, `;md` inserts `{{ cms:markdown content }}` with `content` selected.
@@ -289,6 +316,19 @@ When adapting upstream examples, use the `comfy_middle_seat` gem, `config/initia
289
316
 
290
317
  ## Upgrading
291
318
 
319
+ ### File-link and image escaping (unreleased)
320
+
321
+ File links and images now escape labels and HTML attributes. Labels containing HTML display as text; URLs, labels, image titles, CSS classes, and file separators otherwise retain their existing behavior. Links opening a new tab include `rel="noopener"`.
322
+
323
+ Clear rendered page and translation caches once after deployment so existing pages use the escaped markup:
324
+
325
+ ```ruby
326
+ Comfy::Cms::Page.update_all(content_cache: nil)
327
+ Comfy::Cms::Translation.update_all(content_cache: nil)
328
+ ```
329
+
330
+ Content regenerates on demand. No database migration is required. Helper, partial, and template permission defaults are unchanged; the new [Tag usage audit](#tag-usage-audit) is read-only.
331
+
292
332
  ### Ancestor-aware publishing (unreleased)
293
333
 
294
334
  Review branches with unpublished ancestors: their descendants will no longer be publicly accessible. No database migration is required. After deploying, clear existing rendered content once from the Rails console so cached navigation follows the new rule:
@@ -380,7 +420,7 @@ Bug reports and focused feature proposals can be opened through [GitHub Issues](
380
420
 
381
421
  ## Acknowledgements
382
422
 
383
- - [Oleg Khabarov](https://github.com/GBH) and the contributors to [Comfortable Mexican Sofa](https://github.com/comfy/comfortable-mexican-sofa), the original Comfy CMS.
423
+ - [Oleg Khabarov](https://github.com/GBH) and the contributors to [Comfortable Mexican Sofa](https://github.com/comfy/comfortable-mexican-sofa), the original Comfy CMS. Recent improvements also draw on Oleg’s ongoing [Sofa 3.0 work](https://github.com/comfy/comfortable-mexican-sofa/pull/971), selectively adapted to preserve compatibility.
384
424
  - [Andrew vonderLuft](https://github.com/avonderluft) for reviving Sofa with the [oCcaMS](https://github.com/avonderluft/occams) project, and carrying it forward.
385
425
  - [ShakaCode](https://github.com/shakacode) for sponsoring the revived project as [Comfortable Media Surfer](https://github.com/shakacode/comfortable-media-surfer).
386
426
  - [Roman Almeida](https://github.com/nasmorn) for contributing the OEM license for [Redactor Text Editor](https://imperavi.com/redactor/).
@@ -1,12 +1,180 @@
1
1
  import jQuery from "jquery";
2
2
 
3
- (() => {
4
- window.CMS.diff = () => {
5
- jQuery(".revision").prettyTextDiff({
6
- cleanup: true,
7
- originalContainer: ".original",
8
- changedContainer: ".current",
9
- diffContainer: ".diff .content",
10
- });
11
- };
12
- })();
3
+ const initialized = new WeakSet();
4
+ const contextLines = 3;
5
+
6
+ function element(tag, className, value) {
7
+ const node = document.createElement(tag);
8
+ node.className = className;
9
+ if (value !== undefined) node.textContent = value;
10
+ return node;
11
+ }
12
+
13
+ function compareLines(diff, before, after) {
14
+ // Encode whole lines as tokens so edits cannot match parts of adjacent lines.
15
+ const tokens = new Map();
16
+ const encode = (lines) => lines.map((line) => {
17
+ if (!tokens.has(line)) tokens.set(line, tokens.size);
18
+ return String.fromCharCode(tokens.get(line));
19
+ }).join("");
20
+ const oldLines = encode(before);
21
+ const newLines = encode(after);
22
+
23
+ if (tokens.size > 65536) {
24
+ return [[-1, before.length], [1, after.length]];
25
+ }
26
+ return diff.diff_main(oldLines, newLines, false).map(([type, lines]) => [type, lines.length]);
27
+ }
28
+
29
+ function lineCell(line, number, type, pieces) {
30
+ if (line === undefined) return element("div", "revision-cell revision-empty");
31
+
32
+ const cell = element("div", `revision-cell revision-${type}`);
33
+ const marker = { added: "+", removed: "−", context: "" }[type];
34
+ const code = element("code", "revision-code");
35
+ for (const [changed, text] of pieces || [[false, line]]) {
36
+ code.append(changed ? element(type === "added" ? "ins" : "del", "", text) : text);
37
+ }
38
+
39
+ cell.append(element("span", "revision-line-number", number),
40
+ element("span", "revision-marker", marker), code);
41
+ return cell;
42
+ }
43
+
44
+ function renderSection(section, diff, labels, changes, gaps) {
45
+ const source = section.querySelector(".revision-source");
46
+ const output = section.querySelector("[data-revision-lines]");
47
+ const readLines = (selector) => source.querySelector(selector).textContent.match(/[^\n]*\n|[^\n]+$/g) || [];
48
+ const before = readLines("[data-revision-before]");
49
+ const after = readLines("[data-revision-after]");
50
+ const edits = compareLines(diff, before, after);
51
+ let oldIndex = 0;
52
+ let newIndex = 0;
53
+ output.replaceChildren();
54
+
55
+ function contextRows(container, count) {
56
+ for (let line = 0; line < count; line++) {
57
+ const row = element("div", "revision-row revision-context-row");
58
+ row.append(lineCell(before[oldIndex], ++oldIndex, "context"),
59
+ lineCell(after[newIndex], ++newIndex, "context"));
60
+ container.append(row);
61
+ }
62
+ }
63
+
64
+ for (let index = 0; index < edits.length;) {
65
+ const [type, count] = edits[index];
66
+ if (type === 0) {
67
+ const leading = index > 0 ? Math.min(count, contextLines) : 0;
68
+ const trailing = index < edits.length - 1 ? Math.min(count - leading, contextLines) : 0;
69
+ const collapsed = count - leading - trailing;
70
+ contextRows(output, leading);
71
+ if (collapsed) {
72
+ const gap = element("details", "revision-gap");
73
+ gap.append(element("summary", "", labels.unchangedLines.replace("%{lines}", collapsed)));
74
+ contextRows(gap, collapsed);
75
+ output.append(gap);
76
+ gaps.push(gap);
77
+ }
78
+ contextRows(output, trailing);
79
+ index++;
80
+ continue;
81
+ }
82
+
83
+ const block = element("div", "revision-change");
84
+ let removed = 0;
85
+ let added = 0;
86
+ while (index < edits.length && edits[index][0] !== 0) {
87
+ const [operation, length] = edits[index++];
88
+ if (operation < 0) removed += length;
89
+ else added += length;
90
+ }
91
+
92
+ for (let line = 0; line < Math.max(removed, added); line++) {
93
+ const oldLine = line < removed ? before[oldIndex] : undefined;
94
+ const newLine = line < added ? after[newIndex] : undefined;
95
+ let oldPieces;
96
+ let newPieces;
97
+ if (oldLine !== undefined && newLine !== undefined) {
98
+ const pieces = diff.diff_main(oldLine.replace(/\n$/, ""), newLine.replace(/\n$/, ""), false);
99
+ oldPieces = pieces.filter(([operation]) => operation <= 0).map(([operation, text]) => [operation !== 0, text]);
100
+ newPieces = pieces.filter(([operation]) => operation >= 0).map(([operation, text]) => [operation !== 0, text]);
101
+ }
102
+ const row = element("div", "revision-row");
103
+ row.append(lineCell(oldLine, oldLine === undefined ? null : ++oldIndex, "removed", oldPieces),
104
+ lineCell(newLine, newLine === undefined ? null : ++newIndex, "added", newPieces));
105
+ block.append(row);
106
+ }
107
+ output.append(block);
108
+ changes.push(block);
109
+ }
110
+ if (!edits.length) output.append(element("p", "text-muted px-2", labels.noChanges));
111
+ source.hidden = true;
112
+ }
113
+
114
+ function initializeComparison(comparison) {
115
+ if (initialized.has(comparison)) return;
116
+ initialized.add(comparison);
117
+
118
+ const diff = new window.diff_match_patch();
119
+ const changes = [];
120
+ const gaps = [];
121
+ const labels = comparison.dataset;
122
+ for (const section of comparison.querySelectorAll(".revision")) {
123
+ renderSection(section, diff, labels, changes, gaps);
124
+ }
125
+
126
+ const toolbar = comparison.querySelector(".revision-toolbar");
127
+ const view = toolbar.querySelector("[data-revision-view]");
128
+ const context = toolbar.querySelector("[data-revision-context]");
129
+ const position = toolbar.querySelector("[data-revision-position]");
130
+ const previous = toolbar.querySelector("[data-revision-previous]");
131
+ const next = toolbar.querySelector("[data-revision-next]");
132
+ let active = 0;
133
+
134
+ function showChange(index, scroll = false) {
135
+ changes[active]?.classList.remove("revision-change-active");
136
+ active = index;
137
+ changes[active]?.classList.add("revision-change-active");
138
+ previous.disabled = active === 0;
139
+ next.disabled = active >= changes.length - 1;
140
+ position.textContent = changes.length
141
+ ? labels.changePosition.replace("%{position}", active + 1).replace("%{total}", changes.length)
142
+ : labels.noChanges;
143
+ if (scroll) {
144
+ const toolbarTop = parseFloat(window.getComputedStyle(toolbar).top);
145
+ changes[active].style.scrollMarginTop = `${toolbarTop + toolbar.offsetHeight + 12}px`;
146
+ changes[active].scrollIntoView({ block: "start" });
147
+ }
148
+ }
149
+
150
+ function updateContextButton() {
151
+ const allOpen = gaps.every((gap) => gap.open);
152
+ context.textContent = allOpen ? labels.collapseUnchanged : labels.showFullContent;
153
+ }
154
+
155
+ view.value = window.matchMedia("(max-width: 767px)").matches ? "unified" : "split";
156
+ comparison.dataset.view = view.value;
157
+ view.addEventListener("change", () => { comparison.dataset.view = view.value; });
158
+ previous.addEventListener("click", () => showChange(active - 1, true));
159
+ next.addEventListener("click", () => showChange(active + 1, true));
160
+ context.hidden = gaps.length === 0;
161
+ context.textContent = labels.showFullContent;
162
+ context.addEventListener("click", () => {
163
+ const open = gaps.some((gap) => !gap.open);
164
+ gaps.forEach((gap) => { gap.open = open; });
165
+ updateContextButton();
166
+ });
167
+ gaps.forEach((gap) => gap.addEventListener("toggle", updateContextButton));
168
+ showChange(0);
169
+ toolbar.hidden = false;
170
+ }
171
+
172
+ window.CMS.diff = () => {
173
+ document.querySelectorAll(".revision-comparison").forEach(initializeComparison);
174
+ jQuery(".revision:has(.diff)").prettyTextDiff({
175
+ cleanup: true,
176
+ originalContainer: ".original",
177
+ changedContainer: ".current",
178
+ diffContainer: ".diff .content",
179
+ });
180
+ };
@@ -252,6 +252,94 @@ body#comfy
252
252
  del
253
253
  background-color: #ffc6c6
254
254
 
255
+ .revision-comparison
256
+ .revision-summary
257
+ padding: 0
258
+ border: 0
259
+ .revision-selection, .revision-controls, .revision-navigation
260
+ display: flex
261
+ flex-wrap: wrap
262
+ align-items: center
263
+ gap: 0.5rem
264
+ .revision-toolbar
265
+ position: sticky
266
+ top: 0
267
+ z-index: 10
268
+ background: $white
269
+ border-bottom: 1px solid $gray-300
270
+ @media (max-width: map-get($grid-breakpoints, lg))
271
+ top: 3rem
272
+ .revision-controls
273
+ padding: 0.5rem 0
274
+ .revision-navigation
275
+ margin-left: auto
276
+ .revision-headings, .revision-row, .revision-source
277
+ display: grid
278
+ grid-template-columns: repeat(2, minmax(0, 1fr))
279
+ .revision-source[hidden]
280
+ display: none
281
+ .revision-headings span
282
+ padding: 0.4rem 0.65rem
283
+ background: $gray-100
284
+ font-weight: bold
285
+ .revision .label
286
+ padding: 0.65rem
287
+ margin: 0
288
+ background: $gray-100
289
+ overflow-wrap: anywhere
290
+ .revision-lines
291
+ border: 1px solid $gray-300
292
+ margin-bottom: 1rem
293
+ .revision-cell
294
+ display: grid
295
+ grid-template-columns: minmax(3ch, auto) 1ch minmax(0, 1fr)
296
+ align-content: start
297
+ gap: 0.5rem
298
+ min-width: 0
299
+ padding: 0.15rem 0.5rem
300
+ font-family: $font-family-monospace
301
+ font-size: 0.875rem
302
+ & + .revision-cell
303
+ border-left: 1px solid $gray-300
304
+ .revision-line-number, .revision-marker
305
+ color: $gray-700
306
+ text-align: right
307
+ user-select: none
308
+ .revision-code
309
+ color: inherit
310
+ font-size: inherit
311
+ white-space: pre-wrap
312
+ overflow-wrap: anywhere
313
+ tab-size: 2
314
+ .revision-added
315
+ background: #e6f7e9
316
+ ins
317
+ background: #b5ebc1
318
+ text-decoration: none
319
+ .revision-removed
320
+ background: #fce8e7
321
+ del
322
+ background: #ffc7c2
323
+ text-decoration: none
324
+ .revision-empty
325
+ background: $gray-100
326
+ .revision-change-active
327
+ outline: 2px solid $primary
328
+ outline-offset: -2px
329
+ position: relative
330
+ .revision-gap > summary
331
+ padding: 0.35rem 0.65rem
332
+ color: $primary
333
+ background: $gray-100
334
+ cursor: pointer
335
+ &[data-view="unified"]
336
+ .revision-row
337
+ display: block
338
+ .revision-cell + .revision-cell
339
+ border-left: 0
340
+ .revision-empty, .revision-context-row .revision-cell:first-child
341
+ display: none
342
+
255
343
  #cms-uploader
256
344
  ul.list
257
345
  .file-path
@@ -85,6 +85,10 @@ body#comfy
85
85
  color: $gray-600
86
86
  li.sortable-ghost > .row, li.sortable-chosen > .row, &:not(.sortable-active) > li > .row:hover
87
87
  background-color: $harbor-tint
88
+ li.snippet-unused > .row
89
+ background-color: theme-color-level("warning", $alert-bg-level)
90
+ &:not(.sortable-active) > li.snippet-unused > .row:hover
91
+ background-color: theme-color-level("warning", $alert-border-level)
88
92
 
89
93
  #cms-right
90
94
  .box
@@ -5,6 +5,8 @@ class Comfy::Admin::Cms::SnippetsController < Comfy::Admin::Cms::BaseController
5
5
 
6
6
  self.reorder_action_resource = ::Comfy::Cms::Snippet
7
7
 
8
+ helper Comfy::Admin::Cms::TagUsageHelper
9
+
8
10
  before_action :build_snippet, only: %i[new create]
9
11
  before_action :load_snippet, only: %i[edit update destroy]
10
12
  before_action :authorize
@@ -13,6 +15,7 @@ class Comfy::Admin::Cms::SnippetsController < Comfy::Admin::Cms::BaseController
13
15
  return redirect_to action: :new if @site.snippets.none?
14
16
 
15
17
  @snippets = @site.snippets.includes(:categories).for_category(params[:categories]).order(:position)
18
+ load_snippet_usage(@snippets)
16
19
  end
17
20
 
18
21
  def new
@@ -21,6 +24,7 @@ class Comfy::Admin::Cms::SnippetsController < Comfy::Admin::Cms::BaseController
21
24
 
22
25
  def edit
23
26
  @snippet.attributes = snippet_params
27
+ load_snippet_usage([@snippet])
24
28
  end
25
29
 
26
30
  def create
@@ -38,6 +42,7 @@ class Comfy::Admin::Cms::SnippetsController < Comfy::Admin::Cms::BaseController
38
42
  redirect_to action: :edit, id: @snippet
39
43
  rescue ActiveRecord::RecordInvalid
40
44
  flash.now[:danger] = I18n.t('comfy.admin.cms.snippets.update_failure')
45
+ load_snippet_usage([@snippet])
41
46
  render action: :edit
42
47
  end
43
48
 
@@ -49,6 +54,10 @@ class Comfy::Admin::Cms::SnippetsController < Comfy::Admin::Cms::BaseController
49
54
 
50
55
  protected
51
56
 
57
+ def load_snippet_usage(snippets)
58
+ @snippet_usage = ComfyMiddleSeat::Content::SnippetUsage.new(site: @site, snippets: snippets).call
59
+ end
60
+
52
61
  def build_snippet
53
62
  @snippet = @site.snippets.new(snippet_params)
54
63
  end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Comfy::Admin::Cms::TagUsageController < Comfy::Admin::Cms::BaseController
4
+ before_action :authorize
5
+
6
+ def index
7
+ @report = ComfyMiddleSeat::Content::TagUsage.new(
8
+ sites: Comfy::Cms::Site.where(id: @site.id), scope: 'selected_sites'
9
+ ).call
10
+ @candidate_config = ComfyMiddleSeat::Content::TagUsageReport.new(@report).config
11
+ end
12
+
13
+ protected
14
+
15
+ def load_admin_site
16
+ # A report must never silently inventory a different site from the requested one.
17
+ @site = Comfy::Cms::Site.find(params[:site_id])
18
+ session[:site_id] = @site.id
19
+ end
20
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Comfy::Admin::Cms::TagUsageHelper
4
+ def tag_usage_source_path(source)
5
+ case source[:type]
6
+ when 'layout'
7
+ edit_comfy_admin_cms_site_layout_path(source[:site_id], source[:id])
8
+ when 'snippet'
9
+ edit_comfy_admin_cms_site_snippet_path(source[:site_id], source[:id])
10
+ when 'page'
11
+ edit_comfy_admin_cms_site_page_path(source[:site_id], source[:id])
12
+ when 'translation'
13
+ edit_comfy_admin_cms_site_page_translation_path(source[:site_id], source[:page_id], source[:id])
14
+ end
15
+ end
16
+
17
+ def tag_usage_source_label(source)
18
+ type = t("activerecord.models.comfy/cms/#{source[:type]}")
19
+ "#{type} ##{source[:id]}: #{source[:label]}"
20
+ end
21
+ end
@@ -18,7 +18,7 @@ class Comfy::Cms::Layout < ActiveRecord::Base
18
18
  after_commit :clear_page_content_cache,
19
19
  on: %i[create update],
20
20
  if: :saved_changes?
21
- after_destroy :clear_page_content_cache
21
+ before_destroy :clear_page_content_cache, prepend: true
22
22
 
23
23
  # -- Validations -------------------------------------------------------------
24
24
  validates :site_id,
@@ -1,9 +1,12 @@
1
- - selected_timestamp = l(@revision.created_at, format: "%Y-%m-%d %H:%M:%S %Z")
1
+ - timestamp_format = "%Y-%m-%d %H:%M:%S %Z"
2
+ - selected_timestamp = l(@revision.created_at, format: timestamp_format)
3
+ - selected_label = t('.revision_number', default: 'Revision #%{id}', id: @revision.id)
4
+ - current_label = t('.current_saved_content', default: 'Current saved content')
2
5
 
3
6
  - content_for :right_column do
4
7
  .box.revisions
5
8
  - @record.revisions.order(created_at: :desc).each do |revision|
6
- - timestamp = l(revision.created_at, format: "%Y-%m-%d %H:%M:%S %Z")
9
+ - timestamp = l(revision.created_at, format: timestamp_format)
7
10
  - label = t('.revision_link', default: 'Revision #%{id} — snapshot replaced at %{timestamp}', id: revision.id, timestamp: timestamp)
8
11
  = active_link_to label, {id: revision.id}, class: "btn btn-sm btn-light d-block text-primary text-left mb-1"
9
12
 
@@ -12,43 +15,49 @@
12
15
  = t('.title', default: 'Revisions for')
13
16
  = @record.class.to_s.demodulize
14
17
 
15
- .revision-summary
16
- %h3.h5= t('.selected_revision', default: 'Selected revision #%{id}', id: @revision.id)
17
- %p.mb-2
18
- = t('.snapshot_explanation', default: 'This snapshot contains the content that was replaced at %{timestamp}. The comparison shows how the currently saved content differs from that snapshot.', timestamp: selected_timestamp)
19
- .revision-legend{aria: {label: t('.legend', default: 'Change legend')}}
20
- %span.revision-legend-item
21
- %span.revision-legend-swatch.added{aria: {hidden: true}}
22
- = t('.added', default: 'Added since snapshot')
23
- %span.revision-legend-item
24
- %span.revision-legend-swatch.removed{aria: {hidden: true}}
25
- = t('.removed', default: 'Removed since snapshot')
18
+ .revision-comparison{data: {change_position: t('.change_position', default: 'Change %{position} of %{total}', position: '%{position}', total: '%{total}'), no_changes: t('.no_changes', default: 'No changes'), unchanged_lines: t('.unchanged_lines', default: '%{lines} unchanged lines', lines: '%{lines}'), show_full_content: t('.show_full_content', default: 'Show full content'), collapse_unchanged: t('.collapse_unchanged', default: 'Collapse unchanged lines')}}
19
+ .revision-summary
20
+ .revision-selection
21
+ %strong= selected_label
22
+ %span{aria: {hidden: true}} →
23
+ %strong= current_label
24
+ %p.small.text-muted.mb-2.mt-2
25
+ = t('.snapshot_time', default: 'Snapshot before the save on %{timestamp}', timestamp: selected_timestamp)
26
26
 
27
- .row.d-none.d-lg-flex
28
- .col-lg-10.ml-auto
29
- .row
30
- .col-lg-6
31
- .label= t('.selected_snapshot', default: 'Selected snapshot')
32
- .col-lg-6
33
- .label= t('.current_content', default: 'Current saved content (changes highlighted)')
27
+ .revision-toolbar{hidden: true}
28
+ .revision-controls
29
+ %label.mb-0
30
+ = t('.view', default: 'View')
31
+ %select.form-control.form-control-sm.d-inline-block.w-auto{data: {revision_view: true}}
32
+ %option{value: 'split'}= t('.split', default: 'Split')
33
+ %option{value: 'unified'}= t('.unified', default: 'Unified')
34
+ %button.btn.btn-sm.btn-outline-secondary{type: 'button', data: {revision_context: true}}
35
+ = t('.show_full_content', default: 'Show full content')
36
+ .revision-navigation
37
+ %span{role: 'status', data: {revision_position: true}}
38
+ %button.btn.btn-sm.btn-outline-secondary{type: 'button', aria: {label: t('.previous_change', default: 'Previous change')}, data: {revision_previous: true}} ↑
39
+ %button.btn.btn-sm.btn-outline-secondary{type: 'button', aria: {label: t('.next_change', default: 'Next change')}, data: {revision_next: true}} ↓
40
+ .revision-headings
41
+ %span= selected_label
42
+ %span= current_label
34
43
 
35
- - @current_content.each do |label, content|
36
- .row.revision
37
- .col-lg-2.text-lg-right.bg-light
38
- .label= label
39
- .col-lg-10
40
- .row
41
- .col-lg-6
42
- .content
43
- = safe_join @versioned_content[label].to_s.split("\n"), raw("<br/>")
44
- .col-lg-6.diff
45
- .original.d-none= @versioned_content[label]
46
- .current.d-none= content
47
- .content
44
+ - @current_content.each do |label, content|
45
+ %section.revision
46
+ %h3.h6.label= label
47
+ .revision-source
48
+ %div
49
+ %strong= selected_label
50
+ %pre
51
+ %code{data: {revision_before: true}}= @versioned_content[label].to_s
52
+ %div
53
+ %strong= current_label
54
+ %pre
55
+ %code{data: {revision_after: true}}= content.to_s
56
+ .revision-lines{data: {revision_lines: true}}
48
57
 
49
58
  = comfy_form_with model: @revision, url: {action: :revert} do |form|
50
59
  = form.form_actions do
51
- = submit_tag t('.update', default: 'Restore selected snapshot'), class: 'btn btn-primary'
60
+ = submit_tag t('.restore_revision', default: 'Restore revision #%{id}', id: @revision.id), class: 'btn btn-primary'
52
61
  - if preview_path
53
62
  = link_to t('.preview', default: 'Preview selected snapshot'), preview_path, class: 'btn btn-info', target: 'comfy-cms-revision-preview', rel: 'noopener'
54
- = link_to t('.cancel', default: 'Cancel'), record_path, class: 'btn btn-link'
63
+ = link_to t('.back_to_record', default: 'Back to editor'), record_path, class: 'btn btn-link'