pressroom 0.1.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 (82) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +22 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.md +172 -0
  5. data/Rakefile +8 -0
  6. data/app/assets/javascripts/pressroom/application.js +18 -0
  7. data/app/assets/javascripts/pressroom/controllers/editor_controller.js +146 -0
  8. data/app/assets/javascripts/pressroom/vendor/code.js +181 -0
  9. data/app/assets/javascripts/pressroom/vendor/delimiter.js +98 -0
  10. data/app/assets/javascripts/pressroom/vendor/editorjs.js +11217 -0
  11. data/app/assets/javascripts/pressroom/vendor/header.js +321 -0
  12. data/app/assets/javascripts/pressroom/vendor/image.js +1103 -0
  13. data/app/assets/javascripts/pressroom/vendor/inline-code.js +99 -0
  14. data/app/assets/javascripts/pressroom/vendor/list.js +2091 -0
  15. data/app/assets/javascripts/pressroom/vendor/marker.js +95 -0
  16. data/app/assets/javascripts/pressroom/vendor/quote.js +990 -0
  17. data/app/assets/javascripts/pressroom/vendor/stimulus.js +2563 -0
  18. data/app/assets/javascripts/pressroom/vendor/turbo.js +7256 -0
  19. data/app/assets/stylesheets/pressroom/admin.css +216 -0
  20. data/app/assets/stylesheets/pressroom/content.css +18 -0
  21. data/app/controllers/pressroom/application_controller.rb +41 -0
  22. data/app/controllers/pressroom/categories_controller.rb +50 -0
  23. data/app/controllers/pressroom/posts_controller.rb +98 -0
  24. data/app/controllers/pressroom/tags_controller.rb +39 -0
  25. data/app/controllers/pressroom/uploads_controller.rb +52 -0
  26. data/app/helpers/pressroom/application_helper.rb +4 -0
  27. data/app/helpers/pressroom/blocks_helper.rb +13 -0
  28. data/app/jobs/pressroom/application_job.rb +4 -0
  29. data/app/mailers/pressroom/application_mailer.rb +6 -0
  30. data/app/models/concerns/pressroom/authorable.rb +23 -0
  31. data/app/models/concerns/pressroom/sluggable.rb +66 -0
  32. data/app/models/pressroom/application_record.rb +7 -0
  33. data/app/models/pressroom/category.rb +54 -0
  34. data/app/models/pressroom/post.rb +90 -0
  35. data/app/models/pressroom/tag.rb +30 -0
  36. data/app/models/pressroom/tagging.rb +12 -0
  37. data/app/views/layouts/pressroom/admin.html.erb +34 -0
  38. data/app/views/layouts/pressroom/application.html.erb +17 -0
  39. data/app/views/pressroom/blocks/_code.html.erb +2 -0
  40. data/app/views/pressroom/blocks/_delimiter.html.erb +1 -0
  41. data/app/views/pressroom/blocks/_header.html.erb +5 -0
  42. data/app/views/pressroom/blocks/_image.html.erb +18 -0
  43. data/app/views/pressroom/blocks/_list.html.erb +6 -0
  44. data/app/views/pressroom/blocks/_list_items.html.erb +13 -0
  45. data/app/views/pressroom/blocks/_paragraph.html.erb +1 -0
  46. data/app/views/pressroom/blocks/_quote.html.erb +6 -0
  47. data/app/views/pressroom/categories/_form.html.erb +31 -0
  48. data/app/views/pressroom/categories/edit.html.erb +3 -0
  49. data/app/views/pressroom/categories/index.html.erb +34 -0
  50. data/app/views/pressroom/categories/new.html.erb +3 -0
  51. data/app/views/pressroom/posts/_form.html.erb +49 -0
  52. data/app/views/pressroom/posts/_post_row.html.erb +17 -0
  53. data/app/views/pressroom/posts/edit.html.erb +34 -0
  54. data/app/views/pressroom/posts/index.html.erb +38 -0
  55. data/app/views/pressroom/posts/new.html.erb +3 -0
  56. data/app/views/pressroom/tags/edit.html.erb +24 -0
  57. data/app/views/pressroom/tags/index.html.erb +27 -0
  58. data/config/editorjs_manifest.yml +53 -0
  59. data/config/importmap.rb +18 -0
  60. data/config/locales/pressroom.en.yml +16 -0
  61. data/config/locales/transliteration.ru.yml +70 -0
  62. data/config/locales/transliteration.uk.yml +70 -0
  63. data/config/routes.rb +17 -0
  64. data/db/migrate/20260821000001_create_pressroom_posts.rb +42 -0
  65. data/db/migrate/20260821000002_create_pressroom_taxonomy.rb +33 -0
  66. data/lib/pressroom/blocks/definition.rb +103 -0
  67. data/lib/pressroom/blocks/registry.rb +56 -0
  68. data/lib/pressroom/blocks/renderer.rb +97 -0
  69. data/lib/pressroom/blocks/sanitizer.rb +36 -0
  70. data/lib/pressroom/blocks/schema.rb +247 -0
  71. data/lib/pressroom/blocks/text_extractor.rb +46 -0
  72. data/lib/pressroom/built_in_blocks.rb +97 -0
  73. data/lib/pressroom/configuration.rb +64 -0
  74. data/lib/pressroom/engine.rb +33 -0
  75. data/lib/pressroom/errors.rb +11 -0
  76. data/lib/pressroom/feed.rb +69 -0
  77. data/lib/pressroom/transliteration.rb +213 -0
  78. data/lib/pressroom/version.rb +3 -0
  79. data/lib/pressroom.rb +70 -0
  80. data/lib/tasks/pressroom_tasks.rake +4 -0
  81. data/lib/tasks/pressroom_vendor.rake +31 -0
  82. metadata +171 -0
@@ -0,0 +1,321 @@
1
+ (function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode(".ce-header{padding:.6em 0 3px;margin:0;line-height:1.25em;outline:none}.ce-header p,.ce-header div{padding:0!important;margin:0!important}")),document.head.appendChild(e)}}catch(n){console.error("vite-plugin-css-injected-by-js",n)}})();
2
+ const a = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M6 7L6 12M6 17L6 12M6 12L12 12M12 7V12M12 17L12 12"/><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M19 17V10.2135C19 10.1287 18.9011 10.0824 18.836 10.1367L16 12.5"/></svg>', h = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M6 7L6 12M6 17L6 12M6 12L12 12M12 7V12M12 17L12 12"/><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M16 11C16 10 19 9.5 19 12C19 13.9771 16.0684 13.9997 16.0012 16.8981C15.9999 16.9533 16.0448 17 16.1 17L19.3 17"/></svg>', d = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M6 7L6 12M6 17L6 12M6 12L12 12M12 7V12M12 17L12 12"/><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M16 11C16 10.5 16.8323 10 17.6 10C18.3677 10 19.5 10.311 19.5 11.5C19.5 12.5315 18.7474 12.9022 18.548 12.9823C18.5378 12.9864 18.5395 13.0047 18.5503 13.0063C18.8115 13.0456 20 13.3065 20 14.8C20 16 19.5 17 17.8 17C17.8 17 16 17 16 16.3"/></svg>', c = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M6 7L6 12M6 17L6 12M6 12L12 12M12 7V12M12 17L12 12"/><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M18 10L15.2834 14.8511C15.246 14.9178 15.294 15 15.3704 15C16.8489 15 18.7561 15 20.2 15M19 17C19 15.7187 19 14.8813 19 13.6"/></svg>', u = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M6 7L6 12M6 17L6 12M6 12L12 12M12 7V12M12 17L12 12"/><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M16 15.9C16 15.9 16.3768 17 17.8 17C19.5 17 20 15.6199 20 14.7C20 12.7323 17.6745 12.0486 16.1635 12.9894C16.094 13.0327 16 12.9846 16 12.9027V10.1C16 10.0448 16.0448 10 16.1 10H19.8"/></svg>', g = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M6 7L6 12M6 17L6 12M6 12L12 12M12 7V12M12 17L12 12"/><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M19.5 10C16.5 10.5 16 13.3285 16 15M16 15V15C16 16.1046 16.8954 17 18 17H18.3246C19.3251 17 20.3191 16.3492 20.2522 15.3509C20.0612 12.4958 16 12.6611 16 15Z"/></svg>', v = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M9 7L9 12M9 17V12M9 12L15 12M15 7V12M15 17L15 12"/></svg>';
3
+ /**
4
+ * Header block for the Editor.js.
5
+ *
6
+ * @author CodeX (team@ifmo.su)
7
+ * @copyright CodeX 2018
8
+ * @license MIT
9
+ * @version 2.0.0
10
+ */
11
+ class p {
12
+ constructor({ data: e, config: t, api: s, readOnly: r }) {
13
+ this.api = s, this.readOnly = r, this._config = t ?? null, this._data = this.normalizeData(e), this._element = this.getTag();
14
+ }
15
+ /**
16
+ * Styles
17
+ */
18
+ get _CSS() {
19
+ return {
20
+ block: this.api.styles.block,
21
+ wrapper: "ce-header"
22
+ };
23
+ }
24
+ /**
25
+ * Check if data is valid
26
+ *
27
+ * @param {any} data - data to check
28
+ * @returns {data is HeaderData}
29
+ * @private
30
+ */
31
+ isHeaderData(e) {
32
+ return e.text !== void 0;
33
+ }
34
+ /**
35
+ * Normalize input data
36
+ *
37
+ * @param {HeaderData} data - saved data to process
38
+ *
39
+ * @returns {HeaderData}
40
+ * @private
41
+ */
42
+ normalizeData(e) {
43
+ const t = { text: "", level: this.defaultLevel.number };
44
+ return this.isHeaderData(e) && (t.text = e.text || "", e.level !== void 0 && !isNaN(parseInt(e.level.toString())) && (t.level = parseInt(e.level.toString()))), t;
45
+ }
46
+ /**
47
+ * Return Tool's view
48
+ *
49
+ * @returns {HTMLHeadingElement}
50
+ * @public
51
+ */
52
+ render() {
53
+ return this._element;
54
+ }
55
+ /**
56
+ * Returns header block tunes config
57
+ *
58
+ * @returns {Array}
59
+ */
60
+ renderSettings() {
61
+ return this.levels.map((e) => ({
62
+ icon: e.svg,
63
+ label: this.api.i18n.t(`Heading ${e.number}`),
64
+ onActivate: () => this.setLevel(e.number),
65
+ closeOnActivate: !0,
66
+ isActive: this.currentLevel.number === e.number,
67
+ render: () => document.createElement("div")
68
+ }));
69
+ }
70
+ /**
71
+ * Callback for Block's settings buttons
72
+ *
73
+ * @param {number} level - level to set
74
+ */
75
+ setLevel(e) {
76
+ this.data = {
77
+ level: e,
78
+ text: this.data.text
79
+ };
80
+ }
81
+ /**
82
+ * Method that specified how to merge two Text blocks.
83
+ * Called by Editor.js by backspace at the beginning of the Block
84
+ *
85
+ * @param {HeaderData} data - saved data to merger with current block
86
+ * @public
87
+ */
88
+ merge(e) {
89
+ this._element.insertAdjacentHTML("beforeend", e.text);
90
+ }
91
+ /**
92
+ * Validate Text block data:
93
+ * - check for emptiness
94
+ *
95
+ * @param {HeaderData} blockData — data received after saving
96
+ * @returns {boolean} false if saved data is not correct, otherwise true
97
+ * @public
98
+ */
99
+ validate(e) {
100
+ return e.text.trim() !== "";
101
+ }
102
+ /**
103
+ * Extract Tool's data from the view
104
+ *
105
+ * @param {HTMLHeadingElement} toolsContent - Text tools rendered view
106
+ * @returns {HeaderData} - saved data
107
+ * @public
108
+ */
109
+ save(e) {
110
+ return {
111
+ text: e.innerHTML,
112
+ level: this.currentLevel.number
113
+ };
114
+ }
115
+ /**
116
+ * Allow Header to be converted to/from other blocks
117
+ */
118
+ static get conversionConfig() {
119
+ return {
120
+ export: "text",
121
+ // use 'text' property for other blocks
122
+ import: "text"
123
+ // fill 'text' property from other block's export string
124
+ };
125
+ }
126
+ /**
127
+ * Sanitizer Rules
128
+ */
129
+ static get sanitize() {
130
+ return {
131
+ level: !1,
132
+ text: {}
133
+ };
134
+ }
135
+ /**
136
+ * Returns true to notify core that read-only is supported
137
+ *
138
+ * @returns {boolean}
139
+ */
140
+ static get isReadOnlySupported() {
141
+ return !0;
142
+ }
143
+ /**
144
+ * Get current Tools`s data
145
+ *
146
+ * @returns {HeaderData} Current data
147
+ * @private
148
+ */
149
+ get data() {
150
+ return this._data.text = this._element.innerHTML, this._data.level = this.currentLevel.number, this._data;
151
+ }
152
+ /**
153
+ * Store data in plugin:
154
+ * - at the this._data property
155
+ * - at the HTML
156
+ *
157
+ * @param {HeaderData} data — data to set
158
+ * @private
159
+ */
160
+ set data(e) {
161
+ if (this._data = this.normalizeData(e), e.level !== void 0 && this._element.parentNode) {
162
+ const t = this.getTag();
163
+ t.innerHTML = this._element.innerHTML, this._element.parentNode.replaceChild(t, this._element), this._element = t;
164
+ }
165
+ e.text !== void 0 && (this._element.innerHTML = this._data.text || "");
166
+ }
167
+ /**
168
+ * Get tag for target level
169
+ * By default returns second-leveled header
170
+ *
171
+ * @returns {HTMLElement}
172
+ */
173
+ getTag() {
174
+ var t;
175
+ const e = document.createElement(this.currentLevel.tag);
176
+ return e.innerHTML = this._data.text || "", e.classList.add(this._CSS.wrapper), e.contentEditable = this.readOnly ? "false" : "true", e.dataset.placeholder = this.api.i18n.t(((t = this._config) == null ? void 0 : t.placeholder) || ""), e;
177
+ }
178
+ /**
179
+ * Get current level
180
+ *
181
+ * @returns {level}
182
+ */
183
+ get currentLevel() {
184
+ let e = this.levels.find((t) => t.number === this._data.level);
185
+ return e || (e = this.defaultLevel), e;
186
+ }
187
+ /**
188
+ * Return default level
189
+ *
190
+ * @returns {level}
191
+ */
192
+ get defaultLevel() {
193
+ var e;
194
+ if ((e = this._config) != null && e.defaultLevel) {
195
+ const t = this.levels.find((s) => {
196
+ var r;
197
+ return s.number === ((r = this._config) == null ? void 0 : r.defaultLevel);
198
+ });
199
+ if (t)
200
+ return t;
201
+ console.warn("(ง'̀-'́)ง Heading Tool: the default level specified was not found in available levels");
202
+ }
203
+ return this.levels[1];
204
+ }
205
+ /**
206
+ * @typedef {object} level
207
+ * @property {number} number - level number
208
+ * @property {string} tag - tag corresponds with level number
209
+ * @property {string} svg - icon
210
+ */
211
+ /**
212
+ * Available header levels
213
+ *
214
+ * @returns {level[]}
215
+ */
216
+ get levels() {
217
+ var t;
218
+ const e = [
219
+ {
220
+ number: 1,
221
+ tag: "H1",
222
+ svg: a
223
+ },
224
+ {
225
+ number: 2,
226
+ tag: "H2",
227
+ svg: h
228
+ },
229
+ {
230
+ number: 3,
231
+ tag: "H3",
232
+ svg: d
233
+ },
234
+ {
235
+ number: 4,
236
+ tag: "H4",
237
+ svg: c
238
+ },
239
+ {
240
+ number: 5,
241
+ tag: "H5",
242
+ svg: u
243
+ },
244
+ {
245
+ number: 6,
246
+ tag: "H6",
247
+ svg: g
248
+ }
249
+ ];
250
+ return (t = this._config) != null && t.levels ? e.filter(
251
+ (s) => {
252
+ var r;
253
+ return (r = this._config) == null ? void 0 : r.levels.includes(s.number);
254
+ }
255
+ ) : e;
256
+ }
257
+ /**
258
+ * Handle H1-H6 tags on paste to substitute it with header Tool
259
+ *
260
+ * @param {PasteEvent} event - event with pasted content
261
+ */
262
+ onPaste(e) {
263
+ var s, r;
264
+ const t = e.detail;
265
+ if ("data" in t) {
266
+ const i = t.data;
267
+ let n = this.defaultLevel.number;
268
+ switch (i.tagName) {
269
+ case "H1":
270
+ n = 1;
271
+ break;
272
+ case "H2":
273
+ n = 2;
274
+ break;
275
+ case "H3":
276
+ n = 3;
277
+ break;
278
+ case "H4":
279
+ n = 4;
280
+ break;
281
+ case "H5":
282
+ n = 5;
283
+ break;
284
+ case "H6":
285
+ n = 6;
286
+ break;
287
+ }
288
+ (s = this._config) != null && s.levels && (n = (r = this._config) == null ? void 0 : r.levels.reduce((o, l) => Math.abs(l - n) < Math.abs(o - n) ? l : o)), this.data = {
289
+ level: n,
290
+ text: i.innerHTML
291
+ };
292
+ }
293
+ }
294
+ /**
295
+ * Used by Editor.js paste handling API.
296
+ * Provides configuration to handle H1-H6 tags.
297
+ *
298
+ * @returns {{handler: (function(HTMLElement): {text: string}), tags: string[]}}
299
+ */
300
+ static get pasteConfig() {
301
+ return {
302
+ tags: ["H1", "H2", "H3", "H4", "H5", "H6"]
303
+ };
304
+ }
305
+ /**
306
+ * Get Tool toolbox settings
307
+ * icon - Tool icon's SVG
308
+ * title - title to show in toolbox
309
+ *
310
+ * @returns {{icon: string, title: string}}
311
+ */
312
+ static get toolbox() {
313
+ return {
314
+ icon: v,
315
+ title: "Heading"
316
+ };
317
+ }
318
+ }
319
+ export {
320
+ p as default
321
+ };