Skip to content

Commit 49a1b6c

Browse files
committed
some improvements
1 parent 1329e13 commit 49a1b6c

6 files changed

Lines changed: 162 additions & 67 deletions

File tree

data.coffee

Lines changed: 72 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,76 @@
1-
parser = require './utility/atomParser.js'
1+
parser = require 'xml2json'
22
rest = require 'restler'
3+
date = require 'date-utils'
4+
_date = require 'underscore.date'
5+
6+
parseFeed = (feed) ->
7+
JSON.parse(parser.toJson(feed)).feed.entry
8+
9+
messageFeed = 'http://groups.google.com/group/kc-nodejs/feed/atom_v1_0_topics.xml'
10+
eventFeed = 'http://www.google.com/calendar/feeds/nodekc.org_e8lg6hesldeld1utui23ebpg7k%40group.calendar.google.com/public/basic'
11+
twitterFeed = 'http://search.twitter.com/search.json?q=%40nodekc'
12+
13+
lastMessageFetchResult = {}
14+
lastEventFetchResult = {}
15+
lastTwitterFetchResult = {}
16+
17+
striphtml = (value) ->
18+
value.replace(/<(?:.|\n)*?>/gm, ' ')
19+
20+
timeAgo = (date) ->
21+
_date(new Date(date)).fromNow()
22+
23+
formatContent = (content) ->
24+
content = striphtml(content).trim()
25+
content += '\u2026' if /[\w]$/i.test content
26+
content
327

428
fetchMessages = (cb) ->
5-
rest.get('http://groups.google.com/group/kc-nodejs/feed/atom_v1_0_topics.xml').on('complete', (data) -> cb(parser(data).items))
29+
if lastMessageFetchResult.on? and lastMessageFetchResult.on > (new Date).addMinutes(-1)
30+
cb lastMessageFetchResult.value
31+
return
32+
33+
rest.get(messageFeed).on('complete', (data) ->
34+
35+
messages = for x in parseFeed data
36+
{ subject: x.title.$t, body: formatContent(x.summary.$t), author: x.author.name, timeago: timeAgo(x.updated), url: x.link.href }
37+
38+
lastMessageFetchResult.value = messages
39+
lastMessageFetchResult.on = new Date
40+
41+
cb messages
42+
43+
)
644

745
fetchTweets = (cb) ->
8-
rest.get('http://search.twitter.com/search.json?q=%40nodekc').on('complete', (data) -> cb(data))
46+
if lastTwitterFetchResult.on? and lastTwitterFetchResult.on > (new Date).addMinutes(-1)
47+
cb lastTwitterFetchResult.value
48+
return
49+
50+
rest.get(twitterFeed).on('complete', (data) ->
51+
tweets = for x in data.results
52+
{ timeago: timeAgo(x.created_at), created_at: x.created_at, created_by: x.from_user, tweet: x.text }
53+
54+
lastTwitterFetchResult.value = tweets
55+
lastTwitterFetchResult.on = new Date
56+
57+
cb tweets
58+
)
959

1060
fetchEvents = (cb) ->
11-
rest.get('http://www.google.com/calendar/feeds/nodekc.org_e8lg6hesldeld1utui23ebpg7k%40group.calendar.google.com/public/basic').on('complete', (data) -> cb(parser(data).items))
61+
if lastEventFetchResult.on? and lastEventFetchResult.on > (new Date).addMinutes(-1)
62+
cb lastEventFetchResult.value
63+
return
64+
65+
rest.get(eventFeed).on('complete', (data) ->
66+
events = for x in parseFeed data
67+
{ title: x.title.$t, when: striphtml(x.summary.$t), url: x.id }
68+
69+
lastEventFetchResult.value = events
70+
lastEventFetchResult.on = new Date
71+
72+
cb events
73+
)
1274

1375
module.exports = {
1476
load: (keys...) ->
@@ -21,15 +83,15 @@ module.exports = {
2183
next() if finished.length == keys.length
2284

2385
messages: (data, cb) ->
24-
fetchMessages (items) ->
25-
data.messages = items
86+
fetchMessages (messages) ->
87+
data.messages = messages
2688
cb 'messages'
2789
tweets: (data, cb) ->
28-
fetchTweets (result) ->
29-
data.tweets = result
90+
fetchTweets (tweets) ->
91+
data.tweets = tweets
3092
cb 'tweets'
3193
events: (data, cb) ->
32-
fetchEvents (result) ->
33-
data.events = result
94+
fetchEvents (events) ->
95+
data.events = events
3496
cb 'events'
3597
}

data/messages.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<feed xmlns="http://www.w3.org/2005/Atom">
2+
<id>http://groups.google.com/group/kc-nodejs</id>
3+
<title type="text">KC Node.js and more Google Group</title>
4+
<subtitle type="text">
5+
we&#39;ll discuss node.js and related technologies on a regular schedule. The format of the group meetings is still up for discussion. All are welcome who have interest in node.js and other web technologies.
6+
</subtitle>
7+
<link href="/group/kc-nodejs/feed/atom_v1_0_topics.xml" rel="self" title="KC Node.js and more feed"/>
8+
<updated>-0-0T::Z</updated>
9+
<generator uri="http://groups.google.com" version="1.99">Google Groups</generator>
10+
<entry>
11+
<author>
12+
<name>Joseph Andaverde</name>
13+
<email>[email protected]</email>
14+
</author>
15+
<updated>2012-01-23T03:55:03Z</updated>
16+
<id>http://groups.google.com/group/kc-nodejs/browse_thread/thread/660381282d1f32fd</id>
17+
<link href="http://groups.google.com/group/kc-nodejs/browse_thread/thread/660381282d1f32fd" />
18+
<title type="html">Best practice for concurrent loading</title>
19+
<summary type="html" xml:space="preserve">
20+
I&#39;m curious if there are any established patterns for executing &lt;br&gt; multiple requests asynchronously before responding with a view.
21+
</summary>
22+
</entry>
23+
<entry>
24+
<author>
25+
<name>Joseph Andaverde</name>
26+
<email>[email protected]</email>
27+
</author>
28+
<updated>2012-01-22T18:05:35Z</updated>

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
"jade": "~v0.20.0",
88
"stylus": "~v0.22.5",
99
"easysax": "latest",
10-
"restler": "latest"
10+
"restler": "latest",
11+
"underscore.date": "latest",
12+
"date-utils": "latest"
1113
}
1214
}
1315

public/css/app.css

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ a {
1717
font-weight: bold;
1818
color: #d2d8ba;
1919
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
20-
font-size: 2em;
2120
text-align: center;
2221
}
2322
#wrapper h1 {
@@ -28,10 +27,6 @@ a {
2827
background: url("images/nodekc-dark.png") no-repeat center center;
2928
text-indent: -90000px;
3029
}
31-
#wrapper p {
32-
font-size: 0.8em;
33-
padding-top: 1em;
34-
}
3530
#panels {
3631
list-style-type: none;
3732
}
@@ -43,33 +38,37 @@ a {
4338
padding: 10px;
4439
margin-top: 15px;
4540
margin-left: 10px;
46-
height: 160px;
41+
height: 230px;
4742
overflow: auto;
4843
}
44+
#panels li.panel .title {
45+
font-size: 14px;
46+
}
4947
#panels li.panel ul {
5048
padding: 0;
5149
margin-left: 10px;
5250
list-style-type: none;
5351
}
5452
#panels li.panel h2 {
55-
font-size: 0.6em;
53+
font-size: 20px;
54+
clear: both;
55+
margin-bottom: 10px;
5656
}
5757
#panels li.panel a.message {
5858
font-size: 0.5em;
5959
}
60-
#panels li.panel p.teaser {
61-
font-size: 0.5em;
62-
margin: 0;
63-
text-indent: 0.4em;
64-
padding: 0;
60+
#panels li.panel .time {
61+
font-size: 11px;
62+
color: #888;
6563
}
66-
#panels li.panel.tweets p.tweet {
67-
font-size: 1em;
64+
#panels li.panel .teaser {
65+
font-size: 12px;
6866
}
69-
#panels li.panel.tweets span {
70-
font-size: 0.5em;
71-
color: #ccc;
72-
margin-bottom: 5px;
73-
margin-left: 3px;
74-
text-decoration: underline;
67+
.tweets .avatar {
68+
float: left;
69+
margin-right: 10px;
70+
}
71+
p.join {
72+
clear: both;
73+
margin-top: 10px;
7574
}

public/css/app.styl

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ a
1616
font-weight bold
1717
color #D2D8BA
1818
font-family 'Helvetica Neue', Helvetica, Arial, sans-serif
19-
font-size 2em
2019
text-align center
2120

2221
h1
@@ -27,9 +26,6 @@ a
2726
background url('images/nodekc-dark.png') no-repeat center center
2827
text-indent -90000px
2928

30-
p
31-
font-size .8em
32-
padding-top 1em
3329
#panels
3430
list-style-type none
3531
li.panel
@@ -40,28 +36,30 @@ a
4036
padding 10px
4137
margin-top 15px
4238
margin-left 10px
43-
height 160px
39+
height 230px
4440
overflow auto
41+
42+
.title
43+
font-size 14px
4544
ul
4645
padding 0
4746
margin-left 10px
4847
list-style-type none
4948
h2
50-
font-size .6em
49+
font-size 20px
50+
clear both
51+
margin-bottom 10px
5152
a.message
5253
font-size .5em
53-
p.teaser
54-
font-size .5em
55-
margin 0
56-
text-indent .4em
57-
padding 0
58-
li.panel.tweets
59-
p.tweet
60-
font-size 1em
61-
span
62-
font-size .5em
63-
color #ccc
64-
margin-bottom 5px
65-
margin-left 3px
66-
text-decoration underline
54+
.time
55+
font-size 11px
56+
color #888
57+
.teaser
58+
font-size 12px
59+
.tweets .avatar
60+
float left
61+
margin-right 10px
62+
p.join
63+
clear both
64+
margin-top 10px
6765

views/layout.jade

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
!!! 5
22
html(lang="en")
33
title NodeKC - Kansas City's Node.js user group
4+
script(src='http://livejs.com/live.js')
45

56
script
67
var _gaq = _gaq || [];
@@ -20,28 +21,33 @@ html(lang="en")
2021
h1 NodeKC
2122

2223
ul#panels
23-
li.panel
24+
li.panel.messages
2425
h2 Recent Group Messages
2526
ul
2627
each item in messages
2728
li
28-
a.message(href=item.guid)#{item.title}
29-
p.teaser #{item.desc}
29+
a.title(href=item.url)#{item.subject}
30+
p.teaser= item.body
31+
span.time #{item.timeago}
3032
li.panel.tweets
3133
h2 Tweets
32-
a(href='http://twitter.com/nodekc') @nodekc
34+
a.title(href='http://twitter.com/nodekc')@nodekc
3335

34-
ul
35-
each item in tweets.results
36-
li
37-
p.tweet #{item.text}
38-
span #{item.created_at}
39-
li.panel
36+
ul
37+
each item in tweets
38+
li
39+
a.title(href='http://twitter.com/' + item.created_by) #{item.created_by}
40+
a.avatar(href='http://twitter.com/' + item.created_by, target='_blank')
41+
img(src='http://api.twitter.com/1/users/profile_image/' + item.created_by + '.png', title=item.created_by, target='_blank')
42+
p.teaser #{item.tweet}
43+
span.time #{item.timeago}
44+
li.panel.events
4045
h2 Events
41-
ul
42-
each item in events
43-
li
44-
a(href=item.guid)#{item.title}
45-
p.teaser #{item.desc}
46-
p join our
46+
ul
47+
each item in events
48+
li
49+
a.title(href=item.url)#{item.title}
50+
p.time.teaser
51+
!= item.when
52+
p.join join our
4753
a(href='http://groups.google.com/group/kc-nodejs') google group

0 commit comments

Comments
 (0)