feat: add page_settings JSON property + ACE JSON mode

- Add property :page_settings (Hash, default {}) to Page model
- JSON.parse string input in setter (form submits as text)
- Add collapsible 'Page Settings (JSON)' section to page form
- Support data-mode='json' attribute for ACE editor
  (html_edit.js.coffee: check textarea data-mode attribute)
This commit is contained in:
BenClaw
2026-05-30 20:33:15 +02:00
parent 37cbb428c6
commit 548a227617
3 changed files with 17 additions and 0 deletions
@@ -17,6 +17,10 @@ class HtmlEdit
editor.setValue template_field.val(), -1
editor.getSession().setMode 'ace/mode/slim'
console.log "Editing Emblem using Slim mode for ACE editor"
else if data_mode = text_field.data('mode')
editor.setValue text_field.val(), -1
editor.getSession().setMode "ace/mode/#{data_mode}"
console.log "Editing #{data_mode} using ACE editor"
else
editor.setValue text_field.val(), -1
editor.getSession().setMode 'ace/mode/handlebars'
+6
View File
@@ -37,6 +37,12 @@ javascript:
.field
= f.label :footer
= f.text_area :footer, rows: 15, cols: 80, class: 'html-content'
= collapsible_content 'Page Settings (JSON)' do
.field
= f.label :page_settings
%p.help-text JSON configuration for this page. Use Ace editor in JSON mode.
= f.text_area :page_settings, rows: 12, cols: 80, class: 'html-content', 'data-mode' => 'json',
value: (f.object.page_settings.presence || {}).to_json
.form-row
.form-label= f.label :parent_id
.form-field= f.select :parent_id, tree_options_for_select(Page.full_tree(@page.locale || Page.locales.first), exclude: @page.id, selected: @page.parent_id), include_blank: ' -- '
+7
View File
@@ -21,6 +21,13 @@ module Cmtool
klass.property :active, type: :boolean, default: true
klass.property :layout
klass.property :in_menu, type: :boolean, default: true
klass.property :page_settings, default: {}
# Parse JSON string from form submission
klass.send(:define_method, :page_settings=) do |val|
val = JSON.parse(val) if val.is_a?(String)
super(val)
end
klass.has_ancestry by_property: :locale