Permalink
Browse files

conversion to JS and Hogan partially completed

  • Loading branch information...
1 parent 104b550 commit 9ac8a1b3494d90e0cf922a7ed8c39542b2ae6dea Edward de Groot committed Jun 3, 2013
Showing with 1,469 additions and 1,022 deletions.
  1. +0 −1 .gitignore
  2. +0 −29 Cakefile
  3. +0 −48 bin/template/test/timbits-test.coffee
  4. +75 −0 bin/template/test/timbits-test.js
  5. +0 −30 bin/template/timbit.coffee
  6. +37 −0 bin/template/timbit.js
  7. +6 −6 bin/timbits
  8. +0 −10 examples/helpers/handy.coffee
  9. +3 −0 examples/helpers/hello.js
  10. +0 −9 examples/server.coffee
  11. +7 −0 examples/server.js
  12. +0 −21 examples/timbits/cherry.coffee
  13. +25 −0 examples/timbits/cherry.js
  14. +0 −38 examples/timbits/chocolate.coffee
  15. +53 −0 examples/timbits/chocolate.js
  16. +0 −23 examples/timbits/dutchie.coffee
  17. +25 −0 examples/timbits/dutchie.js
  18. +0 −24 examples/timbits/plain.coffee
  19. +45 −0 examples/timbits/plain.js
  20. +0 −2 examples/views/cherry/default.coffee
  21. +1 −0 examples/views/cherry/default.hjs
  22. +0 −8 examples/views/chocolate/alternate.coffee
  23. +8 −0 examples/views/chocolate/alternate.hjs
  24. +0 −6 examples/views/chocolate/default.coffee
  25. +8 −0 examples/views/chocolate/default.hjs
  26. +0 −16 examples/views/plain/default.coffee
  27. +15 −0 examples/views/plain/default.hjs
  28. +0 −5 examples/views/plain/with-help.coffee
  29. +4 −0 examples/views/plain/with-help.hjs
  30. +59 −0 lib/templates/help.hjs
  31. 0 lib/templates/test.hjs
  32. +116 −0 lib/templates/timbit-help.hjs
  33. 0 lib/templates/timbit-test.hjs
  34. +364 −0 lib/timbits-views.js
  35. +521 −0 lib/timbits.js
  36. +4 −6 package.json
  37. 0 resources/stylesheets/timbits.css
  38. +0 −296 src/timbits-views.coffee
  39. +0 −382 src/timbits.coffee
  40. +0 −62 test/timbits-test.coffee
  41. +93 −0 test/timbits-test.js
View
@@ -1,4 +1,3 @@
.DS_Store
node_modules/
-lib/*.js
*.log
View
@@ -1,29 +0,0 @@
-{spawn} = require 'child_process'
-
-option '-a', '--all', 'run all dynamic tests'
-option '-w', '--watch', 'watch for changes'
-
-task 'build', '', (options) ->
- args = ['-c', '-o', 'lib', 'src']
- args.splice 2, 0, '-w' if options.watch
-
- coffee = spawn 'coffee', args, {stdio: 'inherit', env: process.env}
-
-task "test", "run all dynamic tests", (options) ->
- process.env.TIMBITS_TEST_WHICH = 'all' if options.all
-
- args = [
- '--reporter'
- 'spec'
- '--compilers'
- 'coffee:coffee-script'
- '--growl'
- '--colors'
- ]
-
- args.push '--watch' if options.watch
-
- mocha = spawn 'mocha', args, {
- stdio: 'inherit'
- env: process.env
- }
@@ -1,48 +0,0 @@
-# reduce logging levels to provide clean test feedback
-process.env.TIMBITS_VERBOSITY = 'critical'
-process.env.PANTRY_VERBOSITY = 'critical'
-
-# Module dependencies.
-timbits = require 'timbits'
-should = require 'timbits/node_modules/should'
-request = require 'timbits/node_modules/request'
-
-port = 8785
-alltests = process.env.TIMBITS_TEST_WHICH is 'all'
-
-server = timbits.serve( {port: port })
-
-validateRequest = (vpath, expect = 'html') ->
- describe vpath, ->
- test_msg = "should respond with #{expect} and status 200"
- if typeof expect isnt 'string'
- test_msg = "should respond with status #{expect}"
-
- it test_msg, (done) ->
- request "http://localhost:#{port}#{vpath}", (err, res) ->
- should.not.exist err
- if typeof expect is 'string'
- res.should.have.status 200
- if expect is 'json'
- res.should.be.json
- else
- res.should.be.html
- else
- res.should.have.status expect
- done()
-
-
-describe 'timbits', ->
-
- describe 'automated test cases', ->
- for name, timbit of timbits.box
- if timbit.examples?
- describe "specified examples for #{name}", ->
- for example in timbit.examples
- validateRequest example.href
-
- dynatests = timbit.generateTests(alltests)
- if dynatests.length
- describe "dynamic tests for #{name}", ->
- for href in dynatests
- validateRequest href
@@ -0,0 +1,75 @@
+// reduce logging levels to provide clean test feedback
+process.env.TIMBITS_VERBOSITY = 'critical';
+process.env.PANTRY_VERBOSITY = 'critical';
+
+// load modules
+var timbits = require('../lib/timbits')
+ , should = require('should')
+ , path = require('path')
+ , request = require('request')
+
+// set testing environment
+var port = 8785
+ , alltests = process.env.TIMBITS_TEST_WHICH === 'all';
+
+// create test server
+var server = timbits.serve({
+ home: process.cwd(),
+ port: port,
+ verbosity: 'critical'
+});
+
+
+// helper function for testing requests
+function validateRequest(vpath, expect) {
+ expect = expect || 'html';
+
+ describe(vpath, function() {
+ var test_msg = "should respond with " + expect + " and status 200";
+ if (typeof expect !== 'string')
+ test_msg = "should respond with status " + expect;
+
+ it(test_msg, function(done) {
+ request("http://localhost:" + port + vpath, function(err, res) {
+ should.not.exist(err);
+ if (typeof expect === 'string') {
+ res.should.have.status(200);
+ if (expect === 'json')
+ res.should.be.json;
+ else
+ res.should.be.html;
+ } else {
+ res.should.have.status(expect);
+ }
+ done();
+ });
+ });
+ });
+};
+
+
+describe('timbits', function() {
+ describe('automated test cases', function() {
+ for (name in timbits.box) {
+
+ timbit = timbits.box[name];
+
+ if (timbit.examples != null) {
+ describe('specified examples for ' + name, function() {
+ timbit.examples.forEach(function(example) {
+ validateRequest(example.href);
+ });
+ });
+ }
+
+ var dynatests = timbit.generateTests(alltests);
+ if (dynatests.length) {
+ describe("dynamic tests for " + name, function() {
+ dynatests.forEach(function(href) {
+ validateRequest(href);
+ });
+ });
+ }
+ }
+ });
+});
View
@@ -1,30 +0,0 @@
-# Timbit
-
-# load the timbits module
-timbits = require 'timbits'
-
-# create and export the timbit
-timbit = module.exports = new timbits.Timbit()
-
-# additional timbit implementation code follows...
-
-#timbit.about = 'a description about this timbit'
-
-#timbit.examples = [
-# {href: '/timbit/?q=winning', caption: 'Default View'}
-# {href: '/timbit/alternate?q=winning', caption: 'Alternate View'}
-#]
-
-#timbit.params = {
-# q: {description: 'Keyword to search for',required: true, strict: false, values: ['Coffee', 'Timbits']}
-#}
-
-timbit.eat = (req, res, context) ->
-
- src = {
- uri: "http://search.twitter.com/search.json?q=#{context.q}"
- }
-
- # use the helper method to @fetch the data
- # @fetch will call @render once we have the data
- @fetch req, res, context, src
View
@@ -0,0 +1,37 @@
+// Timbit
+
+// load the timbits module
+var timbits = require('timbits');
+
+//create and export the timbit
+var timbit = module.exports = new timbits.Timbit();
+
+// additional timbit implementation code follows...
+
+timbit.about = 'a description about this timbit';
+
+timbit.examples = [
+ {
+ href: '/timbit/?q=winning',
+ caption: 'Default View'
+ }, {
+ href: '/timbit/alternate?q=winning',
+ caption: 'Alternate View'
+ }
+];
+
+timbit.params = {
+ q: {
+ description: 'Keyword to search for',
+ required: true,
+ strict: false,
+ values: ['Coffee', 'Timbits']
+ }
+};
+
+timbit.eat = function(req, res, context) {
+ var = {
+ uri: 'http://search.twitter.com/search.json?q=' + context.q
+ };
+ timbit.fetch(req, res, context, src);
+};
View
@@ -106,8 +106,8 @@ function newProject(name) {
// copy test template
console.log('Generating test template: ' + name + '-test.coffee');
cp(
- path.join(template, 'test', 'timbits-test.coffee'),
- path.join(project_home, 'test', name + '-test.coffee')
+ path.join(template, 'test', 'timbits-test.js'),
+ path.join(project_home, 'test', name + '-test.js')
);
// create package file
@@ -159,18 +159,18 @@ function newProject(name) {
function generateTimbit(name) {
console.log("Generating timbit '" + name + "'");
if(
- fs.existsSync(path.join('timbits', name + '.coffee')) ||
+ fs.existsSync(path.join('timbits', name + '.js')) ||
fs.existsSync(path.join('views', name))
) {
console.log('ERROR! The timbit ' + name + ' may already exist!');
return;
}
// create timbit
- console.log('Creating timbits/' + name + '.coffee');
+ console.log('Creating timbits/' + name + '.js');
cp(
- path.join(template, 'timbit.coffee'),
- path.join('timbits', name + '.coffee')
+ path.join(template, 'timbit.js'),
+ path.join('timbits', name + '.js')
);
// create default view
@@ -1,10 +0,0 @@
-ck = require 'coffeekup'
-
-@sayHello = (name) ->
- "Hello #{name}!"
-
-@linkIt = (href, caption) ->
- ck.render link, href: href, caption: caption
-
-link = ->
- a href: @href, -> @caption
@@ -0,0 +1,3 @@
+module.exports = function hello(name) {
+ return 'Hello there ' + name;
+};
View
@@ -1,9 +0,0 @@
-# set logging level
-process.env.TIMBITS_VERBOSITY = 'debug'
-process.env.PANTRY_VERBOSITY = 'debug'
-
-# Module dependencies.
-timbits = require '../src/timbits'
-
-# start serving timbits
-server = timbits.serve {home: __dirname}
View
@@ -0,0 +1,7 @@
+process.env.TIMBITS_VERBOSITY = 'debug';
+process.env.PANTRY_VERBOSITY = 'debug';
+
+var timbits = require('../lib/timbits');
+var server = timbits.serve({
+ home: __dirname
+});
@@ -1,21 +0,0 @@
-# Cherry Timbit
-
-# 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.about = '
- Example of a timbit which actually does something.
- This timbit will display the current server time.
- '
-
-timbit.examples = [
- {href: '/cherry/', caption: 'Current Time'}
-]
-
-timbit.eat = (req, res, context) ->
- context.now = new Date()
- @render req, res, context
View
@@ -0,0 +1,25 @@
+// Cherry Timbit
+
+// load the timbits module
+var timbits = require('../../lib/timbits');
+
+// create and export the timbit
+var timbit = module.exports = new timbits.Timbit();
+
+// additional timbit implementation code follows...
+timbit.about = '\
+ Example of a timbit which actually does something.\
+ This timbit will display the current server time.\
+ ';
+
+timbit.examples = [
+ {
+ href: '/cherry/',
+ caption: 'Current Time'
+ }
+];
+
+timbit.eat = function(req, res, context) {
+ context.now = new Date();
+ return this.render(req, res, context);
+};
@@ -1,38 +0,0 @@
-# Chocolate Timbit
-
-# 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.about = '
- 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
- '
-
-timbit.examples = [
- {href: '/chocolate/?q=winning', caption: 'Winning - Default View'}
- {href: '/chocolate/alternate?q=winning&rpp=20', caption: 'Winning - Alternate View'}
-]
-
-timbit.params = {
- q: {description: 'Keyword to search for', required: true, strict: false, values: ['Coffee', 'Timbits']}
- rpp: {description: 'Maximum number of tweets to display', alias: 'max', type: 'Number', default: 10, values: [1, 8, 16]}
-}
-
-timbit.eat = (req, res, context) ->
-
- # specify the data source
- src = {
- name: 'tweets'
- uri: "http://search.twitter.com/search.json?q=#{context.q}&rpp=#{context.rpp}"
- }
-
- @log.debug src.uri
-
- # use the helper method to @fetch the data
- # @fetch will call @render once we have the data
- @fetch req, res, context, src
Oops, something went wrong.

0 comments on commit 9ac8a1b

Please sign in to comment.