From 83ded97419c54d6d2fd2d9ec13a925a5a3daa9e1 Mon Sep 17 00:00:00 2001 From: Lars Henrik Mai Date: Tue, 21 Oct 2014 22:10:48 +0200 Subject: added basic calendar powered by json data --- data/calendar.json | 5 +++++ helpers/calendar_helpers.rb | 39 +++++++++++++++++++++++++++++++++++++ source/aktuelles/kalender.html.haml | 14 +++++++++++-- 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 data/calendar.json create mode 100644 helpers/calendar_helpers.rb diff --git a/data/calendar.json b/data/calendar.json new file mode 100644 index 0000000..a44245f --- /dev/null +++ b/data/calendar.json @@ -0,0 +1,5 @@ +[ + {"summary":"lounge","start":"2014-10-09 19:00:00 UTC","end":"2014-10-09 21:00:00 UTC"}, + {"summary":"sublab webtreff","start":"2014-10-21 19:00:00 +0200","end":"2014-10-21 20:00:00 +0200"}, + {"summary":"lounge","start":"2014-10-23 19:00:00 UTC","end":"2014-10-23 21:00:00 UTC"} +] diff --git a/helpers/calendar_helpers.rb b/helpers/calendar_helpers.rb new file mode 100644 index 0000000..daa4625 --- /dev/null +++ b/helpers/calendar_helpers.rb @@ -0,0 +1,39 @@ +require 'date' + +module CalendarHelpers + + class Event + + # TODO i18n weekdays, group dates + + FORMATS = { + time_only: "%H:%M", + date_only: "%a. %d.%m" + } + + def initialize(args={}) + @summary = args.fetch("summary") + @start_time = DateTime.parse(args.fetch("start")) + @end_time = DateTime.parse(args.fetch("end")) + end + + def summary + @summary + end + + def start_time + @start_time.strftime(FORMATS[:time_only]) + end + + def end_time + @end_time.strftime(FORMATS[:time_only]) + end + + def date + @start_time.strftime(FORMATS[:date_only]) + end + + end + + +end diff --git a/source/aktuelles/kalender.html.haml b/source/aktuelles/kalender.html.haml index 7876565..437bc52 100644 --- a/source/aktuelles/kalender.html.haml +++ b/source/aktuelles/kalender.html.haml @@ -3,5 +3,15 @@ section: "aktuelles" --- %h2 Termine -%div - = lorem.paragraph +- data.calendar.map {|data| CalendarHelpers::Event.new(data)}.each do |ev| + .row + .large-12.columns + %h4= ev.date + .row + .large-2.large-offset-1.columns + %span= ev.start_time + \- + %span= ev.end_time + .large-9.columns + %span= ev.summary + -- cgit v1.2.1