comfy_middle_seat 4.2.0 → 4.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -3
- data/README.md +64 -0
- data/app/assets/javascripts/comfy/admin/cms/cms_tag_completions.js +177 -0
- data/app/assets/javascripts/comfy/admin/cms/codemirror.js +3 -0
- data/app/assets/stylesheets/comfy/admin/cms/application.sass +1 -0
- data/app/assets/stylesheets/comfy/admin/cms/codemirror_overrides.sass +11 -0
- data/lib/comfy_middle_seat/content/renderer.rb +53 -8
- data/lib/comfy_middle_seat/content/tags/markdown.rb +4 -1
- data/lib/comfy_middle_seat/content/tags/snippet.rb +2 -1
- data/lib/comfy_middle_seat/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9433cede5d17f15d7c30a4a6bb30e9951ddb944129c317dc8b9a008f8e8d69f0
|
|
4
|
+
data.tar.gz: 6f30614dae87dfc9735ee436c640f5431ef66e58a084483549fb105ab43bffa2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fba6ed160d2930727df376eb665f184df898ad3bf732b45a734abbee4f4edbe0f063f056db66c8f95adcba9111b9fd43a0640f8f5aebb1860c36b451ddcc09d5
|
|
7
|
+
data.tar.gz: f0801cb516d4d98bd8adc25c8e51bf73c2fc13b25f8930a6597c854abd216dd7a98ba5b08dd214cd45f85f73139844a7e5a6a3bb7771e8bd6c66954dd026c187
|
data/CHANGELOG.md
CHANGED
|
@@ -12,16 +12,27 @@ This changelog follows the project's lineage: **Comfortable Mexican Sofa → Com
|
|
|
12
12
|
|
|
13
13
|
## [Unreleased]
|
|
14
14
|
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
- Add CMS comment blocks and short notes to hide content without processing enclosed tags.
|
|
18
|
+
- Expand CMS tags with editor shortcuts and searchable completion.
|
|
19
|
+
- Open the shortcut selector with `;;` + Tab and filter with fuzzy search.
|
|
20
|
+
|
|
21
|
+
## [v4.2.0] - 2026-10-13
|
|
22
|
+
|
|
15
23
|
### Changed
|
|
16
24
|
|
|
17
25
|
- Keep Page editing actions together in a sticky top toolbar.
|
|
18
26
|
- Save edits and publish or unpublish a page with one button.
|
|
19
|
-
-
|
|
20
|
-
-
|
|
27
|
+
- Show unpublished status below the heading and save hints as button tooltips.
|
|
28
|
+
- Simplify the save confirmation to “Page updated.”
|
|
29
|
+
- Fade success and informational notices after five seconds; pause on hover or focus.
|
|
30
|
+
- Keep warnings and errors visible and respect reduced-motion preferences.
|
|
21
31
|
|
|
22
32
|
### Fixed
|
|
23
33
|
|
|
24
34
|
- Keep editing buttons aligned with the page heading above publication status.
|
|
35
|
+
- Keep editing controls usable after Preview.
|
|
25
36
|
- Restore dismissal of admin flash notices.
|
|
26
37
|
- Keep Add Child Layout on one line when space allows.
|
|
27
38
|
|
|
@@ -251,7 +262,8 @@ First release of `comfortable_media_surfer`. This new gem is a revival of [Comfo
|
|
|
251
262
|
|
|
252
263
|
- Rebranded **ComfortableMexicanSofa** as **ComfortableMediaSurfer** in order to publish new gem (database table names and schema have not changed).
|
|
253
264
|
|
|
254
|
-
[Unreleased]: https://github.com/avonderluft/comfy-middle-seat/compare/v4.
|
|
265
|
+
[Unreleased]: https://github.com/avonderluft/comfy-middle-seat/compare/v4.2.0...master
|
|
266
|
+
[v4.2.0]: https://github.com/avonderluft/comfy-middle-seat/compare/v4.1.0...v4.2.0
|
|
255
267
|
[v4.1.0]: https://github.com/avonderluft/comfy-middle-seat/compare/v4.0.4...v4.1.0
|
|
256
268
|
[v4.0.4]: https://github.com/avonderluft/comfy-middle-seat/compare/ea2bb99c0398e1f4d6e850a25e0c13afc577c3ad...v4.0.4
|
|
257
269
|
[v4.0.3]: https://github.com/avonderluft/comfy-middle-seat/compare/v4.0.2...ea2bb99c0398e1f4d6e850a25e0c13afc577c3ad
|
data/README.md
CHANGED
|
@@ -114,6 +114,70 @@ A Site defines a hostname, path, and language. Layouts define page structure and
|
|
|
114
114
|
|
|
115
115
|
When an editor creates a Page using this Layout, the admin automatically presents fields for `title` and `content`. Content tags can also provide Markdown, files, images, dates, numbers, checkboxes, snippets, partials, helpers, navigation, and other reusable content.
|
|
116
116
|
|
|
117
|
+
### Editor shortcuts
|
|
118
|
+
|
|
119
|
+
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.
|
|
120
|
+
|
|
121
|
+
Type **`;;` then Tab**, or press **Ctrl+Space**, for a searchable shortcut list. Search by shortcut or tag name: `c` prioritizes comment, children, and other `c` shortcuts; `p fl` finds `page_file_link`. Exact and prefix matches appear before fuzzy matches.
|
|
122
|
+
|
|
123
|
+
Use the arrow keys and **Enter** or **Tab** to choose. The tag replaces the entire trigger and search text. **Escape** closes the list without changing your text. Full names such as `;markdown` also work for direct expansion. One **Undo** reverses the expansion without removing what you typed.
|
|
124
|
+
|
|
125
|
+
| Shortcut | Inserts | Selected placeholder |
|
|
126
|
+
| --- | --- | --- |
|
|
127
|
+
| `;md` | `markdown` | `content` |
|
|
128
|
+
| `;tx` | `text` | `field` |
|
|
129
|
+
| `;ta` | `textarea` | `content` |
|
|
130
|
+
| `;wys` | `wysiwyg` | `content` |
|
|
131
|
+
| `;da` | `date` | `field` |
|
|
132
|
+
| `;dt` | `datetime` | `field` |
|
|
133
|
+
| `;num` | `number` | `field` |
|
|
134
|
+
| `;cb` | `checkbox` | `field` |
|
|
135
|
+
| `;fi` | `file`, as a link | `attachment` |
|
|
136
|
+
| `;fs` | `files`, as links | `attachments` |
|
|
137
|
+
| `;im` | `image` | `image label` |
|
|
138
|
+
| `;au` | `audio` | `path/to/audio` |
|
|
139
|
+
| `;fl` | `file_link`, as a link | `file_id` |
|
|
140
|
+
| `;pfl` | `page_file_link`, as a link | `attachment` |
|
|
141
|
+
| `;sn` | `snippet` | `identifier` |
|
|
142
|
+
| `;as`, `;css` | CSS `asset` tag | `layout_identifier` |
|
|
143
|
+
| `;js` | JavaScript `asset` tag | `layout_identifier` |
|
|
144
|
+
| `;hlp` | `helper` | `method_name` |
|
|
145
|
+
| `;par` | `partial` | `path/to/partial` |
|
|
146
|
+
| `;tpl` | `template` | `path/to/template` |
|
|
147
|
+
| `;cr` | `breadcrumbs` | — |
|
|
148
|
+
| `;ch` | `children` | — |
|
|
149
|
+
| `;si` | `siblings` | — |
|
|
150
|
+
| `;com` | Complete multiline comment block | `Comment here` |
|
|
151
|
+
| `;nt` | `comment "Note"` (also `;note`) | `Note` |
|
|
152
|
+
| `;ec` | `endcomment` | — |
|
|
153
|
+
| `;end` | `end` | — |
|
|
154
|
+
|
|
155
|
+
Placeholders are examples: replace them with your field names, identifiers, paths, or IDs. `;asset` inserts the CSS version; `;comment` inserts a full comment block.
|
|
156
|
+
|
|
157
|
+
Shortcuts work at the start of a line, after whitespace, or after `>`, outside an existing CMS tag. Unrecognized shortcuts retain normal Tab behavior. CSS, JavaScript, ordinary text fields, and visual editors are unchanged. Saved content uses the standard `{{ cms:... }}` syntax.
|
|
158
|
+
|
|
159
|
+
### CMS comments
|
|
160
|
+
|
|
161
|
+
Use a quoted note for a short comment:
|
|
162
|
+
|
|
163
|
+
```html
|
|
164
|
+
{{cms:comment "Replace this banner in December"}}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Use a block to hide a section, including any CMS tags inside it:
|
|
168
|
+
|
|
169
|
+
```html
|
|
170
|
+
{{cms:comment}}
|
|
171
|
+
Internal note: this section is not ready.
|
|
172
|
+
{{cms:markdown old_content}}
|
|
173
|
+
{{cms:snippet seasonal_banner}}
|
|
174
|
+
{{cms:endcomment}}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Comments produce no rendered output and do not create editor fields. Unlike HTML comments, enclosed CMS tags are not processed. Source text and existing field values remain stored; removing a comment restores normal processing.
|
|
178
|
+
|
|
179
|
+
Blocks may be nested and must end with `{{cms:endcomment}}`, not `{{cms:end}}`. Short notes accept single or double quotes, with backslash-escaped quotes. Unclosed blocks and malformed comment tags raise a clear syntax error. Comments work in layouts, snippets, and rendered fragment content, including Markdown. They are not a place for secrets: original source remains available to editors and may be exposed by APIs that include raw content.
|
|
180
|
+
|
|
117
181
|
### Publishing pages
|
|
118
182
|
|
|
119
183
|
A page is publicly visible only when it and all its ancestors are published. Unpublishing a parent hides its branch without changing descendants’ individual publication settings. Republishing the parent restores only descendants whose full ancestor chain is published; drafts stay unpublished. Translations must also satisfy their own publication settings.
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import CodeMirror from "codemirror";
|
|
2
|
+
import "codemirror/addon/hint/show-hint";
|
|
3
|
+
|
|
4
|
+
const tag = (shortcut, name, params = "", placeholder = null, aliases = []) => ({
|
|
5
|
+
shortcut,
|
|
6
|
+
name,
|
|
7
|
+
aliases: [shortcut, name, ...aliases],
|
|
8
|
+
text: `{{ cms:${name}${params ? ` ${params}` : ""} }}`,
|
|
9
|
+
placeholder,
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const completions = [
|
|
13
|
+
tag("md", "markdown", "content", "content"),
|
|
14
|
+
tag("tx", "text", "field", "field"),
|
|
15
|
+
tag("ta", "textarea", "content", "content"),
|
|
16
|
+
tag("wys", "wysiwyg", "content", "content"),
|
|
17
|
+
tag("da", "date", "field", "field"),
|
|
18
|
+
tag("dt", "datetime", "field", "field"),
|
|
19
|
+
tag("num", "number", "field", "field"),
|
|
20
|
+
tag("cb", "checkbox", "field", "field"),
|
|
21
|
+
tag("fi", "file", "attachment, as: link", "attachment"),
|
|
22
|
+
tag("fs", "files", "attachments, as: link", "attachments"),
|
|
23
|
+
tag("im", "image", '"image label"', "image label"),
|
|
24
|
+
tag("au", "audio", '"path/to/audio"', "path/to/audio"),
|
|
25
|
+
tag("fl", "file_link", "file_id, as: link", "file_id"),
|
|
26
|
+
tag("pfl", "page_file_link", "attachment, as: link", "attachment"),
|
|
27
|
+
tag("sn", "snippet", "identifier", "identifier"),
|
|
28
|
+
tag("as", "asset", "layout_identifier, type: css, as: tag", "layout_identifier"),
|
|
29
|
+
tag("css", "asset", "layout_identifier, type: css, as: tag", "layout_identifier"),
|
|
30
|
+
tag("js", "asset", "layout_identifier, type: js, as: tag", "layout_identifier"),
|
|
31
|
+
tag("hlp", "helper", "method_name", "method_name"),
|
|
32
|
+
tag("par", "partial", '"path/to/partial"', "path/to/partial"),
|
|
33
|
+
tag("tpl", "template", '"path/to/template"', "path/to/template"),
|
|
34
|
+
tag("cr", "breadcrumbs"),
|
|
35
|
+
tag("ch", "children"),
|
|
36
|
+
tag("si", "siblings"),
|
|
37
|
+
{
|
|
38
|
+
...tag("com", "comment", "", "Comment here"),
|
|
39
|
+
text: "{{ cms:comment }}\nComment here\n{{ cms:endcomment }}",
|
|
40
|
+
},
|
|
41
|
+
tag("nt", "comment", '"Note"', "Note", ["note"]),
|
|
42
|
+
tag("ec", "endcomment"),
|
|
43
|
+
tag("end", "end"),
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
const byAlias = new Map();
|
|
47
|
+
for (const completion of completions) {
|
|
48
|
+
for (const alias of completion.aliases) {
|
|
49
|
+
// Shared full names use the primary entry: asset => ;as, comment => ;com.
|
|
50
|
+
if (!byAlias.has(alias)) byAlias.set(alias, completion);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const completionContext = (editor, requireSemicolon = false, start = null) => {
|
|
55
|
+
if (editor.getOption("readOnly") || editor.somethingSelected() ||
|
|
56
|
+
editor.listSelections().length !== 1) return null;
|
|
57
|
+
|
|
58
|
+
const to = editor.getCursor();
|
|
59
|
+
const line = editor.getLine(to.line);
|
|
60
|
+
if (/\w/.test(line.charAt(to.ch))) return null;
|
|
61
|
+
|
|
62
|
+
if (start && (start.line !== to.line || start.ch > to.ch)) return null;
|
|
63
|
+
// Keep the menu's original start so spaces in a fuzzy query are not lost.
|
|
64
|
+
const match = start
|
|
65
|
+
? /^(;{0,2}[\w ]*)$/.exec(line.slice(start.ch, to.ch))
|
|
66
|
+
: /(?:^|[\s>])(;;[\w ]*|;?\w*)$/.exec(line.slice(0, to.ch));
|
|
67
|
+
if (!match || (requireSemicolon && !match[1].startsWith(";"))) return null;
|
|
68
|
+
|
|
69
|
+
const from = start || CodeMirror.Pos(to.line, to.ch - match[1].length);
|
|
70
|
+
const before = editor.getRange(CodeMirror.Pos(0, 0), from);
|
|
71
|
+
if (before.lastIndexOf("{{") > before.lastIndexOf("}}")) return null;
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
from,
|
|
75
|
+
to,
|
|
76
|
+
selector: match[1].startsWith(";;"),
|
|
77
|
+
query: match[1].replace(/^;{1,2}/, "").toLowerCase().replace(/ /g, ""),
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const insertCompletion = (editor, completion, from, to) => {
|
|
82
|
+
const indent = editor.getLine(from.line).match(/^\s*/)[0];
|
|
83
|
+
const text = completion.text.replace(/\n/g, `\n${indent}`);
|
|
84
|
+
const start = editor.indexFromPos(from);
|
|
85
|
+
|
|
86
|
+
editor.operation(() => {
|
|
87
|
+
// A distinct history origin keeps the expansion separate from preceding typing.
|
|
88
|
+
editor.replaceRange(text, from, to, "cms-completion");
|
|
89
|
+
if (completion.placeholder) {
|
|
90
|
+
const offset = text.indexOf(completion.placeholder);
|
|
91
|
+
editor.setSelection(
|
|
92
|
+
editor.posFromIndex(start + offset),
|
|
93
|
+
editor.posFromIndex(start + offset + completion.placeholder.length)
|
|
94
|
+
);
|
|
95
|
+
} else {
|
|
96
|
+
editor.setCursor(editor.posFromIndex(start + text.length));
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const matchRank = (alias, query) => {
|
|
102
|
+
if (alias === query) return 0;
|
|
103
|
+
if (alias.startsWith(query)) return 1;
|
|
104
|
+
if (alias.includes(query)) return 2;
|
|
105
|
+
|
|
106
|
+
let position = 0;
|
|
107
|
+
for (const character of query) {
|
|
108
|
+
position = alias.indexOf(character, position);
|
|
109
|
+
if (position === -1) return Infinity;
|
|
110
|
+
position += 1;
|
|
111
|
+
}
|
|
112
|
+
return 3;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const displayNames = {
|
|
116
|
+
as: "asset (CSS)",
|
|
117
|
+
css: "asset (CSS)",
|
|
118
|
+
js: "asset (JavaScript)",
|
|
119
|
+
com: "comment (block)",
|
|
120
|
+
nt: "comment (note)",
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const hints = (editor, start) => {
|
|
124
|
+
const context = completionContext(editor, false, start);
|
|
125
|
+
if (!context) return null;
|
|
126
|
+
|
|
127
|
+
return {
|
|
128
|
+
from: context.from,
|
|
129
|
+
to: context.to,
|
|
130
|
+
list: completions
|
|
131
|
+
.map((completion) => ({
|
|
132
|
+
completion,
|
|
133
|
+
rank: Math.min(...completion.aliases.map((alias) => matchRank(alias, context.query))),
|
|
134
|
+
}))
|
|
135
|
+
.filter(({ rank }) => Number.isFinite(rank))
|
|
136
|
+
.sort((a, b) => a.rank - b.rank)
|
|
137
|
+
.map(({ completion }) => ({
|
|
138
|
+
text: completion.text,
|
|
139
|
+
displayText: `;${completion.shortcut} ${displayNames[completion.shortcut] || completion.name}`,
|
|
140
|
+
hint(cm, data) {
|
|
141
|
+
insertCompletion(cm, completion, data.from, data.to);
|
|
142
|
+
},
|
|
143
|
+
})),
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const showCompletions = (editor, context) => {
|
|
148
|
+
editor.showHint({
|
|
149
|
+
hint: (cm) => hints(cm, context.from),
|
|
150
|
+
completeSingle: false,
|
|
151
|
+
closeCharacters: /[\t\r\n()[\]{}:>,]/,
|
|
152
|
+
});
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
export const cmsTagCompletionKeys = (mode) => {
|
|
156
|
+
if (!["text/html", "htmlmixed", "text/x-markdown", "markdown"].includes(mode)) return {};
|
|
157
|
+
|
|
158
|
+
return {
|
|
159
|
+
Tab(editor) {
|
|
160
|
+
const context = completionContext(editor, true);
|
|
161
|
+
if (context?.selector) {
|
|
162
|
+
showCompletions(editor, context);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const completion = context && byAlias.get(context.query);
|
|
166
|
+
if (!completion) return CodeMirror.Pass;
|
|
167
|
+
|
|
168
|
+
insertCompletion(editor, completion, context.from, context.to);
|
|
169
|
+
},
|
|
170
|
+
"Ctrl-Space"(editor) {
|
|
171
|
+
const context = completionContext(editor);
|
|
172
|
+
if (!context) return CodeMirror.Pass;
|
|
173
|
+
|
|
174
|
+
showCompletions(editor, context);
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import jQuery from "jquery";
|
|
2
2
|
import CodeMirror from "codemirror";
|
|
3
|
+
import { cmsTagCompletionKeys } from "./cms_tag_completions";
|
|
3
4
|
import "codemirror/mode/markdown/markdown";
|
|
4
5
|
import "codemirror/mode/htmlmixed/htmlmixed";
|
|
5
6
|
|
|
@@ -12,6 +13,7 @@ import "codemirror/mode/htmlmixed/htmlmixed";
|
|
|
12
13
|
)) {
|
|
13
14
|
const codemirror = CodeMirror.fromTextArea(textarea, {
|
|
14
15
|
mode: textarea.dataset.cmsCmMode,
|
|
16
|
+
extraKeys: cmsTagCompletionKeys(textarea.dataset.cmsCmMode),
|
|
15
17
|
tabSize: 2,
|
|
16
18
|
lineWrapping: true,
|
|
17
19
|
autoCloseTags: true,
|
|
@@ -52,6 +54,7 @@ import "codemirror/mode/htmlmixed/htmlmixed";
|
|
|
52
54
|
},
|
|
53
55
|
dispose() {
|
|
54
56
|
for (const codemirror of codeMirrorInstances) {
|
|
57
|
+
codemirror.closeHint();
|
|
55
58
|
codemirror.toTextArea();
|
|
56
59
|
}
|
|
57
60
|
codeMirrorInstances.length = 0;
|
|
@@ -12,6 +12,17 @@ body#comfy
|
|
|
12
12
|
.CodeMirror-scroll
|
|
13
13
|
min-height: 160px
|
|
14
14
|
|
|
15
|
+
.CodeMirror-hints
|
|
16
|
+
z-index: 1060
|
|
17
|
+
max-width: calc(100vw - 1rem)
|
|
18
|
+
border-color: $gray-400
|
|
19
|
+
background-color: $white
|
|
20
|
+
.CodeMirror-hint
|
|
21
|
+
color: $body-color
|
|
22
|
+
.CodeMirror-hint-active
|
|
23
|
+
background-color: $primary
|
|
24
|
+
color: $white
|
|
25
|
+
|
|
15
26
|
.CodeMirror-focused
|
|
16
27
|
border-color: rgba(82, 168, 236, 0.8)
|
|
17
28
|
outline: 0
|
|
@@ -22,6 +22,9 @@ class ComfyMiddleSeat::Content::Renderer
|
|
|
22
22
|
|
|
23
23
|
# tags are in this format: {{ cms:tag_class params }}
|
|
24
24
|
TAG_REGEX = %r{\{\{\s*?cms:(?<class>\w+)(?<params>.*?)\}\}}
|
|
25
|
+
COMMENT_START_REGEX = %r{\{\{\s*cms:(?<comment>comment|endcomment)(?=\s|\}\}|\z)}
|
|
26
|
+
TOKEN_REGEX = %r{#{COMMENT_START_REGEX}|#{TAG_REGEX}}
|
|
27
|
+
COMMENT_NOTE_REGEX = %r{(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|“(?:\\.|[^”\\])*”|‘(?:\\.|[^’\\])*’)\s*\}\}}m
|
|
25
28
|
|
|
26
29
|
class << self
|
|
27
30
|
# @return [Hash<String, Class<ComfyMiddleSeat::Content::Tag>>]
|
|
@@ -73,23 +76,35 @@ class ComfyMiddleSeat::Content::Renderer
|
|
|
73
76
|
|
|
74
77
|
# Splitting text with tags into tokens we can process down the line
|
|
75
78
|
# @return [Array<String, {Symbol => String}>]
|
|
76
|
-
def tokenize(string)
|
|
79
|
+
def tokenize(string, preserve_whitespace: false)
|
|
77
80
|
tokens = []
|
|
78
81
|
ss = StringScanner.new(string.to_s)
|
|
79
|
-
while (string = ss.scan_until(
|
|
82
|
+
while (string = ss.scan_until(TOKEN_REGEX))
|
|
80
83
|
text = string.sub(ss[0], '')
|
|
81
84
|
tokens << text unless text.empty?
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
case ss[:comment]
|
|
86
|
+
when 'comment'
|
|
87
|
+
skip_comment(ss)
|
|
88
|
+
when 'endcomment'
|
|
89
|
+
raise SyntaxError, 'Unexpected {{cms:endcomment}} without {{cms:comment}}'
|
|
90
|
+
else
|
|
91
|
+
tokens << {
|
|
92
|
+
tag_class: ss[:class],
|
|
93
|
+
tag_params: ss[:params].strip,
|
|
94
|
+
source: ss[0]
|
|
95
|
+
}
|
|
96
|
+
end
|
|
87
97
|
end
|
|
88
98
|
text = ss.rest
|
|
89
|
-
tokens << text if text.present?
|
|
99
|
+
tokens << text if text.present? || (preserve_whitespace && !text.empty?)
|
|
90
100
|
tokens
|
|
91
101
|
end
|
|
92
102
|
|
|
103
|
+
# Remove comments before formatters such as Markdown can transform their contents.
|
|
104
|
+
def strip_comments(string)
|
|
105
|
+
tokenize(string, preserve_whitespace: true).map { |token| token.is_a?(Hash) ? token[:source] : token }.join
|
|
106
|
+
end
|
|
107
|
+
|
|
93
108
|
# Constructing node tree for content. It's a list of strings and tags with
|
|
94
109
|
# their own `nodes` method that has array of strings and tags with their own
|
|
95
110
|
# `nodes` method that... you get the idea.
|
|
@@ -143,4 +158,34 @@ class ComfyMiddleSeat::Content::Renderer
|
|
|
143
158
|
|
|
144
159
|
nodes.flatten
|
|
145
160
|
end
|
|
161
|
+
|
|
162
|
+
private
|
|
163
|
+
|
|
164
|
+
# Comments are lexical: their contents must never become tag instances or form fields.
|
|
165
|
+
def skip_comment(scanner)
|
|
166
|
+
return unless comment_block?(scanner)
|
|
167
|
+
|
|
168
|
+
depth = 1
|
|
169
|
+
while scanner.scan_until(COMMENT_START_REGEX)
|
|
170
|
+
if scanner[:comment] == 'comment'
|
|
171
|
+
depth += 1 if comment_block?(scanner)
|
|
172
|
+
else
|
|
173
|
+
unless scanner.skip(%r{\s*\}\}})
|
|
174
|
+
raise SyntaxError, 'Invalid CMS comment closing tag: use {{cms:endcomment}} without parameters'
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
depth -= 1
|
|
178
|
+
return if depth.zero?
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
raise SyntaxError, 'Unclosed CMS comment: expected {{cms:endcomment}}'
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
def comment_block?(scanner)
|
|
185
|
+
scanner.skip(%r{\s*})
|
|
186
|
+
return true if scanner.skip(%r{\}\}})
|
|
187
|
+
return false if scanner.skip(COMMENT_NOTE_REGEX)
|
|
188
|
+
|
|
189
|
+
raise SyntaxError, 'Invalid CMS comment: use {{cms:comment "note"}} or {{cms:comment}}...{{cms:endcomment}}'
|
|
190
|
+
end
|
|
146
191
|
end
|
|
@@ -5,7 +5,10 @@
|
|
|
5
5
|
#
|
|
6
6
|
class ComfyMiddleSeat::Content::Tags::Markdown < ComfyMiddleSeat::Content::Tags::Fragment
|
|
7
7
|
def render
|
|
8
|
-
|
|
8
|
+
return '' unless renderable
|
|
9
|
+
|
|
10
|
+
source = ComfyMiddleSeat::Content::Renderer.new(context).strip_comments(content)
|
|
11
|
+
Kramdown::Document.new(source).to_html
|
|
9
12
|
end
|
|
10
13
|
|
|
11
14
|
def form_field(object_name, view, index)
|
|
@@ -18,7 +18,8 @@ class ComfyMiddleSeat::Content::Tags::Snippet < ComfyMiddleSeat::Content::Tag
|
|
|
18
18
|
|
|
19
19
|
def content
|
|
20
20
|
if snippet.markdown
|
|
21
|
-
|
|
21
|
+
source = ComfyMiddleSeat::Content::Renderer.new(context).strip_comments(snippet.content)
|
|
22
|
+
Kramdown::Document.new(source).to_html
|
|
22
23
|
else
|
|
23
24
|
snippet.content
|
|
24
25
|
end
|
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.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Oleg Khabarov
|
|
@@ -230,6 +230,7 @@ files:
|
|
|
230
230
|
- app/assets/javascripts/comfy/admin/cms/application.js
|
|
231
231
|
- app/assets/javascripts/comfy/admin/cms/base.js
|
|
232
232
|
- app/assets/javascripts/comfy/admin/cms/categories.js
|
|
233
|
+
- app/assets/javascripts/comfy/admin/cms/cms_tag_completions.js
|
|
233
234
|
- app/assets/javascripts/comfy/admin/cms/codemirror.js
|
|
234
235
|
- app/assets/javascripts/comfy/admin/cms/custom.js
|
|
235
236
|
- app/assets/javascripts/comfy/admin/cms/diff.js
|