From 4c47031f9693fc04b01cbb005ad864cd1e3d2425 Mon Sep 17 00:00:00 2001 From: erdgeist Date: Mon, 6 Jul 2026 04:15:46 +0200 Subject: Add erfa/chaostreff node-kind creation conventions, part 2 The following changes were already announced in the last commit, but the files forgotten. Here's them actually attached. 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. New read-only admin/conventions view dumps the NODE_KINDS registry as a reference table for whoever's confused later about how a given kind behaves - deliberately just renders the same label/hint text used on nodes#new rather than re-describing parent/tags/template separately, since decomposing the parent Proc would mean either invoking it (Update's has a real side effect - creates the year folder) or re-stating its logic a second time in a different shape, either of which risks drifting from the actual behavior. --- lib/ccc_conventions.rb | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 lib/ccc_conventions.rb (limited to 'lib') diff --git a/lib/ccc_conventions.rb b/lib/ccc_conventions.rb new file mode 100644 index 0000000..c0f9943 --- /dev/null +++ b/lib/ccc_conventions.rb @@ -0,0 +1,47 @@ +module CccConventions + ERFA_PARENT_NAME = "club/erfas" + CHAOSTREFF_PARENT_NAME = "club/chaostreffs" + + NODE_KINDS = { + "top_level" => { + parent: -> { Node.root }, + path_prefix: "", + label: "Top Level" + }, + "generic" => { + label: "Generic", + hint: "Can be created anywhere - choose the parent below." + # no path_prefix - depends on whatever parent gets chosen; see below + }, + "update" => { + parent: -> { Update.find_or_create_parent }, + tags: ["update"], + path_prefix: -> { "updates/#{Time.now.year}" }, + label: "Update", + hint: -> { "Automatically created in /updates/#{Time.now.year}/, gets tag \"update\", and inherits the update template." } + }, + "press_release" => { + parent: -> { Update.find_or_create_parent }, + tags: ["update", "pressemitteilung"], + path_prefix: -> { "updates/#{Time.now.year}" }, + label: "Pressemitteilung", + hint: -> { "Automatically created in /updates/#{Time.now.year}/, gets tags \"update, pressemitteilung\", and inherits the update template." } + }, + "erfa" => { + parent: -> { Node.find_by_unique_name!(ERFA_PARENT_NAME) }, + tags: ["erfa-detail"], + template: "chapter_detail", + path_prefix: ERFA_PARENT_NAME, + label: "Erfa", + hint: "Automatically created under the Erfa-Kreise overview page, gets tag \"erfa-detail\", and uses the chapter detail template." + }, + "chaostreff" => { + parent: -> { Node.find_by_unique_name!(CHAOSTREFF_PARENT_NAME) }, + tags: ["chaostreff-detail"], + template: "chapter_detail", + path_prefix: CHAOSTREFF_PARENT_NAME, + label: "Chaostreff", + hint: "Automatically created under the Chaostreffs overview page, gets tag \"chaostreff-detail\", and uses the chapter detail template." + } + }.freeze +end -- cgit v1.3