diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-07-07 03:48:09 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-07-07 03:48:09 +0200 |
| commit | 1bf719d6ac58187cf406d92a40b665d3fa6e658b (patch) | |
| tree | 214c0095fe06dd204e31285fbd16df4e07821d80 /lib/ccc_conventions.rb | |
| parent | 7b6af89509e8439fe2474e623ee97e4db67ab011 (diff) | |
Add context-aware child-creation shortcuts to nodes#show
parent_match Procs on CccConventions::NODE_KINDS, matched against
unique_path, decide which "add child" kinds show on a given node. Fixes
nodes#new not honoring a pre-selected kind (radio group and parent-field
visibility both defaulted to "generic" unconditionally).
Diffstat (limited to 'lib/ccc_conventions.rb')
| -rw-r--r-- | lib/ccc_conventions.rb | 61 |
1 files changed, 33 insertions, 28 deletions
diff --git a/lib/ccc_conventions.rb b/lib/ccc_conventions.rb index c0f9943..b420452 100644 --- a/lib/ccc_conventions.rb +++ b/lib/ccc_conventions.rb | |||
| @@ -4,44 +4,49 @@ module CccConventions | |||
| 4 | 4 | ||
| 5 | NODE_KINDS = { | 5 | NODE_KINDS = { |
| 6 | "top_level" => { | 6 | "top_level" => { |
| 7 | parent: -> { Node.root }, | 7 | parent: -> { Node.root }, |
| 8 | path_prefix: "", | 8 | parent_match: ->(path) { path == [] }, |
| 9 | label: "Top Level" | 9 | path_prefix: "", |
| 10 | label: "Top Level" | ||
| 10 | }, | 11 | }, |
| 11 | "generic" => { | 12 | "generic" => { |
| 12 | label: "Generic", | 13 | parent_match: ->(path) { true }, |
| 13 | hint: "Can be created anywhere - choose the parent below." | 14 | label: "Generic", |
| 14 | # no path_prefix - depends on whatever parent gets chosen; see below | 15 | hint: "Can be created anywhere - choose the parent below." |
| 15 | }, | 16 | }, |
| 16 | "update" => { | 17 | "update" => { |
| 17 | parent: -> { Update.find_or_create_parent }, | 18 | parent: -> { Update.find_or_create_parent }, |
| 18 | tags: ["update"], | 19 | parent_match: ->(path) { path[0] == "updates" && (path.length == 1 || path[1] =~ /\A\d{4}\z/) }, |
| 19 | path_prefix: -> { "updates/#{Time.now.year}" }, | 20 | tags: ["update"], |
| 20 | label: "Update", | 21 | path_prefix: -> { "updates/#{Time.now.year}" }, |
| 21 | hint: -> { "Automatically created in /updates/#{Time.now.year}/, gets tag \"update\", and inherits the update template." } | 22 | label: "Update", |
| 23 | hint: -> { "Automatically created in /updates/#{Time.now.year}/, gets tag \"update\", and inherits the update template." } | ||
| 22 | }, | 24 | }, |
| 23 | "press_release" => { | 25 | "press_release" => { |
| 24 | parent: -> { Update.find_or_create_parent }, | 26 | parent: -> { Update.find_or_create_parent }, |
| 25 | tags: ["update", "pressemitteilung"], | 27 | parent_match: ->(path) { path[0] == "updates" && (path.length == 1 || path[1] =~ /\A\d{4}\z/) }, |
| 26 | path_prefix: -> { "updates/#{Time.now.year}" }, | 28 | tags: ["update", "pressemitteilung"], |
| 27 | label: "Pressemitteilung", | 29 | path_prefix: -> { "updates/#{Time.now.year}" }, |
| 28 | hint: -> { "Automatically created in /updates/#{Time.now.year}/, gets tags \"update, pressemitteilung\", and inherits the update template." } | 30 | label: "Pressemitteilung", |
| 31 | hint: -> { "Automatically created in /updates/#{Time.now.year}/, gets tags \"update, pressemitteilung\", and inherits the update template." } | ||
| 29 | }, | 32 | }, |
| 30 | "erfa" => { | 33 | "erfa" => { |
| 31 | parent: -> { Node.find_by_unique_name!(ERFA_PARENT_NAME) }, | 34 | parent: -> { Node.find_by_unique_name!(ERFA_PARENT_NAME) }, |
| 32 | tags: ["erfa-detail"], | 35 | parent_match: ->(path) { path == ["club", "erfas"] }, |
| 33 | template: "chapter_detail", | 36 | tags: ["erfa-detail"], |
| 34 | path_prefix: ERFA_PARENT_NAME, | 37 | template: "chapter_detail", |
| 35 | label: "Erfa", | 38 | path_prefix: ERFA_PARENT_NAME, |
| 36 | hint: "Automatically created under the Erfa-Kreise overview page, gets tag \"erfa-detail\", and uses the chapter detail template." | 39 | label: "Erfa", |
| 40 | hint: "Automatically created under the Erfa-Kreise overview page, gets tag \"erfa-detail\", and uses the chapter detail template." | ||
| 37 | }, | 41 | }, |
| 38 | "chaostreff" => { | 42 | "chaostreff" => { |
| 39 | parent: -> { Node.find_by_unique_name!(CHAOSTREFF_PARENT_NAME) }, | 43 | parent: -> { Node.find_by_unique_name!(CHAOSTREFF_PARENT_NAME) }, |
| 40 | tags: ["chaostreff-detail"], | 44 | parent_match: ->(path) { path == ["club", "chaostreffs"] }, |
| 41 | template: "chapter_detail", | 45 | tags: ["chaostreff-detail"], |
| 42 | path_prefix: CHAOSTREFF_PARENT_NAME, | 46 | template: "chapter_detail", |
| 43 | label: "Chaostreff", | 47 | path_prefix: CHAOSTREFF_PARENT_NAME, |
| 44 | hint: "Automatically created under the Chaostreffs overview page, gets tag \"chaostreff-detail\", and uses the chapter detail template." | 48 | label: "Chaostreff", |
| 49 | hint: "Automatically created under the Chaostreffs overview page, gets tag \"chaostreff-detail\", and uses the chapter detail template." | ||
| 45 | } | 50 | } |
| 46 | }.freeze | 51 | }.freeze |
| 47 | end | 52 | end |
