events a bit more

This commit is contained in:
Lorin Werthen 2016-08-24 01:01:17 +02:00
parent bc5da5b81e
commit ec990ac755
No known key found for this signature in database
GPG key ID: F11FFC921E0E08E0
6 changed files with 54 additions and 14 deletions

View file

@ -1,7 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
source 'https://rubygems.org' source 'https://rubygems.org'
gem 'nanoc', '~>4.2' gem 'nanoc', '~>4.3.1'
gem 'kramdown' gem 'kramdown'
gem 'coffee-script' gem 'coffee-script'
# Needed for relativize_urls # Needed for relativize_urls

View file

@ -3,7 +3,7 @@ GEM
specs: specs:
adsf (1.2.1) adsf (1.2.1)
rack (>= 1.0.0) rack (>= 1.0.0)
autoprefixer-rails (6.4.0.2) autoprefixer-rails (6.4.0.3)
execjs execjs
builder (3.2.2) builder (3.2.2)
coderay (1.1.1) coderay (1.1.1)
@ -45,7 +45,7 @@ GEM
lumberjack (1.0.10) lumberjack (1.0.10)
method_source (0.8.2) method_source (0.8.2)
mini_portile2 (2.1.0) mini_portile2 (2.1.0)
nanoc (4.3.0) nanoc (4.3.2)
cri (~> 2.3) cri (~> 2.3)
hamster (~> 3.0) hamster (~> 3.0)
ref (~> 2.0) ref (~> 2.0)
@ -87,7 +87,7 @@ DEPENDENCIES
highline highline
icalendar icalendar
kramdown kramdown
nanoc (~> 4.2) nanoc (~> 4.3.1)
nokogiri nokogiri
sass sass
w3c_validators w3c_validators

25
content/events.erb Normal file
View file

@ -0,0 +1,25 @@
---
navigable: true
title: Events
---
<div>
<div class="content">
<h1>Upcoming events</h1>
</div>
<% all_events.each do |event| %>
<div class="box">
<a href="<%= relative_path_to(event) %>">
<%= event[:title] %>
</a>
<% sub_events(event).each do |sub_event| %>
[
<a href="<%= relative_path_to(sub_event) %>">
<%= sub_event[:title] %>
</a>
]
<% end %>
</div>
<% end %>
</div>

View file

@ -1,11 +1,5 @@
# This doesn't use the new define syntax yet because item Nanoc::Filter.define(:ical) do |_content, _params|
# is not available there cal = Icalendar::Calendar.new
class IcalFilter < Nanoc::Filter cal.add_event(event_for(item))
identifier :ical cal.to_ical
def run(_content, _params = {})
cal = Icalendar::Calendar.new
cal.add_event(event_for(item))
cal.to_ical
end
end end

20
lib/helpers/events.rb Normal file
View file

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

View file

@ -6,6 +6,7 @@ include Nanoc::Helpers::Text
include ArchiveHelper include ArchiveHelper
include AssetHelper include AssetHelper
include EventsHelper
include IcalHelper include IcalHelper
include NavigationHelper include NavigationHelper
include DataHelper include DataHelper