Permalink
Browse files

cleanup and re-org.

  • Loading branch information...
1 parent 32f7060 commit c0d43740e69cef1c8d81ea6e4cbc0fb683b43372 Kellen Presley committed Nov 20, 2009
Showing with 23 additions and 17 deletions.
  1. +3 −1 README.textile
  2. +1 −1 vendor/picard/lib/picard.js
  3. +19 −15 vendor/picard/lib/picard/{routes.js → engine.js}
View
@@ -4,4 +4,6 @@ p. If you want to check it out, install "Node":http://nodejs.org and start it wi
!http://bloglikepattern.com/images/picard.png!
-p. Right now it only supports stupid simple GET requests, but it does support Haml thanks to creationix's haml-js project.
+p. Picard uses Haml thanks to creationix's haml-js project.
+
+p. Red Alert: Picard is just for fun, so don't use it for reals.
@@ -1,7 +1,7 @@
var sys = require('sys')
picard = exports;
-picard.routes = require('./picard/routes')
+picard.routes = require('./picard/engine')
picard.start = function() {
require('http').createServer(function(request, response) {
@@ -36,7 +36,7 @@ var routes = {
request.resolve = function(response){
var scope = null
- scope = routes.handle(this, request.method)
+ scope = routes.execute_callback(this)
if( scope == null )
this.serve_static()
@@ -79,12 +79,24 @@ var routes = {
}
},
- handle: function(request, method){
- var route_array = []
+ execute_callback: function(request){
+ var rest_type = routes.rest_type(request)
- if(method == "GET")
+ for(var route in route_array){
+ var matches = routes.match(request.uri.path, route)
+
+ if( matches ){ // incoming request matches route
+ request.extract_route_params(route, matches)
+ return rest_type[route](request)
+ }
+ }
+ },
+
+ rest_type: function(request){
+ route_array = []
+ if(request.method == "GET")
route_array = get_routes
- else if(method == "POST"){
+ else if(request.method == "POST"){
route_array = post_routes
var rest_method = request._method
@@ -95,17 +107,9 @@ var routes = {
route_array = delete_routes
}
}
-
- for(var route in route_array){
- var match_data = routes.match(request.uri.path, route)
-
- if(match_data){ // incoming request matches route
- request.extract_route_params(route, match_data)
- return route_array[route](request)
- }
- }
+ return route_array
},
-
+
match: function(path, route){
var full_route = '^'+route+'$'
var regexp = new RegExp(full_route.replace(/:[^/]*/g, '([^/]*)'))

0 comments on commit c0d4374

Please sign in to comment.