From ec990ac7557d061b2bafa3a7e6bc0850ddca7d88 Mon Sep 17 00:00:00 2001 From: Lorin Werthen Date: Wed, 24 Aug 2016 01:01:17 +0200 Subject: [PATCH] events a bit more --- Gemfile | 2 +- Gemfile.lock | 6 +++--- content/events.erb | 25 +++++++++++++++++++++++++ lib/filters/ical_filter.rb | 14 ++++---------- lib/helpers/events.rb | 20 ++++++++++++++++++++ lib/helpers_.rb | 1 + 6 files changed, 54 insertions(+), 14 deletions(-) create mode 100644 content/events.erb create mode 100644 lib/helpers/events.rb diff --git a/Gemfile b/Gemfile index 7cd991a..ee3c8a5 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ # frozen_string_literal: true source 'https://rubygems.org' -gem 'nanoc', '~>4.2' +gem 'nanoc', '~>4.3.1' gem 'kramdown' gem 'coffee-script' # Needed for relativize_urls diff --git a/Gemfile.lock b/Gemfile.lock index 860035a..4dabb4d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -3,7 +3,7 @@ GEM specs: adsf (1.2.1) rack (>= 1.0.0) - autoprefixer-rails (6.4.0.2) + autoprefixer-rails (6.4.0.3) execjs builder (3.2.2) coderay (1.1.1) @@ -45,7 +45,7 @@ GEM lumberjack (1.0.10) method_source (0.8.2) mini_portile2 (2.1.0) - nanoc (4.3.0) + nanoc (4.3.2) cri (~> 2.3) hamster (~> 3.0) ref (~> 2.0) @@ -87,7 +87,7 @@ DEPENDENCIES highline icalendar kramdown - nanoc (~> 4.2) + nanoc (~> 4.3.1) nokogiri sass w3c_validators diff --git a/content/events.erb b/content/events.erb new file mode 100644 index 0000000..750f770 --- /dev/null +++ b/content/events.erb @@ -0,0 +1,25 @@ +--- +navigable: true +title: Events +--- + +
+
+

Upcoming events

+
+ + <% all_events.each do |event| %> +
+ + <%= event[:title] %> + + <% sub_events(event).each do |sub_event| %> + [ + + <%= sub_event[:title] %> + + ] + <% end %> +
+ <% end %> +
diff --git a/lib/filters/ical_filter.rb b/lib/filters/ical_filter.rb index 608b90c..d416118 100644 --- a/lib/filters/ical_filter.rb +++ b/lib/filters/ical_filter.rb @@ -1,11 +1,5 @@ -# This doesn't use the new define syntax yet because item -# is not available there -class IcalFilter < Nanoc::Filter - identifier :ical - - def run(_content, _params = {}) - cal = Icalendar::Calendar.new - cal.add_event(event_for(item)) - cal.to_ical - end +Nanoc::Filter.define(:ical) do |_content, _params| + cal = Icalendar::Calendar.new + cal.add_event(event_for(item)) + cal.to_ical end diff --git a/lib/helpers/events.rb b/lib/helpers/events.rb new file mode 100644 index 0000000..181806c --- /dev/null +++ b/lib/helpers/events.rb @@ -0,0 +1,20 @@ +module EventsHelper + def all_events + @items.find_all('/events/*/*') + grouped_events + end + + 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 +end diff --git a/lib/helpers_.rb b/lib/helpers_.rb index a09791f..3880fe5 100644 --- a/lib/helpers_.rb +++ b/lib/helpers_.rb @@ -6,6 +6,7 @@ include Nanoc::Helpers::Text include ArchiveHelper include AssetHelper +include EventsHelper include IcalHelper include NavigationHelper include DataHelper