summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Henrik Mai <lars.mai@kontinui.de>2014-10-25 17:33:47 +0200
committerLars Henrik Mai <lars.mai@kontinui.de>2014-10-25 17:33:47 +0200
commita1e8c6fc94297741b1ee00e821b3bf9d4d51e189 (patch)
treea9db9acb39726ed52d2f904dfbc2de56b18655c9
parent90c0d3659850d71119a2825cfedc85f18e9c768f (diff)
use data for tweets and wiki changes
-rw-r--r--data/tweets.json20
-rw-r--r--data/wiki_changes.json18
-rw-r--r--helpers/calendar_helpers.rb14
-rw-r--r--helpers/twitter_helpers.rb27
-rw-r--r--helpers/wiki_helpers.rb29
-rw-r--r--source/_article.html.haml2
-rw-r--r--source/_wiki_changes.html.haml11
-rw-r--r--source/index.html.haml30
8 files changed, 112 insertions, 39 deletions
diff --git a/data/tweets.json b/data/tweets.json
new file mode 100644
index 0000000..f859f7a
--- /dev/null
+++ b/data/tweets.json
@@ -0,0 +1,20 @@
+[
+{
+ "id": 210462857140252672,
+ "created_at": "Wed Oct 23 12:07:10 +0000 2012",
+ "text": "Check out our freshly-launched Surveillance Self-Defense for tips on staying safer online: https://ssd.eff.org",
+ "user": {
+ "name": "Privacy Leipzig",
+ "screen_name": "privacy_leipzig"
+ }
+},
+{
+ "id": 210462857140252672,
+ "created_at": "Wed Jun 06 20:07:10 +0000 2014",
+ "text": "WTF? LOL!",
+ "user": {
+ "name": "sublab // Leipzig",
+ "screen_name": "sublab"
+ }
+}
+]
diff --git a/data/wiki_changes.json b/data/wiki_changes.json
new file mode 100644
index 0000000..a6be3b5
--- /dev/null
+++ b/data/wiki_changes.json
@@ -0,0 +1,18 @@
+[
+{
+ "username": "Woruman",
+ "page": "techniksprechstunde",
+ "datetime": "2014-04-11 21:25:54"
+},
+{
+ "username": "drnerd",
+ "page": "techniksprechstunde",
+ "datetime": "2014-04-10 20:09:44"
+},
+{
+ "username": "jackrandom",
+ "page": "coreboot-x201",
+ "datetime": "2014-04-08 12:52:15",
+ "changelog": "USB Boot patch now obsolete"
+}
+]
diff --git a/helpers/calendar_helpers.rb b/helpers/calendar_helpers.rb
index daa4625..ed8ab16 100644
--- a/helpers/calendar_helpers.rb
+++ b/helpers/calendar_helpers.rb
@@ -2,14 +2,16 @@ require 'date'
module CalendarHelpers
- class Event
+ FORMATS = {
+ time_only: "%H:%M",
+ date_only: "%a. %d.%m",
+ date_string_short: "%e. %b %Y",
+ log: "%Y-%m-%d %H:%M"
+ }
- # TODO i18n weekdays, group dates
+ class Event
- FORMATS = {
- time_only: "%H:%M",
- date_only: "%a. %d.%m"
- }
+ # TODO i18n weekdays, group dates
def initialize(args={})
@summary = args.fetch("summary")
diff --git a/helpers/twitter_helpers.rb b/helpers/twitter_helpers.rb
new file mode 100644
index 0000000..1a3850c
--- /dev/null
+++ b/helpers/twitter_helpers.rb
@@ -0,0 +1,27 @@
+require 'date'
+
+module TwitterHelpers
+
+ class Tweet
+
+ attr_reader :tweet_id, :text, :user_name
+
+ def initialize(atts={})
+ @tweet_id = atts.fetch("id")
+ @created_at = DateTime.parse(atts.fetch("created_at"))
+ @text = atts.fetch("text")
+ @user_name = atts.fetch("user").fetch("name")
+ @user_screen_name = atts.fetch("user").fetch("screen_name")
+ end
+
+ def created_at
+ @created_at.strftime(CalendarHelpers::FORMATS[:date_string_short])
+ end
+
+ def user_screen_name
+ "@#{@user_screen_name}"
+ end
+
+ end
+
+end
diff --git a/helpers/wiki_helpers.rb b/helpers/wiki_helpers.rb
index 95e8268..4984095 100644
--- a/helpers/wiki_helpers.rb
+++ b/helpers/wiki_helpers.rb
@@ -3,21 +3,32 @@ require 'addressable/template'
module WikiHelpers
- RecentChangesItem = Struct.new(:username, :page, :datetime, :changelog)
-
WikiPageUrl = Addressable::Template.new("http://sublab.org/wiki/ikiwiki.cgi{?page}&do=goto")
- def wiki_changes(count=3)
- # mockup for now
+ class WikiChanges
+
+ attr_reader :username, :page, :changelog
+
+ def initialize(atts={})
+ @username = atts.fetch("username")
+ @page = atts.fetch("page")
+ @datetime = DateTime.parse(atts.fetch("datetime"))
+ @changelog = atts.fetch("changelog", nil)
+ end
- [
- RecentChangesItem.new("Woruman", "techniksprechstunde", DateTime.parse("2014-04-11 21:25:54")),
- RecentChangesItem.new("drnerd", "techniksprechstunde", DateTime.parse("2014-04-10 20:09:44")),
- RecentChangesItem.new("jackrandom", "coreboot-x201", DateTime.parse("2014-04-08 12:52:15"), "USB Boot patch now obsolete")
- ]
+ def datetime
+ @datetime.strftime(CalendarHelpers::FORMATS[:log])
+ end
+
+ end
+ def wiki_changes
+ data.wiki_changes.map do |atts|
+ WikiChanges.new(atts)
+ end
end
+ # TODO move to link helper module
def link_to_wiki(name)
url = WikiPageUrl.expand({page: name}).to_s
link_to escape_html(name), url
diff --git a/source/_article.html.haml b/source/_article.html.haml
index a276a81..fde602e 100644
--- a/source/_article.html.haml
+++ b/source/_article.html.haml
@@ -1,7 +1,7 @@
.row
.column
%article
- %aside.blog-date= article.date.strftime('%e %b %Y')
+ %aside.blog-date= article.date.strftime(CalendarHelpers::FORMATS[:date_string_short])
.blog-inner
%h3.blog-article-heading= link_to article.title, article
= article.body
diff --git a/source/_wiki_changes.html.haml b/source/_wiki_changes.html.haml
deleted file mode 100644
index e1e8d6e..0000000
--- a/source/_wiki_changes.html.haml
+++ /dev/null
@@ -1,11 +0,0 @@
-%ul
- - wiki_changes.each do |item|
- %li
- = item.datetime.strftime("%Y-%m-%d %H:%M")
- |
- \#{link_to_wiki(item.page)}
- changed by
- \#{link_to_wiki(item.username)}
- - if item.changelog
- |
- \#{item.changelog}
diff --git a/source/index.html.haml b/source/index.html.haml
index 0bba68b..947653e 100644
--- a/source/index.html.haml
+++ b/source/index.html.haml
@@ -37,18 +37,24 @@ title: sublab - Ein Hackerspace in Leipzig
.row
.columns
%h3 @sublab tweets
- %p
- %strong sublab
- @sublab Apr 5
- %br/
- WTF? LOL!
- %p
- %strong about:radio
- @aboutradio Apr 5
- %br/
- Heute von 16-18Uhr: about:radio u.a. zu den Themen: Libre Graphics Meeting in Leipzig, Kamera in der Simildenstrasse
-
+ - data.tweets.map {|atts| Tweet.new(atts) }.each do |tweet|
+ %p
+ %strong= tweet.user_name
+ = tweet.user_screen_name
+ = tweet.created_at
+ %br
+ = tweet.text
.row
.columns
%h3 Wiki Aktivität
- = partial "wiki_changes"
+ %ul
+ - wiki_changes.each do |item|
+ %li
+ = item.datetime
+ |
+ = link_to_wiki(item.page)
+ changed by
+ = link_to_wiki(item.username)
+ - if item.changelog
+ |
+ = item.changelog