comfy_middle_seat 4.6.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.
- checksums.yaml +4 -4
- data/.github/workflows/rubyonrails.yml +21 -4
- data/CHANGELOG.md +13 -1
- data/README.md +4 -0
- data/app/assets/javascripts/comfy/admin/cms/diff.js +178 -10
- data/app/assets/stylesheets/comfy/admin/cms/base.sass +88 -0
- data/app/assets/stylesheets/comfy/admin/cms/harbor.sass +4 -0
- data/app/controllers/comfy/admin/cms/snippets_controller.rb +9 -0
- data/app/views/comfy/admin/cms/revisions/show.html.haml +44 -35
- data/app/views/comfy/admin/cms/snippets/_usage.html.haml +8 -0
- data/app/views/comfy/admin/cms/snippets/edit.html.haml +6 -0
- data/app/views/comfy/admin/cms/snippets/index.html.haml +18 -10
- data/config/locales/ar.yml +3 -0
- data/config/locales/ca.yml +3 -0
- data/config/locales/cs.yml +3 -0
- data/config/locales/da.yml +3 -0
- data/config/locales/de.yml +3 -0
- data/config/locales/en.yml +3 -0
- data/config/locales/es.yml +3 -0
- data/config/locales/fi.yml +3 -0
- data/config/locales/fr.yml +3 -0
- data/config/locales/gr.yml +3 -0
- data/config/locales/hr.yml +3 -0
- data/config/locales/it.yml +3 -0
- data/config/locales/ja.yml +3 -0
- data/config/locales/nb.yml +3 -0
- data/config/locales/nl.yml +3 -0
- data/config/locales/pl.yml +3 -0
- data/config/locales/pt-BR.yml +3 -0
- data/config/locales/ru.yml +3 -0
- data/config/locales/sk.yml +3 -0
- data/config/locales/sv.yml +3 -0
- data/config/locales/tr.yml +3 -0
- data/config/locales/uk.yml +3 -0
- data/config/locales/zh-CN.yml +3 -0
- data/config/locales/zh-TW.yml +3 -0
- data/lib/comfy_middle_seat/content/snippet_usage.rb +44 -0
- data/lib/comfy_middle_seat/content/tag_usage.rb +9 -4
- data/lib/comfy_middle_seat/content.rb +1 -0
- data/lib/comfy_middle_seat/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9aea480edb52b3ea05d811492c0b4fe541cc51d1b1ca176ec190f5401c89ff9a
|
|
4
|
+
data.tar.gz: c9af8b6591f8bfbbef7f5f17c12130054cdeea7b0d849eda4706c36beed36fee
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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@
|
|
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
|
|
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
|
-
|
|
65
|
-
|
|
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,6 +14,17 @@ 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
|
+
|
|
17
28
|
- List partials, helpers, and templates in the admin, with usage links and permission status.
|
|
18
29
|
- Audit tag usage from the command line and export candidate allowlists.
|
|
19
30
|
|
|
@@ -303,7 +314,8 @@ First release of `comfortable_media_surfer`. This new gem is a revival of [Comfo
|
|
|
303
314
|
|
|
304
315
|
- Rebranded **ComfortableMexicanSofa** as **ComfortableMediaSurfer** in order to publish new gem (database table names and schema have not changed).
|
|
305
316
|
|
|
306
|
-
[Unreleased]: https://github.com/avonderluft/comfy-middle-seat/compare/v4.
|
|
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
|
|
307
319
|
[v4.5.0]: https://github.com/avonderluft/comfy-middle-seat/compare/v4.4.0...v4.5.0
|
|
308
320
|
[v4.4.0]: https://github.com/avonderluft/comfy-middle-seat/compare/v4.3.0...v4.4.0
|
|
309
321
|
[v4.3.0]: https://github.com/avonderluft/comfy-middle-seat/compare/v4.2.0...v4.3.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`:
|
|
@@ -1,12 +1,180 @@
|
|
|
1
1
|
import jQuery from "jquery";
|
|
2
2
|
|
|
3
|
-
(
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
-
|
|
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:
|
|
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-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
= t('.
|
|
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
|
-
.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
.
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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('.
|
|
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('.
|
|
63
|
+
= link_to t('.back_to_record', default: 'Back to editor'), record_path, class: 'btn btn-link'
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
%small.snippet-usage.text-muted.d-block
|
|
2
|
+
- if sources.empty?
|
|
3
|
+
= t('comfy.admin.cms.snippets.usage.no_references')
|
|
4
|
+
- else
|
|
5
|
+
- sources.group_by { |source| source[:type] }.each do |type, group|
|
|
6
|
+
%span.snippet-usage-group.mr-2{data: {source_type: type}}
|
|
7
|
+
= "#{t("comfy.admin.cms.base.#{type.pluralize}")}:"
|
|
8
|
+
= safe_join(group.map { |source| link_to(source[:identifier], tag_usage_source_path(source)) }, ', ')
|
|
@@ -4,6 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|
.page-header
|
|
6
6
|
%h2= t('.title')
|
|
7
|
+
- if @snippet_usage
|
|
8
|
+
- sources = @snippet_usage[:sources_by_id].fetch(@snippet.id, [])
|
|
9
|
+
- if sources.present? || @snippet_usage[:complete]
|
|
10
|
+
%p.text-break.mb-2= render 'usage', sources: sources
|
|
11
|
+
- unless @snippet_usage[:complete]
|
|
12
|
+
%p.small.text-muted= t('comfy.admin.cms.snippets.usage.incomplete')
|
|
7
13
|
|
|
8
14
|
= comfy_form_with model: @snippet, scope: :snippet, url: {action: :update} do |form|
|
|
9
15
|
= render form
|
|
@@ -7,25 +7,33 @@
|
|
|
7
7
|
|
|
8
8
|
= comfy_admin_partial "comfy/admin/cms/partials/snippets_before"
|
|
9
9
|
|
|
10
|
+
- if @snippet_usage && !@snippet_usage[:complete]
|
|
11
|
+
%p.small.text-muted= t('comfy.admin.cms.snippets.usage.incomplete')
|
|
12
|
+
|
|
10
13
|
%ul.list.sortable
|
|
11
14
|
- @snippets.each do |snippet|
|
|
12
|
-
|
|
15
|
+
- sources = @snippet_usage&.dig(:sources_by_id, snippet.id)
|
|
16
|
+
- unused = @snippet_usage&.dig(:complete) && sources.blank?
|
|
17
|
+
%li{class: ('snippet-unused' if unused), data: {id: snippet.id}}
|
|
13
18
|
.row
|
|
14
|
-
.col-md
|
|
19
|
+
.col-12.col-md.item
|
|
15
20
|
.item-controls.d-none.d-lg-block
|
|
16
|
-
- if !params[:categories].present? && @
|
|
21
|
+
- if !params[:categories].present? && @snippets.size > 1
|
|
17
22
|
.dragger
|
|
18
23
|
%i.fas.fa-bars
|
|
19
|
-
.item-content
|
|
24
|
+
.item-content.text-break
|
|
20
25
|
.item-title
|
|
21
26
|
= link_to snippet.label, edit_comfy_admin_cms_site_snippet_path(@site, snippet)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
%span.item-meta.ml-2= snippet.identifier
|
|
28
|
+
- if unused
|
|
29
|
+
%span.sr-only= t('comfy.admin.cms.snippets.usage.no_references')
|
|
30
|
+
- if snippet.categories.present?
|
|
31
|
+
%span.item-categories.ml-2
|
|
32
|
+
= render "comfy/admin/cms/categories/categories", object: snippet
|
|
33
|
+
- if sources.present?
|
|
34
|
+
= render 'usage', sources: sources
|
|
27
35
|
|
|
28
|
-
.col-md-
|
|
36
|
+
.col-12.col-md-auto.d-flex.align-items-center.justify-content-md-end
|
|
29
37
|
.btn-group.btn-group-sm
|
|
30
38
|
= link_to t('.edit'), edit_comfy_admin_cms_site_snippet_path(@site, snippet), class: 'btn btn-outline-secondary'
|
|
31
39
|
= link_to t('.delete'), comfy_admin_cms_site_snippet_path(@site, snippet), method: :delete, data: {confirm: t('.are_you_sure')}, class: 'btn btn-danger'
|
data/config/locales/ar.yml
CHANGED
data/config/locales/ca.yml
CHANGED
|
@@ -230,6 +230,9 @@ ca:
|
|
|
230
230
|
create: Crear el fragment
|
|
231
231
|
cancel: Cancel·la
|
|
232
232
|
update: Actualitza el fragment
|
|
233
|
+
usage:
|
|
234
|
+
no_references: No s'ha trobat cap referència.
|
|
235
|
+
incomplete: La llista d'usos del fragment pot ser incompleta.
|
|
233
236
|
|
|
234
237
|
revisions:
|
|
235
238
|
reverted: S'ha revertit el contingut
|
data/config/locales/cs.yml
CHANGED
data/config/locales/da.yml
CHANGED
|
@@ -230,6 +230,9 @@ da:
|
|
|
230
230
|
create: Opret snippet
|
|
231
231
|
cancel: Annuller
|
|
232
232
|
update: Opdater snippet
|
|
233
|
+
usage:
|
|
234
|
+
no_references: Ingen referencer fundet.
|
|
235
|
+
incomplete: Oversigten over brug af denne snippet kan være ufuldstændig.
|
|
233
236
|
|
|
234
237
|
revisions:
|
|
235
238
|
reverted: Indhold gendannet
|
data/config/locales/de.yml
CHANGED
|
@@ -230,6 +230,9 @@ de:
|
|
|
230
230
|
create: Schnipsel erstellen
|
|
231
231
|
cancel: Abbrechen
|
|
232
232
|
update: Schnipsel speichern
|
|
233
|
+
usage:
|
|
234
|
+
no_references: Keine Verweise gefunden.
|
|
235
|
+
incomplete: Die Liste der Verweise auf den Schnipsel könnte unvollständig sein.
|
|
233
236
|
|
|
234
237
|
revisions:
|
|
235
238
|
reverted: Inhalt wurde aus gewählter Version wiederhergestellt
|
data/config/locales/en.yml
CHANGED
data/config/locales/es.yml
CHANGED
|
@@ -230,6 +230,9 @@ es:
|
|
|
230
230
|
create: Crear Fragmento
|
|
231
231
|
cancel: Cancelar
|
|
232
232
|
update: Actualizar Fragmento
|
|
233
|
+
usage:
|
|
234
|
+
no_references: No se encontraron referencias.
|
|
235
|
+
incomplete: La lista de usos del fragmento puede estar incompleta.
|
|
233
236
|
|
|
234
237
|
revisions:
|
|
235
238
|
reverted: Contenido revertido
|
data/config/locales/fi.yml
CHANGED
|
@@ -230,6 +230,9 @@ fi:
|
|
|
230
230
|
create: Luo koodileike
|
|
231
231
|
cancel: Peru
|
|
232
232
|
update: Päivitä koodileike
|
|
233
|
+
usage:
|
|
234
|
+
no_references: Viittauksia ei löytynyt.
|
|
235
|
+
incomplete: Luettelo koodileikkeen käyttöpaikoista voi olla puutteellinen.
|
|
233
236
|
|
|
234
237
|
revisions:
|
|
235
238
|
reverted: Aiempi sisältö on palautettu
|
data/config/locales/fr.yml
CHANGED
|
@@ -230,6 +230,9 @@ fr:
|
|
|
230
230
|
create: Créer le fragment
|
|
231
231
|
cancel: Annuler
|
|
232
232
|
update: Modifier le fragment
|
|
233
|
+
usage:
|
|
234
|
+
no_references: Aucune référence trouvée.
|
|
235
|
+
incomplete: La liste des références au fragment peut être incomplète.
|
|
233
236
|
|
|
234
237
|
revisions:
|
|
235
238
|
reverted: Contenu restauré
|
data/config/locales/gr.yml
CHANGED
|
@@ -230,6 +230,9 @@ gr:
|
|
|
230
230
|
create: Δημιουργία Snippet
|
|
231
231
|
cancel: Ακύρωση
|
|
232
232
|
update: Ενημέρωση Snippet
|
|
233
|
+
usage:
|
|
234
|
+
no_references: Δεν βρέθηκαν αναφορές.
|
|
235
|
+
incomplete: Η λίστα αναφορών στο Snippet ενδέχεται να μην είναι πλήρης.
|
|
233
236
|
|
|
234
237
|
revisions:
|
|
235
238
|
reverted: Το περιεχόμενο επαναφέρθηκε
|
data/config/locales/hr.yml
CHANGED
|
@@ -230,6 +230,9 @@ hr:
|
|
|
230
230
|
create: Kreiraj isječak
|
|
231
231
|
cancel: Otkaži
|
|
232
232
|
update: Ažuriraj isječak
|
|
233
|
+
usage:
|
|
234
|
+
no_references: Nisu pronađene reference.
|
|
235
|
+
incomplete: Popis referenci na isječak možda nije potpun.
|
|
233
236
|
|
|
234
237
|
revisions:
|
|
235
238
|
reverted: Sadržaj je poništen
|
data/config/locales/it.yml
CHANGED
|
@@ -230,6 +230,9 @@ it:
|
|
|
230
230
|
create: Crea Snippet
|
|
231
231
|
cancel: Cancellare
|
|
232
232
|
update: Modifica Snippet
|
|
233
|
+
usage:
|
|
234
|
+
no_references: Nessun riferimento trovato.
|
|
235
|
+
incomplete: L'elenco dei riferimenti allo snippet potrebbe essere incompleto.
|
|
233
236
|
|
|
234
237
|
revisions:
|
|
235
238
|
reverted: Contenuto ripristinato con successo
|
data/config/locales/ja.yml
CHANGED
data/config/locales/nb.yml
CHANGED
|
@@ -230,6 +230,9 @@ nb:
|
|
|
230
230
|
create: Oprett snutt
|
|
231
231
|
cancel: Cancel
|
|
232
232
|
update: Endre snutt
|
|
233
|
+
usage:
|
|
234
|
+
no_references: Fant ingen referanser.
|
|
235
|
+
incomplete: Listen over referanser til snutten kan være ufullstendig.
|
|
233
236
|
|
|
234
237
|
revisions:
|
|
235
238
|
reverted: Innhold tilbakeført
|
data/config/locales/nl.yml
CHANGED
|
@@ -230,6 +230,9 @@ nl:
|
|
|
230
230
|
create: Snippet Aanmaken
|
|
231
231
|
cancel: Annuleren
|
|
232
232
|
update: Snippet Bijwerken
|
|
233
|
+
usage:
|
|
234
|
+
no_references: Geen verwijzingen gevonden.
|
|
235
|
+
incomplete: De lijst met verwijzingen naar het snippet is mogelijk onvolledig.
|
|
233
236
|
|
|
234
237
|
revisions:
|
|
235
238
|
reverted: Content teruggezet
|
data/config/locales/pl.yml
CHANGED
|
@@ -230,6 +230,9 @@ pl:
|
|
|
230
230
|
create: Utwórz snippet
|
|
231
231
|
cancel: Anuluj
|
|
232
232
|
update: Uaktualnij snippet
|
|
233
|
+
usage:
|
|
234
|
+
no_references: Nie znaleziono odwołań.
|
|
235
|
+
incomplete: Lista odwołań do snippeta może być niepełna.
|
|
233
236
|
|
|
234
237
|
revisions:
|
|
235
238
|
reverted: Zawartość została przywrócona
|
data/config/locales/pt-BR.yml
CHANGED
|
@@ -230,6 +230,9 @@ pt-BR:
|
|
|
230
230
|
create: Criar Fragmento
|
|
231
231
|
cancel: Cancelar
|
|
232
232
|
update: Atualizar Fragmento
|
|
233
|
+
usage:
|
|
234
|
+
no_references: Nenhuma referência encontrada.
|
|
235
|
+
incomplete: A lista de referências ao fragmento pode estar incompleta.
|
|
233
236
|
|
|
234
237
|
revisions:
|
|
235
238
|
reverted: Conteúdo revertido com sucesso.
|
data/config/locales/ru.yml
CHANGED
|
@@ -230,6 +230,9 @@ ru:
|
|
|
230
230
|
create: Создать сниппет
|
|
231
231
|
cancel: Oтменить
|
|
232
232
|
update: Обновить сниппет
|
|
233
|
+
usage:
|
|
234
|
+
no_references: Ссылок не найдено.
|
|
235
|
+
incomplete: Список мест, где используется сниппет, может быть неполным.
|
|
233
236
|
|
|
234
237
|
revisions:
|
|
235
238
|
reverted: Контент возвращен в прежнее состояние
|
data/config/locales/sk.yml
CHANGED
|
@@ -230,6 +230,9 @@ sk:
|
|
|
230
230
|
create: Vytvoriť fragment
|
|
231
231
|
cancel: Zrušiť
|
|
232
232
|
update: Upraviť fragment
|
|
233
|
+
usage:
|
|
234
|
+
no_references: Nenašli sa žiadne odkazy.
|
|
235
|
+
incomplete: Prehľad použitia fragmentu nemusí byť úplný.
|
|
233
236
|
|
|
234
237
|
revisions:
|
|
235
238
|
reverted: Obsah bol obnovený
|
data/config/locales/sv.yml
CHANGED
|
@@ -230,6 +230,9 @@ sv:
|
|
|
230
230
|
create: Skapa Snippet
|
|
231
231
|
cancel: Avbryt
|
|
232
232
|
update: Uppdatera Snippet
|
|
233
|
+
usage:
|
|
234
|
+
no_references: Inga referenser hittades.
|
|
235
|
+
incomplete: Listan över var denna snippet används kan vara ofullständig.
|
|
233
236
|
|
|
234
237
|
revisions:
|
|
235
238
|
reverted: Innehåll återställt
|
data/config/locales/tr.yml
CHANGED
data/config/locales/uk.yml
CHANGED
|
@@ -230,6 +230,9 @@ uk:
|
|
|
230
230
|
create: Створити сніппет
|
|
231
231
|
cancel: Cкасувати
|
|
232
232
|
update: Оновити сніппет
|
|
233
|
+
usage:
|
|
234
|
+
no_references: Посилань не знайдено.
|
|
235
|
+
incomplete: Список місць, де використано сніппет, може бути неповним.
|
|
233
236
|
|
|
234
237
|
revisions:
|
|
235
238
|
reverted: Контент повернутий до попереднього стану
|
data/config/locales/zh-CN.yml
CHANGED
data/config/locales/zh-TW.yml
CHANGED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'cgi'
|
|
4
|
+
|
|
5
|
+
# List the saved records that directly reference each requested snippet.
|
|
6
|
+
class ComfyMiddleSeat::Content::SnippetUsage
|
|
7
|
+
def initialize(site:, snippets:)
|
|
8
|
+
@site = site
|
|
9
|
+
@snippet_ids = snippets.to_h { |snippet| [snippet.identifier_in_database, snippet.id] }
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def call
|
|
13
|
+
return { sources_by_id: {}, complete: true } if @snippet_ids.empty?
|
|
14
|
+
|
|
15
|
+
report = ComfyMiddleSeat::Content::TagUsage.new(sites: [@site], kinds: ['snippet']).call
|
|
16
|
+
entries = report[:entries].select { |entry| @snippet_ids.key?(entry[:name]) }
|
|
17
|
+
records = referenced_records(entries)
|
|
18
|
+
sources_by_id = entries.to_h do |entry|
|
|
19
|
+
snippet_id = @snippet_ids.fetch(entry[:name])
|
|
20
|
+
keys = entry[:sources].map { |source| record_key(source) }.uniq
|
|
21
|
+
sources = (keys - [['snippet', snippet_id]]).filter_map { |key| records[key] }
|
|
22
|
+
[snippet_id, sources.sort_by { |source| [source[:type], source[:label].to_s.downcase, source[:id]] }]
|
|
23
|
+
end
|
|
24
|
+
{ sources_by_id: sources_by_id, complete: report[:complete] }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
def record_key(source)
|
|
30
|
+
source[:type] == 'translation' ? ['page', source[:page_id]] : source.values_at(:type, :id)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def referenced_records(entries)
|
|
34
|
+
keys = entries.flat_map { |entry| entry[:sources].map { |source| record_key(source) } }.uniq
|
|
35
|
+
keys.group_by(&:first).each_with_object({}) do |(type, group), records|
|
|
36
|
+
page = type == 'page'
|
|
37
|
+
field = page ? :slug : :identifier
|
|
38
|
+
@site.public_send("#{type}s").where(id: group.map(&:last)).pluck(:id, :label, field).each do |id, label, identifier|
|
|
39
|
+
identifier = CGI.unescape(identifier.to_s) if page
|
|
40
|
+
records[[type, id]] = { type: type, site_id: @site.id, id: id, label: label, identifier: identifier.presence || id.to_s }
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -8,12 +8,15 @@ class ComfyMiddleSeat::Content::TagUsage
|
|
|
8
8
|
'render_partial' => 'partial',
|
|
9
9
|
'helper' => 'helper',
|
|
10
10
|
'template' => 'template',
|
|
11
|
-
'render_template' => 'template'
|
|
11
|
+
'render_template' => 'template',
|
|
12
|
+
'snippet' => 'snippet'
|
|
12
13
|
}.freeze
|
|
14
|
+
ALLOWLIST_KINDS = %w[partial helper template].freeze
|
|
13
15
|
|
|
14
|
-
def initialize(sites: nil, scope: nil)
|
|
16
|
+
def initialize(sites: nil, scope: nil, kinds: ALLOWLIST_KINDS)
|
|
15
17
|
@sites = sites || Comfy::Cms::Site.all
|
|
16
18
|
@scope = scope || (sites.nil? ? 'all_sites' : 'selected_sites')
|
|
19
|
+
@kinds = KINDS.select { |_tag, kind| kinds.include?(kind) }
|
|
17
20
|
end
|
|
18
21
|
|
|
19
22
|
def call
|
|
@@ -21,7 +24,7 @@ class ComfyMiddleSeat::Content::TagUsage
|
|
|
21
24
|
@entries = {}
|
|
22
25
|
@warnings = []
|
|
23
26
|
@source_count = 0
|
|
24
|
-
@allowlists =
|
|
27
|
+
@allowlists = (@kinds.values & ALLOWLIST_KINDS).to_h do |kind|
|
|
25
28
|
allowed = ComfyMiddleSeat.config.public_send("allowed_#{kind}s")
|
|
26
29
|
next [kind, nil] unless allowed.is_a?(Array)
|
|
27
30
|
|
|
@@ -91,7 +94,7 @@ private
|
|
|
91
94
|
def scan(content, source)
|
|
92
95
|
@source_count += 1
|
|
93
96
|
@renderer.tokenize(content).each do |token|
|
|
94
|
-
next unless token.is_a?(Hash) && (kind =
|
|
97
|
+
next unless token.is_a?(Hash) && (kind = @kinds[token[:tag_class]])
|
|
95
98
|
|
|
96
99
|
scan_token(token, kind, source)
|
|
97
100
|
end
|
|
@@ -113,6 +116,8 @@ private
|
|
|
113
116
|
end
|
|
114
117
|
|
|
115
118
|
def status(kind, name)
|
|
119
|
+
return unless @allowlists.key?(kind)
|
|
120
|
+
|
|
116
121
|
if (allowed = @allowlists[kind])
|
|
117
122
|
allowed.include?(name) ? 'explicitly_allowed' : 'blocked'
|
|
118
123
|
elsif kind == 'helper' && ComfyMiddleSeat::Content::Tags::Helper::BLACKLIST.include?(name)
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: comfy_middle_seat
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 4.
|
|
4
|
+
version: 4.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Oleg Khabarov
|
|
@@ -475,6 +475,7 @@ files:
|
|
|
475
475
|
- app/views/comfy/admin/cms/sites/index.html.haml
|
|
476
476
|
- app/views/comfy/admin/cms/sites/new.html.haml
|
|
477
477
|
- app/views/comfy/admin/cms/snippets/_form.html.haml
|
|
478
|
+
- app/views/comfy/admin/cms/snippets/_usage.html.haml
|
|
478
479
|
- app/views/comfy/admin/cms/snippets/edit.html.haml
|
|
479
480
|
- app/views/comfy/admin/cms/snippets/index.html.haml
|
|
480
481
|
- app/views/comfy/admin/cms/snippets/new.html.haml
|
|
@@ -581,6 +582,7 @@ files:
|
|
|
581
582
|
- lib/comfy_middle_seat/content/image_transformations.rb
|
|
582
583
|
- lib/comfy_middle_seat/content/params_parser.rb
|
|
583
584
|
- lib/comfy_middle_seat/content/renderer.rb
|
|
585
|
+
- lib/comfy_middle_seat/content/snippet_usage.rb
|
|
584
586
|
- lib/comfy_middle_seat/content/tag.rb
|
|
585
587
|
- lib/comfy_middle_seat/content/tag_usage.rb
|
|
586
588
|
- lib/comfy_middle_seat/content/tag_usage_report.rb
|