diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-07-06 04:15:46 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-07-06 04:15:46 +0200 |
| commit | 4c47031f9693fc04b01cbb005ad864cd1e3d2425 (patch) | |
| tree | b21e1fa6dd2b3f729962fe9d4e7d8e6c20285a85 | |
| parent | d95947f9d738fd74d1fc16c6a1843b7f46bc0484 (diff) | |
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.
| -rw-r--r-- | app/views/admin/conventions.html.erb | 11 | ||||
| -rw-r--r-- | lib/ccc_conventions.rb | 47 |
2 files changed, 58 insertions, 0 deletions
diff --git a/app/views/admin/conventions.html.erb b/app/views/admin/conventions.html.erb new file mode 100644 index 0000000..72f6214 --- /dev/null +++ b/app/views/admin/conventions.html.erb | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | <h1>Node creation conventions</h1> | ||
| 2 | |||
| 3 | <table id="conventions"> | ||
| 4 | <tr><th>Kind</th><th>What happens</th></tr> | ||
| 5 | <% @node_kinds.each do |kind, config| %> | ||
| 6 | <tr> | ||
| 7 | <td><%= kind %></td> | ||
| 8 | <td><%= resolve_kind_text(config[:label]) %> — <%= resolve_kind_text(config[:hint]) %></td> | ||
| 9 | </tr> | ||
| 10 | <% end %> | ||
| 11 | </table> | ||
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 @@ | |||
| 1 | module CccConventions | ||
| 2 | ERFA_PARENT_NAME = "club/erfas" | ||
| 3 | CHAOSTREFF_PARENT_NAME = "club/chaostreffs" | ||
| 4 | |||
| 5 | NODE_KINDS = { | ||
| 6 | "top_level" => { | ||
| 7 | parent: -> { Node.root }, | ||
| 8 | path_prefix: "", | ||
| 9 | label: "Top Level" | ||
| 10 | }, | ||
| 11 | "generic" => { | ||
| 12 | label: "Generic", | ||
| 13 | hint: "Can be created anywhere - choose the parent below." | ||
| 14 | # no path_prefix - depends on whatever parent gets chosen; see below | ||
| 15 | }, | ||
| 16 | "update" => { | ||
| 17 | parent: -> { Update.find_or_create_parent }, | ||
| 18 | tags: ["update"], | ||
| 19 | path_prefix: -> { "updates/#{Time.now.year}" }, | ||
| 20 | label: "Update", | ||
| 21 | hint: -> { "Automatically created in /updates/#{Time.now.year}/, gets tag \"update\", and inherits the update template." } | ||
| 22 | }, | ||
| 23 | "press_release" => { | ||
| 24 | parent: -> { Update.find_or_create_parent }, | ||
| 25 | tags: ["update", "pressemitteilung"], | ||
| 26 | path_prefix: -> { "updates/#{Time.now.year}" }, | ||
| 27 | label: "Pressemitteilung", | ||
| 28 | hint: -> { "Automatically created in /updates/#{Time.now.year}/, gets tags \"update, pressemitteilung\", and inherits the update template." } | ||
| 29 | }, | ||
| 30 | "erfa" => { | ||
| 31 | parent: -> { Node.find_by_unique_name!(ERFA_PARENT_NAME) }, | ||
| 32 | tags: ["erfa-detail"], | ||
| 33 | template: "chapter_detail", | ||
| 34 | path_prefix: ERFA_PARENT_NAME, | ||
| 35 | label: "Erfa", | ||
| 36 | hint: "Automatically created under the Erfa-Kreise overview page, gets tag \"erfa-detail\", and uses the chapter detail template." | ||
| 37 | }, | ||
| 38 | "chaostreff" => { | ||
| 39 | parent: -> { Node.find_by_unique_name!(CHAOSTREFF_PARENT_NAME) }, | ||
| 40 | tags: ["chaostreff-detail"], | ||
| 41 | template: "chapter_detail", | ||
| 42 | path_prefix: CHAOSTREFF_PARENT_NAME, | ||
| 43 | label: "Chaostreff", | ||
| 44 | hint: "Automatically created under the Chaostreffs overview page, gets tag \"chaostreff-detail\", and uses the chapter detail template." | ||
| 45 | } | ||
| 46 | }.freeze | ||
| 47 | end | ||
