From afae88656a6ce075acdaeac67f0572264288bfa3 Mon Sep 17 00:00:00 2001 From: Niko Strijbol Date: Mon, 27 Apr 2020 18:17:57 +0200 Subject: [PATCH] Support predefined locations The service that looks up the locations changes sometimes. Therefore it is useful to have some "predefined" locations, which we can change in one place; the format is "$NAME". Since the metadata is yaml, this exclude the nice "#NAME" or even ":NAME". --- Rules | 1 + lib/helpers/preprocess.rb | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/Rules b/Rules index d825d41..e6fb788 100644 --- a/Rules +++ b/Rules @@ -36,6 +36,7 @@ preprocess do add_report_metadata add_project_metadata + convert_locations end # diff --git a/lib/helpers/preprocess.rb b/lib/helpers/preprocess.rb index 41abf9a..07ff4a9 100644 --- a/lib/helpers/preprocess.rb +++ b/lib/helpers/preprocess.rb @@ -12,6 +12,14 @@ module PreprocessHelper } end + def predefined_locations + { + '$kelder' => 'Zeus WPI, Gent', + '$s9' => 'S9, Gent', + '$therminal' => 'De Therminal, Gent' + } + end + def allowed_privacy_status %w(additional general processor development) end @@ -87,6 +95,16 @@ module PreprocessHelper end end + def convert_locations + @items.find_all('/events/*/*.md').each do |event| + location_link = event[:locationlink]&.downcase&.strip + if location_link&.start_with?('$') && !predefined_locations.key?(location_link) + raise "unknown location variable #{location_link}, must be one of #{predefined_locations.keys}" + end + event[:locationlink] = predefined_locations.fetch(location_link, event[:locationlink]) + end + end + def add_report_metadata @items.find_all('/about/verslagen/*/*').each do |report| report[:academic_year] = report.identifier.to_s.split('/')[-2]