Skip to content

Instantly share code, notes, and snippets.

@sadjow
Created July 31, 2012 22:19
Show Gist options
  • Save sadjow/3221172 to your computer and use it in GitHub Desktop.
Save sadjow/3221172 to your computer and use it in GitHub Desktop.
derby = require 'derby'
{get, view, ready} = derby.createApp module
derby.use(require '../../ui')
FeedParser = require('feedparser')
parser = new FeedParser()
## ROUTES ##
start = +new Date()
# Derby routes can be rendered on the client and the server
get '/:roomName?', (page, model, {roomName}) ->
articles = []
#model.set '_articles', articles
model.set 'length', 0
parser.on 'article', (article) ->
model.incr 'length'
console.log 'pushed!'
parser.parseFile 'http://upanema.blogspot.com/feeds/posts/default?alt=rss'
roomName ||= 'home'
model.set '_heroTitle', 'SEGUEM AS VISITAS AS COMUNIDADES RURAIS'
model.set '_posts', [1, 2, 3, 4 ,5 ,6 ,7 ,8 , 9 ,10]
model.set '_posts2', [1, 2]
# Subscribes the model to any updates on this room's object. Calls back
# with a scoped model equivalent to:
# room = model.at "rooms.#{roomName}"
model.subscribe "rooms.#{roomName}", (err, room) ->
model.ref '_room', room
# setNull will set a value if the object is currently null or undefined
room.setNull 'welcome', "Welcome to #{roomName}!"
room.incr 'visits'
# This value is set for when the page initially renders
model.set '_timer', '0.0'
# Reset the counter when visiting a new route client-side
start = +new Date()
# Render will use the model data as well as an optional context object
page.render
title: 'Upanema Online'
subtitle: 'Notícias, Fotos, Novidades, Guia de Serviços, tudo sobre a cidade de Upanema RN.'
randomUrl: parseInt(Math.random() * 1e9).toString(36)
## CONTROLLER FUNCTIONS ##
ready (model) ->
timer = null
# Functions on the app can be bound to DOM events using the "x-bind"
# attribute in a template.
@stop = ->
# Any path name that starts with an underscore is private to the current
# client. Nothing set under a private path is synced back to the server.
model.set '_stopped', true
clearInterval timer
do @start = ->
model.set '_stopped', false
timer = setInterval ->
model.set '_timer', (((+new Date()) - start) / 1000).toFixed(1)
, 100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment