Permalink
Browse files

R0.0.2 - refactor + examples

  • Loading branch information...
Edward de Groot
Edward de Groot committed Jul 13, 2011
1 parent 832ca9a commit a78f9441390d939d906b0c359a325bef431c7eb9
View
@@ -1,3 +1,4 @@
.DS_Store
node_modules/
-lib/*.js
+lib/*.js
+*.log
View
@@ -1,4 +1,13 @@
0.0.1 / 2011-07-05
==================
- * Initial release
+ * Initial release
+
+0.0.2 / 2011-07-13
+==================
+
+ * Created sample timbits of varying complexity
+ * Major refactoring as we develop our examples
+ * Reworked areas towards convention over configuration
+ * Uses the CoffeeKup view engine by default
+ * Created Story timbit to be used as a real world prototype
View
@@ -1,3 +1,5 @@
+(The MIT License)
+
Copyright (c) 2011 Postmedia Network Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
View
@@ -1,5 +1,30 @@
-# Timbit
-Widget framework based on Zappa
+# Timbits
+Widget framework based on Express and CoffeeScript
+
+## Introduction
+
+Timbits is an attempt to build an easy and reusable widget framework on top of Express. These widgets are meant to render independent HTML snippets based on REST based JSON/XML data sources and brought together on a page via ESI (Edge Side Includes)
+
+It's primarily meant to serve internal purposes as Postmedia Network Inc, however it is being open sourced under the MIT License. Others may find some use for what we are doing, and still others may be able to help turn this into a more generic and useful solution by contributing and/or correcting our ignorant ways.
+
+Be kind. We're coming from years of .NET experience and some Ruby on Rails. This is our first foray into Node.js development and we're still figuring things out. Constructive criticism is encouraged. If you see something odd and think to yourself "WTF?" then by all means, let us know.
+
+## Usage
+
+Yea, we're not even close to having useful documentation yet. Stay tuned.
+
+## Outstanding Issues
+
+Way too much at this time. On the short list (and mostly in progress):
+
+* Integrated testing framework
+* Integrated benchmarks
+* Command line server with ability to automatically restart
+* Documentation
+* Refactor and expand data retrieval, including caching, conditional GETs, XML support
+* Support for alternate server configurations
+* More examples
+* Deployment and monitoring process
## Created by
View
@@ -1,19 +1,5 @@
-
# Module dependencies.
-
timbits = require '../src/timbits'
-app = timbits.createServer();
-
-# Routes
-
-app.get '/', (req, res) ->
-
- res.render 'index', {
- title: "Third Timbit"
- }
-
-chocolate = new timbits.Timbit('Chocolate')
-timbits.addFlavour app, chocolate
-timbits.app.listen 3000
-console.log "Express server listening on port %d in %s mode", app.address().port, app.settings.env
+# start serving timbits
+timbits.serve()
View
@@ -1,11 +0,0 @@
-
-exports.echo = (msg) ->
- msg
-
-class test
- sayHello: (name) ->
- "Hello #{name}"
-
-
-
-exports.testClass = test
View
@@ -1,10 +0,0 @@
-
-console.log 'starting...'
-
-hello = require ('./hello')
-console.log hello.echo('is anyone there?')
-
-t = new hello.testClass()
-console.log t.sayHello('Bob')
-
-console.log '... and done'
@@ -0,0 +1,14 @@
+# Cherry Timbit
+# Example of a timbit which actually does something.
+# This timbit will display the current server time
+
+# load the timbits module
+timbits = require '../../src/timbits'
+
+# create and export the timbit
+timbit = module.exports = new timbits.Timbit()
+
+# additional timbit implementation code follows...
+timbit.eat = (context) ->
+ context.now = new Date()
+ @render context
@@ -0,0 +1,27 @@
+# Chocolate Timbit
+# Example of a timbit which transforms remote data
+# This timbit will query twitter and display the results
+# There are two views available, the default and the alternate
+# /chocolate?q=timbits
+# /chocolate/alternate?q=timbits
+
+# load the timbits module
+timbits = require '../../src/timbits'
+
+# create and export the timbit
+timbit = module.exports = new timbits.Timbit()
+
+# additional timbit implementation code follows...
+timbit.eat = (context) ->
+
+ context.q = context.request.query.q || 'timbits'
+
+ # specify the data source
+ src = {
+ host: 'search.twitter.com'
+ path: "/search.json?q=#{context.q}"
+ }
+
+ # use the helper method to @fetch the data
+ # @fetch will call @render once we have the data
+ @fetch context, 'tweets', src
@@ -0,0 +1,32 @@
+# Dutchie Timbit
+# Similar (in function, not taste) to the chocolate timbit
+# This timbit displays some more advanced features such as:
+# - specify a custom route
+# - overiding the render implementation with custom code
+# - um, that's it for now. more to come...
+# e.g. /dutchie/postmedia/alternate
+
+# load the timbits module
+timbits = require '../../src/timbits'
+
+# create and export the timbit
+timbit = module.exports = new timbits.Timbit()
+
+# additional timbit implementation code follows...
+timbit.route = "/dutchie/:q?/:view?"
+
+timbit.eat = (context) ->
+
+ context.q = context.request.params.q || 'timbits'
+
+ # specify the data source
+ src = {
+ host: 'search.twitter.com'
+ path: "/search.json?q=#{context.q}"
+ }
+
+ # use the helper method to @fetch the data
+ # @fetch will call @render once we have the data
+ @fetch context, 'tweets', src, (context) ->
+ # let's just re-use the chocolate timbit views
+ context.response.render "chocolate/#{context.view}", context: context
@@ -0,0 +1,13 @@
+# Plain Timbit
+# Example of the simplist timbit that could possibly be created.
+# This timbit will simply render a view using data from the query string
+# pass in 'item' via the querystring
+# e.g. /plain?item=World
+
+# load the timbits module
+timbits = require '../../src/timbits'
+
+# create and export the timbit
+timbit = module.exports = new timbits.Timbit()
+
+# additional timbit implementation code follows...
@@ -0,0 +1,27 @@
+# Story Timbit
+# Our 'prototype of a 'real world' widget
+# This one will retrieve and display a story from our CMS (SouthPARC)
+
+# load the timbits module
+timbits = require '../../src/timbits'
+
+# create and export the timbit
+timbit = module.exports = new timbits.Timbit()
+
+# additional timbit implementation code follows...
+timbit.route = '/story/:id/:view?'
+
+timbit.eat = (context) ->
+
+ # determine story id
+ id = context.request.params.id
+
+ # specify the data source
+ src = {
+ host: 'app.canada.com'
+ path: "/southparc/query.svc/content/#{id}?format=json"
+ }
+
+ # use the helper method to @fetch the data
+ # @fetch will call @render once we have the data
+ @fetch context, 'story', src
@@ -0,0 +1,2 @@
+h1 ->
+ "The current server date/time is #{@now}"
@@ -0,0 +1,8 @@
+h1 "Alternate #{@name} Timbit View"
+h2 "Recent tweets for '#{@q}'"
+
+ul ->
+ for result in @tweets.results
+ li ->
+ b "#{result.from_user}: "
+ result.text
@@ -0,0 +1,5 @@
+h1 "Default #{@name} Timbit View"
+h2 "Recent tweets for '#{@q}'"
+
+ul ->
+ li result.text for result in @tweets.results
@@ -1,3 +0,0 @@
-html ->
- body ->
- "Hello Coffee World"
@@ -1,2 +0,0 @@
-h1= title
-p Welcome to #{title}
@@ -1,6 +0,0 @@
-!!!
-html
- head
- title= title
- link(rel='stylesheet', href='/stylesheets/style.css')
- body!= body
@@ -0,0 +1,2 @@
+h1 ->
+ "Hello #{@request.query.who || 'Anonymous'}"
@@ -0,0 +1,3 @@
+h1 @story.Title
+
+div @story.Body.replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&amp;/g, '&')
View
@@ -1,9 +1,26 @@
{
- "name": "timbits"
- , "version": "0.0.1"
- , "private": true
- , "dependencies": {
- "express": "2.4.2"
- , "jade": ">= 0.0.1"
- }
-}
+ "name": "timbits",
+ "description": "Widget framework based on Express and CoffeeScript",
+ "version": "0.0.2",
+ "author": "Postmedia Network Inc.",
+ "contributors": [
+ { "name": "Edward de Groot", "email": "edegroot@postmedia.com" },
+ { "name": "Keith Benedict", "email": "kbenedict@postmedia.com" },
+ { "name": "Stephen Veerman", "email": "sveerman@postmedia.com" }
+ ],
+ "dependencies": {
+ "express": ">= 2.3.0",
+ "coffee-script": ">= 1.1.1",
+ "coffeekup": ">= 0.2.3"
+ },
+ "devDependencies": {
+ },
+ "keywords": ["framework", "widgets", "express", "coffeescript", "coffeekup"],
+ "repository": "git://github.com/postmedia/timbits",
+ "main": "./lib/timbits",
+ "bin": { "timbits": "./bin/timbits" },
+ "scripts": {
+ "build": "cake build"
+ },
+ "engines": { "node": ">= 0.4.7 < 0.5.0" }
+}
Oops, something went wrong.

0 comments on commit a78f944

Please sign in to comment.