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".
This commit is contained in:
Niko Strijbol 2020-04-27 18:17:57 +02:00
parent 918cc9b08b
commit afae88656a
No known key found for this signature in database
GPG key ID: 1A8AEBABD9012251
2 changed files with 19 additions and 0 deletions

1
Rules
View file

@ -36,6 +36,7 @@ preprocess do
add_report_metadata
add_project_metadata
convert_locations
end
#

View file

@ -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]