From 51d491a3d67e8c9efde8019ecb8a8e1a8195ec99 Mon Sep 17 00:00:00 2001 From: erdgeist Date: Sun, 5 Jul 2026 21:51:15 +0200 Subject: Add erfa/chaostreff node-kind creation conventions lib/ccc_conventions.rb: NODE_KINDS registry replaces the kind-specific branches previously scattered across nodes_controller#create (tags), unique_path-position check). Each kind declares its parent lookup (a Proc - Update's "update"/"press_release" continue to genuinely find-or-create their year-folder via Update.find_or_create_parent; erfa/chaostreff use a plain find_by_unique_name!, since their parent nodes are fixed and a missing one should fail loudly, not be silently created), its tags, and (new) its default template. Node gains a default_template_name column (migration, with backfill for existing update-tree nodes via node.update? - reusing that method rather than re-deriving its unique_path check in raw SQL). Page#set_template now inherits from node.default_template_name, falling back to the old update?-based check only when the column is blank, and only fills in template_name when nothing's already been explicitly chosen - a deliberate change from the previous behavior, which unconditionally overwrote template_name on every save regardless of manual selection. Node#update? itself is unchanged and still used as-is by admin_controller's sitemap filtering - a genuinely different, still valid use of that check. "generic" stays special-cased in the controller, parametrized by params[:parent_id] at request time - doesn't fit "kind implies a fixed lookup" and isn't in the registry. nodes#new's four hardcoded radio buttons and nodes_controller's kind-specific case/when branches are both replaced by iterating/looking up this one registry - adding a new kind now means one new hash entry, not four scattered edits. --- app/controllers/nodes_controller.rb | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) (limited to 'app/controllers/nodes_controller.rb') diff --git a/app/controllers/nodes_controller.rb b/app/controllers/nodes_controller.rb index 494887d..1e1def2 100644 --- a/app/controllers/nodes_controller.rb +++ b/app/controllers/nodes_controller.rb @@ -33,17 +33,17 @@ class NodesController < ApplicationController @node = Node.new @node.parent_id = find_parent - @node.slug = params[:title].parameterize.to_s - + @node.slug = slug_for(params[:title]) + + config = CccConventions::NODE_KINDS[params[:kind]] + if @node.save @node.draft.update(:title => params[:title]) - case params[:kind] - when "update" - @node.draft.tag_list.add("update") - when "press_release" - @node.draft.tag_list.add("update", "pressemitteilung") - end + Array(config && config[:tags]).each { |t| @node.draft.tag_list.add(t) } @node.draft.save! + + @node.update!(default_template_name: config[:template]) if config && config[:template] + redirect_to(edit_node_path(@node)) else render :new @@ -103,9 +103,17 @@ class NodesController < ApplicationController redirect_to node_path(@node) end - + + def parameterize_preview + render plain: slug_for(params[:title]) + end + private + def slug_for(title) + title.to_s.parameterize + end + def node_params params.fetch(:node, {}).permit(:slug, :parent_id, :staged_slug, :staged_parent_id) end @@ -120,18 +128,15 @@ class NodesController < ApplicationController def find_parent case params[:kind] - when "top_level" - Node.root.id - when "update" - Update.find_or_create_parent.id - when "press_release" - Update.find_or_create_parent.id when "generic" if params[:parent_id] && Node.find(params[:parent_id]) params[:parent_id] else nil end + else + config = CccConventions::NODE_KINDS[params[:kind]] + config && config[:parent] ? config[:parent].call.id : nil end end end -- cgit v1.3