2017-06-07 10:23:02 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-09-13 18:12:52 +02:00
|
|
|
require 'uri'
|
2017-06-07 10:23:02 +02:00
|
|
|
|
2016-08-24 01:01:17 +02:00
|
|
|
module EventsHelper
|
2017-06-07 10:23:02 +02:00
|
|
|
def all_events(year = nil)
|
|
|
|
items_ = if year
|
|
|
|
@items.find_all("/events/#{year}/*.md")
|
|
|
|
else
|
|
|
|
@items.find_all('/events/*/*.md')
|
|
|
|
end
|
|
|
|
|
|
|
|
items_.sort_by { |x| x[:time] }
|
2016-10-03 15:15:48 +02:00
|
|
|
end
|
|
|
|
|
2017-06-07 10:23:02 +02:00
|
|
|
def upcoming_events(year = nil)
|
|
|
|
all_events(year).reject { |x| x[:time] <= Date.today }
|
2016-10-03 15:15:48 +02:00
|
|
|
end
|
|
|
|
|
2017-06-07 10:23:02 +02:00
|
|
|
def past_events(year = nil)
|
|
|
|
all_events(year).reject { |x| x[:time] > Date.today }.reverse
|
2016-08-24 01:01:17 +02:00
|
|
|
end
|
|
|
|
|
2017-06-07 10:23:02 +02:00
|
|
|
def academic_years_event_items
|
|
|
|
items.find_all('/events/*').map { |e| [e[:academic_year], e] }.reverse
|
|
|
|
end
|
|
|
|
|
2016-08-24 01:01:17 +02:00
|
|
|
def grouped_events
|
|
|
|
@items.find_all('/events/*/*/main.md')
|
|
|
|
end
|
|
|
|
|
|
|
|
def sub_events(grouped_event)
|
|
|
|
if grouped_event.identifier =~ /main.md/
|
|
|
|
query = grouped_event.identifier.to_s.split('/')[0..-2].join('/') + '/*'
|
|
|
|
@items.find_all(query).reject do |i|
|
|
|
|
i.identifier =~ /main.md/
|
|
|
|
end
|
|
|
|
else
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
end
|
2016-09-13 18:12:52 +02:00
|
|
|
|
|
|
|
def locationlink(location)
|
|
|
|
"https://www.google.com/maps/embed/v1/place?key=AIzaSyBDTmw7LtDG28o9QjCnNucAJv2zTZpLjJU&q=#{URI.escape(location)}" if location
|
|
|
|
end
|
2016-08-24 01:01:17 +02:00
|
|
|
end
|