iron-cms 0.19.1 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +7 -8
  3. data/app/assets/builds/iron.css +2125 -2101
  4. data/app/assets/tailwind/iron/application.css +2 -0
  5. data/app/assets/tailwind/iron/components/field-list.css +35 -0
  6. data/app/assets/tailwind/iron/components/translation-notice.css +39 -0
  7. data/app/assets/tailwind/iron/lexxy.css +154 -47
  8. data/app/controllers/iron/blocks_controller.rb +8 -1
  9. data/app/controllers/iron/entries/content_copies_controller.rb +36 -0
  10. data/app/controllers/iron/entries_controller.rb +2 -1
  11. data/app/controllers/iron/references_controller.rb +7 -0
  12. data/app/helpers/iron/entries_helper.rb +24 -0
  13. data/app/helpers/iron/fields_helper.rb +21 -0
  14. data/app/mcp/iron/mcp/tool_context.rb +27 -12
  15. data/app/mcp/iron/mcp/tools/create_entry.rb +4 -3
  16. data/app/mcp/iron/mcp/tools/get_entry.rb +4 -3
  17. data/app/mcp/iron/mcp/tools/list_content_types.rb +1 -1
  18. data/app/mcp/iron/mcp/tools/list_entries.rb +4 -3
  19. data/app/mcp/iron/mcp/tools/search.rb +4 -3
  20. data/app/mcp/iron/mcp/tools/update_entry.rb +4 -3
  21. data/app/models/iron/entry/titlable.rb +29 -11
  22. data/app/models/iron/entry/translatable.rb +53 -0
  23. data/app/models/iron/entry.rb +1 -1
  24. data/app/models/iron/field.rb +14 -0
  25. data/app/models/iron/fields/block.rb +8 -0
  26. data/app/models/iron/fields/block_list.rb +14 -0
  27. data/app/models/iron/fields/boolean.rb +4 -0
  28. data/app/models/iron/fields/file.rb +4 -0
  29. data/app/models/iron/fields/reference_list.rb +8 -0
  30. data/app/models/iron/fields/rich_text_area.rb +10 -0
  31. data/app/views/iron/entries/_entry.html.erb +1 -1
  32. data/app/views/iron/entries/_entry_option.html.erb +4 -3
  33. data/app/views/iron/entries/_translation_notice.html.erb +32 -0
  34. data/app/views/iron/entries/edit.html.erb +14 -4
  35. data/app/views/iron/entries/entry.html.erb +8 -4
  36. data/app/views/iron/entries/fields/_block_list.html.erb +6 -22
  37. data/app/views/iron/entries/fields/_reference.html.erb +1 -1
  38. data/app/views/iron/entries/fields/_reference_item.html.erb +2 -2
  39. data/app/views/iron/entries/fields/_reference_list.html.erb +12 -3
  40. data/app/views/iron/entries/fields/block_list/_empty_state.html.erb +49 -0
  41. data/app/views/iron/entries/fields/block_list/_menu.html.erb +14 -0
  42. data/app/views/iron/entries/search.html.erb +3 -1
  43. data/app/views/iron/home/_recent_activity.html.erb +1 -1
  44. data/config/locales/en.yml +32 -0
  45. data/config/locales/it.yml +32 -0
  46. data/config/routes.rb +10 -0
  47. data/lib/iron/version.rb +1 -1
  48. metadata +18 -5
@@ -22,6 +22,8 @@
22
22
  @import './components/block-card.css';
23
23
  @import './components/field-definition.css';
24
24
  @import './components/reference-item.css';
25
+ @import './components/field-list.css';
26
+ @import './components/translation-notice.css';
25
27
  @import './components/save-bar.css';
26
28
  @import './components/drawer.css';
27
29
  @import './components/modal.css';
@@ -0,0 +1,35 @@
1
+ @layer components {
2
+ .field-list {
3
+ &:has(> .field-list-items > [data-sortable-list-target~="item"] > [data-destroy]:not(:checked)) > .field-list-empty {
4
+ @apply hidden;
5
+ }
6
+
7
+ &:not(:has(> .field-list-items > [data-sortable-list-target~="item"] > [data-destroy]:not(:checked))) > .field-list-items {
8
+ @apply hidden;
9
+ }
10
+ }
11
+
12
+ .field-list-empty {
13
+ @apply flex flex-col items-center px-6 py-10 text-center;
14
+ @apply rounded-xl border border-dashed border-stone-300;
15
+ @apply dark:border-white/15;
16
+ }
17
+
18
+ .field-list-empty-icon {
19
+ @apply flex items-center justify-center size-10 rounded-lg;
20
+ @apply bg-white text-stone-400 shadow-xs ring-1 ring-stone-900/5;
21
+ @apply dark:bg-white/5 dark:shadow-none dark:ring-0;
22
+ }
23
+
24
+ .field-list-empty-title {
25
+ @apply mt-4 text-sm font-medium text-stone-900 dark:text-white;
26
+ }
27
+
28
+ .field-list-empty-description {
29
+ @apply mt-1 max-w-lg text-sm text-stone-500 dark:text-stone-400;
30
+ }
31
+
32
+ .field-list-empty-actions {
33
+ @apply mt-4 flex flex-wrap justify-center gap-2;
34
+ }
35
+ }
@@ -0,0 +1,39 @@
1
+ @layer components {
2
+ .translation-notice {
3
+ @apply flex flex-wrap items-start gap-4 rounded-xl p-5 mb-10;
4
+ @apply bg-amber-50 ring-1 ring-amber-200;
5
+ @apply dark:bg-amber-500/5 dark:ring-amber-500/20;
6
+ }
7
+
8
+ .translation-notice-icon {
9
+ @apply flex items-center justify-center size-10 shrink-0 rounded-lg;
10
+ @apply bg-amber-100 text-amber-600;
11
+ @apply dark:bg-amber-500/15 dark:text-amber-400;
12
+ }
13
+
14
+ .translation-notice-title {
15
+ @apply text-sm/6 font-semibold text-amber-900 dark:text-amber-200;
16
+ }
17
+
18
+ .translation-notice-description {
19
+ @apply mt-1 max-w-2xl text-sm/6 text-stone-600 dark:text-stone-300;
20
+ }
21
+
22
+ .translation-notice-actions {
23
+ @apply mt-4 flex flex-wrap gap-2;
24
+ }
25
+
26
+ .translation-notice-unsaved {
27
+ @apply mt-3 hidden text-sm text-stone-500 dark:text-stone-400;
28
+ }
29
+
30
+ .translation-notice:has(~ form[data-dirty="true"]) {
31
+ .translation-notice-copy {
32
+ @apply hidden;
33
+ }
34
+
35
+ .translation-notice-unsaved {
36
+ @apply block;
37
+ }
38
+ }
39
+ }
@@ -28,8 +28,9 @@
28
28
 
29
29
  @layer components {
30
30
  /* Editor container — must establish a positioning context so lexxy's
31
- absolutely-positioned children (language picker, table tools, delete
32
- buttons) anchor to the editor instead of leaking to the document. */
31
+ absolutely-positioned children (language picker, table tools, attachment
32
+ toolbar, caption editor) anchor to the editor instead of leaking to the
33
+ document. */
33
34
  lexxy-editor {
34
35
  @apply relative block w-full rounded-xl;
35
36
  @apply bg-white dark:bg-white/5;
@@ -57,8 +58,7 @@
57
58
 
58
59
  /* Toolbar buttons — square, icon-only. Buttons that live inside dropdown
59
60
  panels are reshaped by the panel rules below. */
60
- lexxy-toolbar button,
61
- lexxy-toolbar summary {
61
+ lexxy-toolbar button {
62
62
  @apply inline-flex items-center justify-center;
63
63
  @apply h-8 w-8 rounded-md;
64
64
  @apply text-stone-700 dark:text-stone-200;
@@ -75,8 +75,7 @@
75
75
  @apply dark:bg-white/15 dark:text-white;
76
76
  }
77
77
 
78
- lexxy-toolbar button svg,
79
- lexxy-toolbar summary svg {
78
+ lexxy-toolbar button svg {
80
79
  @apply size-5 text-inherit;
81
80
  fill: currentColor;
82
81
  }
@@ -172,7 +171,7 @@
172
171
  @apply hover:bg-stone-100 dark:hover:bg-white/10;
173
172
  }
174
173
 
175
- .lexxy-editor__toolbar-dropdown-list button[aria-pressed="true"] {
174
+ .lexxy-editor__toolbar-dropdown-list button[aria-checked="true"] {
176
175
  @apply bg-sky-100 text-sky-900;
177
176
  @apply dark:bg-sky-500/20 dark:text-sky-100;
178
177
  }
@@ -202,7 +201,8 @@
202
201
  @apply flex items-center gap-2 p-2 min-w-[22rem];
203
202
  }
204
203
 
205
- lexxy-link-dropdown input[type="url"] {
204
+ /* Lexxy 1.0.4 renders the URL field as type="text" with inputmode="url". */
205
+ lexxy-link-dropdown input {
206
206
  @apply flex-1 min-w-0;
207
207
  @apply h-8 px-2 rounded-md;
208
208
  @apply border border-stone-300 dark:border-white/10;
@@ -210,7 +210,7 @@
210
210
  @apply text-sm leading-none text-stone-900 dark:text-white;
211
211
  @apply placeholder:text-stone-400 dark:placeholder:text-stone-500;
212
212
  @apply outline-none;
213
- @apply focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-sky-600 focus-visible:border-transparent dark:focus-visible:outline-sky-500;
213
+ @apply focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-sky-600 focus-visible:border-transparent dark:focus-visible:outline-sky-500;
214
214
  }
215
215
 
216
216
  lexxy-link-dropdown .lexxy-editor__toolbar-dropdown-actions {
@@ -237,9 +237,10 @@
237
237
  }
238
238
 
239
239
  /* Highlight/Color dropdown
240
- Lexxy emits N text-color buttons followed by N background-color buttons.
241
- A 2-row grid with `grid-auto-flow: column` fills column-by-column, so each
242
- column pairs a color with its background (row 1 = color, row 2 = bg). */
240
+ Lexxy emits a group of N text-color buttons followed by a group of N
241
+ background-color buttons. The groups dissolve into the grid, and a 2-row
242
+ grid with `grid-auto-flow: column` fills column-by-column, so each column
243
+ pairs a color with its background (row 1 = color, row 2 = bg). */
243
244
  lexxy-highlight-dropdown [data-dropdown-panel] {
244
245
  @apply flex flex-col gap-2 p-2;
245
246
  }
@@ -253,6 +254,10 @@
253
254
  @apply gap-1;
254
255
  }
255
256
 
257
+ lexxy-highlight-dropdown .lexxy-highlight-colors__group {
258
+ @apply contents;
259
+ }
260
+
256
261
  lexxy-highlight-dropdown .lexxy-highlight-button {
257
262
  @apply relative rounded-md p-0;
258
263
  width: var(--button-size);
@@ -274,12 +279,12 @@
274
279
  }
275
280
 
276
281
  /* Selected state — transparent bg with a thick inset ring in the swatch's color */
277
- lexxy-highlight-dropdown .lexxy-highlight-button[aria-pressed="true"] {
282
+ lexxy-highlight-dropdown .lexxy-highlight-button[aria-checked="true"] {
278
283
  background-color: transparent;
279
284
  box-shadow: inset 0 0 0 2px currentColor;
280
285
  }
281
286
 
282
- lexxy-highlight-dropdown .lexxy-highlight-button[aria-pressed="true"]::after {
287
+ lexxy-highlight-dropdown .lexxy-highlight-button[aria-checked="true"]::after {
283
288
  content: "✓";
284
289
  }
285
290
 
@@ -370,6 +375,44 @@
370
375
  @apply mt-1;
371
376
  }
372
377
 
378
+ /* Captions show as text; clicking one opens lexxy's caption editor over it.
379
+ Without a caption, lexxy shows the file name as a one-line placeholder. */
380
+ lexxy-editor .attachment__caption--editable {
381
+ @apply cursor-text;
382
+ }
383
+
384
+ lexxy-editor .attachment__caption-text {
385
+ @apply block min-h-lh whitespace-pre-wrap wrap-anywhere;
386
+ }
387
+
388
+ lexxy-editor .attachment__caption--editable[data-placeholder] .attachment__caption-text {
389
+ @apply truncate;
390
+ }
391
+
392
+ /* While editing, the caption holds its height and the editor covers it. */
393
+ lexxy-editor .attachment__caption--editing .attachment__caption-text {
394
+ @apply hidden;
395
+ }
396
+
397
+ /* Lexxy keeps the caption field outside the editable region so screen
398
+ readers reach it, and positions it over the caption being edited. */
399
+ .lexxy-caption-editor {
400
+ @apply absolute z-10 box-border p-0 overflow-hidden resize-none;
401
+ @apply bg-transparent border-0 rounded outline-none;
402
+ @apply placeholder:text-stone-400 dark:placeholder:text-stone-500;
403
+ }
404
+
405
+ /* Announcements and the label of a selected attachment exist only for
406
+ screen readers. The label must stay selectable for the DOM Selection API. */
407
+ lexxy-live-region,
408
+ .lexxy-fake-selection {
409
+ @apply sr-only;
410
+ }
411
+
412
+ .lexxy-fake-selection {
413
+ @apply select-text;
414
+ }
415
+
373
416
  lexxy-editor .attachment__toolbar {
374
417
  @apply absolute z-10 top-2 right-2;
375
418
  @apply flex items-center gap-1;
@@ -395,7 +438,7 @@
395
438
  @apply rounded;
396
439
  }
397
440
 
398
- /* Floating controls (delete button, table tools, etc.) */
441
+ /* Floating controls (attachment toolbar, table tools, etc.) */
399
442
  .lexxy-floating-controls {
400
443
  @apply absolute z-10;
401
444
  @apply text-white text-sm leading-none;
@@ -407,8 +450,7 @@
407
450
  @apply shadow-md;
408
451
  }
409
452
 
410
- .lexxy-floating-controls button,
411
- .lexxy-floating-controls summary {
453
+ .lexxy-floating-controls button {
412
454
  @apply inline-flex items-center justify-center;
413
455
  @apply h-7 min-w-7 px-1 rounded;
414
456
  @apply text-white hover:bg-white/15;
@@ -421,10 +463,90 @@
421
463
  fill: currentColor;
422
464
  }
423
465
 
424
- lexxy-node-delete-button .lexxy-node-delete:hover {
466
+ /* Attachment toolbar — lexxy shows a single toolbar for the selected
467
+ attachment or divider and publishes that node's box, relative to the
468
+ editor, as --lexxy-anchor-* properties. Pin it inside the top trailing
469
+ corner of image previews and gallery images. */
470
+ lexxy-attachment-toolbar {
471
+ left: calc(var(--lexxy-anchor-left) + var(--lexxy-anchor-width));
472
+ top: var(--lexxy-anchor-top);
473
+ @apply -translate-x-[calc(100%+0.25rem)] translate-y-1;
474
+ }
475
+
476
+ /* A divider is too thin to hold the toolbar: center it on the divider's end. */
477
+ lexxy-attachment-toolbar[data-node-type="horizontal_divider"] {
478
+ top: calc(var(--lexxy-anchor-top) + var(--lexxy-anchor-height) / 2);
479
+ @apply -translate-y-1/2;
480
+ }
481
+
482
+ /* File chips and inline attachments are too small to hold it: float it just
483
+ past the node's selection ring, and flip it back over the node when it
484
+ would overflow the editor. */
485
+ lexxy-attachment-toolbar[data-presentation="block"]:not([data-node-type="horizontal_divider"]),
486
+ lexxy-attachment-toolbar[data-presentation="inline"] {
487
+ top: calc(var(--lexxy-anchor-top) + var(--lexxy-anchor-height) / 2);
488
+ @apply translate-x-1.5 -translate-y-1/2;
489
+ }
490
+
491
+ lexxy-attachment-toolbar[data-presentation="block"][data-overflow]:not([data-node-type="horizontal_divider"]),
492
+ lexxy-attachment-toolbar[data-presentation="inline"][data-overflow] {
493
+ @apply -translate-x-full;
494
+ }
495
+
496
+ .lexxy-attachment-toolbar__remove:hover,
497
+ .lexxy-attachment-toolbar__remove:focus-visible {
425
498
  @apply bg-red-600;
426
499
  }
427
500
 
501
+ /* Lexxy reveals the ALT button only when the host's Action Text stores an
502
+ `alt` on attachments. */
503
+ .lexxy-attachment-toolbar__alternative-text {
504
+ @apply text-xs font-semibold tracking-wide;
505
+ }
506
+
507
+ /* Alternative-text dialog — a non-modal <dialog> lexxy opens beneath the
508
+ selected image, publishing the image's bottom edge, relative to the editor,
509
+ as --lexxy-anchor-bottom. Dressed like the link dropdown. Leave `display`
510
+ to the browser so the closed dialog stays hidden. */
511
+ .lexxy-alternative-text-dialog {
512
+ @apply absolute z-20 inset-x-0 mx-auto my-0 w-3/5 min-w-[min(20rem,100%)] p-3;
513
+ top: calc(var(--lexxy-anchor-bottom) + --spacing(2));
514
+ @apply bg-white dark:bg-stone-800;
515
+ @apply border-2 border-sky-200 dark:border-sky-500/30;
516
+ @apply rounded-md shadow-lg;
517
+ @apply text-stone-900 dark:text-white;
518
+ }
519
+
520
+ .lexxy-alternative-text-dialog__controls {
521
+ @apply flex flex-col gap-2;
522
+ }
523
+
524
+ .lexxy-alternative-text-dialog textarea {
525
+ @apply textarea min-h-[calc(2lh+--spacing(3))] resize-none field-sizing-content;
526
+ }
527
+
528
+ .lexxy-alternative-text-dialog__actions {
529
+ @apply flex justify-end gap-2;
530
+ }
531
+
532
+ .lexxy-alternative-text-dialog__actions button {
533
+ @apply h-8 px-3 rounded-md;
534
+ @apply text-sm font-medium leading-none;
535
+ @apply bg-white dark:bg-white/10;
536
+ @apply text-stone-700 dark:text-stone-200;
537
+ @apply ring-1 ring-inset ring-stone-300 dark:ring-white/15;
538
+ @apply hover:bg-stone-50 dark:hover:bg-white/15;
539
+ /* The entry form dresses every button with button-base, whose outline-none
540
+ also silences outline widths; restore the style to show a focus ring. */
541
+ @apply focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-offset-2;
542
+ @apply focus-visible:outline-sky-600 dark:focus-visible:outline-sky-500;
543
+ }
544
+
545
+ .lexxy-alternative-text-dialog__actions .lexxy-alternative-text-dialog__save {
546
+ @apply bg-sky-600 text-white ring-0;
547
+ @apply hover:bg-sky-700;
548
+ }
549
+
428
550
  /* Tables in the editor */
429
551
  lexxy-editor table {
430
552
  @apply w-full !my-0 border-collapse text-sm;
@@ -538,9 +660,10 @@
538
660
  @apply -translate-x-1/2 -translate-y-[calc(100%+4px)];
539
661
  }
540
662
 
541
- /* Icon-only buttons are square; summary stays auto-width so its count text
542
- ("3 rows") can render inline. Apply only to direct children of the row /
543
- column / delete groups so menu items inside the dropdown can grow. */
663
+ /* Icon-only buttons are square; the more-menu trigger stays auto-width so
664
+ its count text ("3 rows") can render inline. Apply only to direct children
665
+ of the row / column / delete groups so menu items inside the dropdown can
666
+ grow. */
544
667
  lexxy-table-tools .lexxy-table-control > .lexxy-table-control__button {
545
668
  @apply w-7 font-bold;
546
669
  }
@@ -550,21 +673,13 @@
550
673
  @apply hidden;
551
674
  }
552
675
 
553
- /* Summary holds the visible row/column count; suppress the default marker */
554
- lexxy-table-tools summary {
555
- list-style: none;
556
- @apply font-normal whitespace-nowrap cursor-pointer;
676
+ /* The more-menu trigger holds the visible row/column count */
677
+ lexxy-table-tools .lexxy-table-control__more-menu-trigger {
678
+ @apply px-2 font-normal whitespace-nowrap;
679
+ @apply aria-expanded:bg-white/15;
557
680
  }
558
681
 
559
- lexxy-table-tools summary::-webkit-details-marker {
560
- display: none;
561
- }
562
-
563
- lexxy-table-tools summary::marker {
564
- content: "";
565
- }
566
-
567
- /* More-menu dropdown anchors directly under its summary */
682
+ /* More-menu dropdown anchors directly under its trigger */
568
683
  lexxy-table-tools .lexxy-table-control__more-menu {
569
684
  @apply relative;
570
685
  }
@@ -853,19 +968,11 @@
853
968
  @apply bg-stone-300 dark:bg-stone-600;
854
969
  }
855
970
 
856
- /* Per-node delete button (appears on hover or selection) */
857
- lexxy-node-delete-button {
858
- @apply absolute z-10 opacity-0 pointer-events-none transition-opacity;
859
- inset-block-start: 0.25rem;
860
- inset-inline-end: 0.25rem;
861
- inset-inline-start: auto;
862
- }
863
-
864
- lexxy-editor figure:hover > lexxy-node-delete-button,
865
- lexxy-editor .attachment:hover > lexxy-node-delete-button,
866
- lexxy-editor .node--selected > lexxy-node-delete-button,
867
- lexxy-editor .node--selected lexxy-node-delete-button {
868
- @apply opacity-100 pointer-events-auto;
971
+ /* The alternative-text dialog's prompt is an <h2>, not a content heading.
972
+ Prose zeroes the top margin of whatever follows an h2, so the gap below
973
+ the prompt hangs off the heading. */
974
+ lexxy-editor .lexxy-alternative-text-dialog h2 {
975
+ @apply mt-0 mb-2 text-sm font-medium text-stone-900 dark:text-white;
869
976
  }
870
977
 
871
978
  /* Tailwind Typography wraps inline <code> with backtick pseudo-elements; suppress them */
@@ -1,12 +1,19 @@
1
1
  module Iron
2
2
  class BlocksController < ApplicationController
3
+ before_action :set_locale
4
+
3
5
  def new
4
6
  @block_list = Fields::BlockList.build(
5
- locale: Locale.find(params[:locale_id]),
7
+ locale: Current.locale,
6
8
  definition: FieldDefinition.find(params[:block_list_field_definition_id]),
7
9
  )
8
10
  @block = @block_list.blocks.build_for(BlockDefinition.find(params[:block_definition_id]))
9
11
  @form_field_name = params[:form_field_name]
10
12
  end
13
+
14
+ private
15
+ def set_locale
16
+ Current.locale = Locale.find(params[:locale_id])
17
+ end
11
18
  end
12
19
  end
@@ -0,0 +1,36 @@
1
+ module Iron
2
+ class Entries::ContentCopiesController < ApplicationController
3
+ before_action :ensure_can_write
4
+ before_action :set_entry, :set_locales
5
+
6
+ rescue_from ActiveRecord::RecordInvalid do |error|
7
+ redirect_to edit_path, alert: t(".invalid", source: @source.name, field: error.record.definition.name, error: error.record.errors.full_messages.to_sentence)
8
+ end
9
+
10
+ def create
11
+ if @entry.copy_content(from: @source, to: @target)
12
+ redirect_to edit_path, notice: t(".copied", source: @source.name, target: @target.name)
13
+ else
14
+ redirect_to edit_path, alert: t(".skipped", source: @source.name, target: @target.name)
15
+ end
16
+ end
17
+
18
+ private
19
+ def set_entry
20
+ @entry = Entry.find(params.expect(:entry_id))
21
+ end
22
+
23
+ def set_locales
24
+ @source = Locale.find_by!(code: params.expect(:from))
25
+ @target = Locale.find_by!(code: params.expect(:to))
26
+ end
27
+
28
+ def edit_path
29
+ if @entry.content_type.single?
30
+ entry_content_type_path(@entry.content_type, locale: @target.code)
31
+ else
32
+ edit_entry_path(@entry, locale: @target.code)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -80,7 +80,8 @@ module Iron
80
80
 
81
81
  def set_locale
82
82
  @locale = Locale.find_by(code: params[:locale]) if params[:locale].present?
83
- @locale ||= Locale.first
83
+ @locale ||= Locale.default || Locale.first
84
+ Current.locale = @locale
84
85
  end
85
86
 
86
87
  def set_entry
@@ -1,5 +1,7 @@
1
1
  module Iron
2
2
  class ReferencesController < ApplicationController
3
+ before_action :set_locale
4
+
3
5
  def new
4
6
  @form_field_name = params[:form_field_name]
5
7
  @reference_list_dom_id = params[:reference_list_dom_id]
@@ -7,5 +9,10 @@ module Iron
7
9
  @entry = Entry.find(params[:entry_id])
8
10
  @reference = Reference.build(entry: @entry)
9
11
  end
12
+
13
+ private
14
+ def set_locale
15
+ Current.locale = Locale.find_by(code: params[:locale])
16
+ end
10
17
  end
11
18
  end
@@ -6,4 +6,28 @@ module Iron::EntriesHelper
6
6
  Iron::Entry.find(params[:id]).content_type == content_type
7
7
  )
8
8
  end
9
+
10
+ def entry_editor_path(entry, locale:)
11
+ if entry.content_type.single?
12
+ entry_content_type_path(entry.content_type, locale: locale.code)
13
+ else
14
+ edit_entry_path(entry, locale: locale.code)
15
+ end
16
+ end
17
+
18
+ def locale_content_status(entry, locale)
19
+ if entry.written_in?(locale)
20
+ tag.span class: "ms-auto inline-flex items-center gap-1.5 text-xs text-stone-500 dark:text-stone-400" do
21
+ safe_join [ tag.span(class: "size-2 rounded-full bg-sky-500 dark:bg-sky-400", aria: { hidden: true }), t("iron.entries.locale_status.written") ]
22
+ end
23
+ elsif entry.needs_translation_into?(locale)
24
+ tag.span class: "ms-auto inline-flex items-center gap-1.5 text-xs text-amber-700 dark:text-amber-300" do
25
+ safe_join [ untranslated_dot, t("iron.entries.locale_status.untranslated") ]
26
+ end
27
+ end
28
+ end
29
+
30
+ def untranslated_dot(**options)
31
+ tag.span class: "size-2 shrink-0 rounded-full border-[1.5px] border-amber-500 dark:border-amber-400", aria: { hidden: true }, **options
32
+ end
9
33
  end
@@ -1,5 +1,7 @@
1
1
  module Iron
2
2
  module FieldsHelper
3
+ QUICK_PICK_LIMIT = 4
4
+
3
5
  def file_field_fallback_icon(field)
4
6
  case field.file.blob.content_type
5
7
  when "application/pdf" then "file-text"
@@ -8,5 +10,24 @@ module Iron
8
10
  else "file"
9
11
  end
10
12
  end
13
+
14
+ def new_block_in_list_path(block_list, block_definition, builder)
15
+ new_block_path(
16
+ block_list_field_definition_id: block_list.definition.id,
17
+ block_definition_id: block_definition.id,
18
+ locale_id: block_list.locale.id,
19
+ form_field_name: builder.field_name(:blocks_attributes),
20
+ )
21
+ end
22
+
23
+ def block_quick_picks(block_list)
24
+ block_definitions = block_list.definition.supported_block_definitions.to_a
25
+
26
+ if block_definitions.size > QUICK_PICK_LIMIT
27
+ [ block_definitions.first(QUICK_PICK_LIMIT - 1), block_definitions.drop(QUICK_PICK_LIMIT - 1) ]
28
+ else
29
+ [ block_definitions, [] ]
30
+ end
31
+ end
11
32
  end
12
33
  end
@@ -20,32 +20,34 @@ module Iron
20
20
  end
21
21
  end
22
22
 
23
- def list_entries(handle:, route: nil, after: nil, per_page: nil)
24
- return Iron::Content.get(handle, route:, locale: locale_code) if route.present?
23
+ def list_entries(handle:, route: nil, after: nil, per_page: nil, locale: nil)
24
+ return Iron::Content.get(handle, route:, locale: effective_locale(locale)) if route.present?
25
25
 
26
26
  content_type = ContentType.find_by!(handle:)
27
- serialize_collection(Paginator.new(after:, per_page:).call(content_type.entries))
27
+ in_locale(locale) { serialize_collection(Paginator.new(after:, per_page:).call(content_type.entries)) }
28
28
  end
29
29
 
30
- def get_entry(handle:, id: nil, route: nil)
31
- Iron::Content.get(handle, id:, route:, locale: locale_code)
30
+ def get_entry(handle:, id: nil, route: nil, locale: nil)
31
+ Iron::Content.get(handle, id:, route:, locale: effective_locale(locale))
32
32
  end
33
33
 
34
- def search(query:, after: nil, per_page: nil)
34
+ def search(query:, after: nil, per_page: nil, locale: nil)
35
35
  raise InvalidRequest, "query is required" if query.blank?
36
36
 
37
- scope = Entry.search(query, locale: Current.locale)
38
- serialize_collection(Paginator.new(after:, per_page:).call(scope))
37
+ in_locale(locale) do
38
+ scope = Entry.search(query, locale: Current.locale)
39
+ serialize_collection(Paginator.new(after:, per_page:).call(scope))
40
+ end
39
41
  end
40
42
 
41
- def create_entry(handle:, content:, route: nil)
43
+ def create_entry(handle:, content:, route: nil, locale: nil)
42
44
  authorize_write!
43
- Iron::Content.create(handle, content, route:, locale: locale_code, actor: Current.user, allow_local_files: false)
45
+ Iron::Content.create(handle, content, route:, locale: effective_locale(locale), actor: Current.user, allow_local_files: false)
44
46
  end
45
47
 
46
- def update_entry(handle:, content:, id: nil, route: nil)
48
+ def update_entry(handle:, content:, id: nil, route: nil, locale: nil)
47
49
  authorize_write!
48
- Iron::Content.update(handle, content, id:, route:, locale: locale_code, actor: Current.user, allow_local_files: false)
50
+ Iron::Content.update(handle, content, id:, route:, locale: effective_locale(locale), actor: Current.user, allow_local_files: false)
49
51
  end
50
52
 
51
53
  def delete_entry(handle:, id: nil, route: nil)
@@ -75,6 +77,19 @@ module Iron
75
77
  Current.locale&.code
76
78
  end
77
79
 
80
+ # An explicit tool `locale` overrides the locale the connector URL
81
+ # resolved into Current.locale, so one connector can reach every locale.
82
+ def effective_locale(locale)
83
+ locale.presence || locale_code
84
+ end
85
+
86
+ def in_locale(locale)
87
+ code = effective_locale(locale)
88
+ return yield if code.blank?
89
+
90
+ Current.set(locale: Locale.find_by!(code:)) { yield }
91
+ end
92
+
78
93
  def serialize_collection(page)
79
94
  {
80
95
  "data" => page.records.map { |entry| Iron::Content.serialize(entry) },
@@ -14,13 +14,14 @@ module Iron
14
14
  properties: {
15
15
  handle: { type: "string", description: "Collection content type handle" },
16
16
  content: { type: "object", description: "Field handles to values (see describe_schema)" },
17
- route: { type: "string", description: "Optional route for web-published types" }
17
+ route: { type: "string", description: "Optional route for web-published types" },
18
+ locale: { type: "string", description: "Locale code to write, e.g. \"en\". Defaults to the connector's locale." }
18
19
  },
19
20
  required: [ "handle", "content" ]
20
21
  )
21
22
 
22
- def self.perform(context, handle:, content:, route: nil)
23
- context.create_entry(handle:, content:, route:)
23
+ def self.perform(context, handle:, content:, route: nil, locale: nil)
24
+ context.create_entry(handle:, content:, route:, locale:)
24
25
  end
25
26
  end
26
27
  end
@@ -11,13 +11,14 @@ module Iron
11
11
  properties: {
12
12
  handle: { type: "string", description: "Content type handle" },
13
13
  id: { type: "integer", description: "Entry id (collection types)" },
14
- route: { type: "string", description: "Entry route (web-published types)" }
14
+ route: { type: "string", description: "Entry route (web-published types)" },
15
+ locale: { type: "string", description: "Locale code to read, e.g. \"en\". Defaults to the connector's locale." }
15
16
  },
16
17
  required: [ "handle" ]
17
18
  )
18
19
 
19
- def self.perform(context, handle:, id: nil, route: nil)
20
- context.get_entry(handle:, id:, route:)
20
+ def self.perform(context, handle:, id: nil, route: nil, locale: nil)
21
+ context.get_entry(handle:, id:, route:, locale:)
21
22
  end
22
23
  end
23
24
  end
@@ -12,7 +12,7 @@ module Iron
12
12
  input_schema(properties: {})
13
13
 
14
14
  def self.perform(context)
15
- context.list_content_types
15
+ { "content_types" => context.list_content_types }
16
16
  end
17
17
  end
18
18
  end