44 */
55
66var fs = require ( 'fs' )
7+ , path = require ( "path" )
78 , extname = require ( 'path' ) . extname
89 , jsdom = require ( 'jsdom' )
910 , express = require ( 'express' )
1011 , processing = require ( '../' )
11- , app = express ( ) ;
12+ , exphbs = require ( 'express3-handlebars' )
13+ , app = express ( )
14+ , morgan = require ( 'morgan' )
15+ , serveIndex = require ( 'serve-index' ) ;
1216
13- app . use ( express . logger ( 'dev' ) ) ;
14- app . use ( '/processing-js' , express . static ( __dirname + '/../deps/processing-js' ) ) ;
15- app . use ( '/processing-js' , express . directory ( __dirname + '/../deps/processing-js' ) ) ;
17+ // Set Handlebars to use the test directory
18+ app . engine ( 'handlebars' , exphbs ( {
19+ layoutsDir : __dirname ,
20+ defaultLayout : 'main'
21+ } ) ) ;
22+ app . set ( 'views' , __dirname ) ;
23+ app . set ( 'view engine' , 'handlebars' ) ;
24+
25+ //Set up Logging
26+ app . use ( morgan ( 'combined' ) ) ;
27+
28+ var pathToref = "../deps/processing-js/test/ref" ;
29+
30+ //pull in list of test to merge with template
31+ filedata = fs . readFileSync ( path . join ( __dirname , pathToref , 'tests.js' ) , 'utf8' ) ;
32+ eval ( filedata ) ;
1633
1734process . on ( 'uncaughtException' , function ( ) { } ) ;
1835
1936app . get ( '/' , function ( req , res ) {
20- res . sendfile ( __dirname + '/index.html' ) ;
37+ res . render ( 'home' , { "tests" : tests } ) ;
2138} ) ;
2239
2340app . get ( '/test/:path(*)' , function ( req , res ) {
24- var path = req . params . path
25- , file = '/../deps/processing-js/examples/' + path ;
26-
27- fs . readFile ( __dirname + file , function ( err , data ) {
41+ var pdePath = req . params . path
42+ , file = path . join ( __dirname , pathToref , pdePath ) ;
43+ // console.log(file);
44+ fs . readFile ( file , function ( err , data ) {
45+ if ( err ) {
46+ console . log ( err ) ;
47+ res . send ( err ) ;
48+ }
2849 try {
2950 if ( '.html' === extname ( path ) ) {
3051 var document = jsdom . jsdom ( data + '' )
@@ -38,7 +59,7 @@ app.get('/test/:path(*)', function(req, res) {
3859 p5 . canvas . createPNGStream ( ) . pipe ( res ) ;
3960 } , 500 ) ;
4061 } else {
41- var p5 = processing . createInstance ( __dirname + file ) ;
62+ var p5 = processing . createInstance ( file ) ;
4263
4364 setTimeout ( function ( ) {
4465 p5 . noLoop ( ) ;
0 commit comments