Skip to content

Commit 4d7355d

Browse files
committed
refactoring
1 parent 159be1e commit 4d7355d

4 files changed

Lines changed: 64 additions & 0 deletions

File tree

cache.coffee

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module.exports = {
2+
for: (expiration, work) ->
3+
lastResult = null
4+
lastModified = null
5+
return (complete) ->
6+
if lastModified? and (new Date).getTime() - expiration < lastModified
7+
complete lastResult
8+
else
9+
work (data) ->
10+
lastResult = data
11+
lastModified = (new Date).getTime()
12+
complete lastResult
13+
}

models/event.coffee

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
date = require 'date-utils'
2+
moment = require 'moment'
3+
4+
Event = (data) ->
5+
this.title = data.summary
6+
this.location = data.location
7+
this.details = data.description
8+
this.when = determineDate(data.start, data.end)
9+
this.url = createEventUrl data.uid
10+
11+
determineDate = (start, end) ->
12+
start = moment(start)
13+
end = moment(end)
14+
date = moment(new Date(start.native())).add('hours', -6).format('ddd, MMM D')
15+
16+
return date if start.diff(end, 'days') == -1
17+
18+
date + start.add('hours', -6).format(' h:mma CST')
19+
20+
createEventUrl = (id) ->
21+
id = id.split('@')[0]
22+
id = new Buffer(id + ' [email protected]').toString('base64').replace('==', '')
23+
24+
module.exports = Event

models/message.coffee

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
moment = require 'moment'
2+
3+
Message = (data) ->
4+
this.subject = data.title.$t
5+
this.body = formatContent data.summary.$t
6+
this.author = data.author.name
7+
this.timeago = moment(new Date(data.updated)).fromNow()
8+
this.url = data.link.href
9+
10+
striphtml = (value) ->
11+
value.replace(/<(?:.|\n)*?>/gm, ' ')
12+
13+
formatContent = (content) ->
14+
content = striphtml(content).trim()
15+
content += '\u2026' if /[\w]$/i.test content
16+
content
17+
18+
module.exports = Message

models/tweet.coffee

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
moment = require 'moment'
2+
3+
Tweet = (data) ->
4+
this.created_by = data.from_user
5+
this.tweet = data.text
6+
this.timeago = moment(new Date(data.created_at)).fromNow()
7+
this.created_at = data.created_at
8+
9+
module.exports = Tweet

0 commit comments

Comments
 (0)