diff options
author | Lars Henrik Mai <lars.mai@kontinui.de> | 2014-11-18 23:36:26 +0100 |
---|---|---|
committer | Lars Henrik Mai <lars.mai@kontinui.de> | 2014-11-18 23:36:26 +0100 |
commit | 0ec1f76d5e4937569cb92e1aedd6ff27bc5df0b4 (patch) | |
tree | 9e5a70251cf924d77be0c77f0c10dcba17bb3009 | |
parent | 3562a4142ad8a8f8b2b3a1a10538acfbf146d462 (diff) |
week calendar powered by OC json
-rw-r--r-- | data/calendar.json | 6 | ||||
-rw-r--r-- | helpers/calendar_helpers.rb | 22 | ||||
-rw-r--r-- | source/index.html.haml | 8 |
3 files changed, 28 insertions, 8 deletions
diff --git a/data/calendar.json b/data/calendar.json index a44245f..347e97f 100644 --- a/data/calendar.json +++ b/data/calendar.json @@ -1,5 +1 @@ -[ - {"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"} -] +[{"summary":"Website-Treff","start":"2014-11-04 18:30:00 UTC","end":"2014-11-04 22:00:00 UTC"},{"summary":"Website-Treff","start":"2014-11-11 18:30:00 UTC","end":"2014-11-11 22:00:00 UTC"},{"summary":"Website-Treff","start":"2014-11-18 18:30:00 UTC","end":"2014-11-18 22:00:00 UTC"},{"summary":"Hier passiert was","start":"2014-11-21 17:00:00 +0100","end":"2014-11-21 17:30:00 +0100"},{"summary":"Website-Treff","start":"2014-11-25 18:30:00 UTC","end":"2014-11-25 22:00:00 UTC"},{"summary":"magic event","start":"2014-11-26","end":"2014-11-27"},{"summary":"Ein Ding","start":"2014-11-26","end":"2014-11-27"},{"summary":"was anderes","start":"2014-11-28 10:00:00 +0100","end":"2014-11-28 15:00:00 +0100"}]
\ No newline at end of file diff --git a/helpers/calendar_helpers.rb b/helpers/calendar_helpers.rb index ed8ab16..3b915dc 100644 --- a/helpers/calendar_helpers.rb +++ b/helpers/calendar_helpers.rb @@ -37,5 +37,27 @@ module CalendarHelpers end + def week_schedule + events = data.calendar-week.map {|atts| Event.new(atts) } + events.group_by {|ev| ev.date } + end + + def events_on(datetime) + date = datetime.to_date + events = data.calendar.select do |hsh| + ev_date = DateTime.parse(hsh['start']).to_date + ev_date == date + end + events.map {|atts| Event.new(atts)} + end + + def current_week + monday = week_start(Date.parse("2014-11-18")) + (monday..monday + 6).to_a + end + + def week_start(date, offset_from_sunday=1) + date - (date.wday - offset_from_sunday) % 7 + end end diff --git a/source/index.html.haml b/source/index.html.haml index f05a832..abd9728 100644 --- a/source/index.html.haml +++ b/source/index.html.haml @@ -20,13 +20,15 @@ title: sublab - Ein Hackerspace in Leipzig %p CryptoCon14 - 22. bis 25. Mai 2014 .row - - %w(Montag Dienstag Mittwoch Donnerstag Freitag Samstag Sonntag).each_with_index do |dow, i| + - current_week.each_with_index do |date, i| - dow_classes = ["columns", "small-12", "medium-4", "large-1", "dow-columns"] - dow_classes << "end" if i == 6 %div{class: dow_classes} - %h5= dow + %h5= date.strftime("%A") %ul - %li= lorem.words(3) + - events_on(date).each do |ev| + %li + = "%s: %s" % [ev.start_time, ev.summary] .row .columns |