Permalink
Browse files

Code reformatting for better readability

Change some comments here and there, formatted the code differently to
have better readability. Mainly for comments and var/function types
  • Loading branch information...
njuneau committed Aug 2, 2011
1 parent ccc7f94 commit 11eb6e8319a8da4a1f6b428768cc994cc62eeb08
View
@@ -13,6 +13,6 @@
#--------------------- Templates ---------------------#
--resource src/server/blog/templates/index.ntt@blog_view_index
+-resource src/server/test/templates/index.ntt@blog_view_index
#--------------------- Javascript ---------------------#
View
File renamed without changes.
@@ -6,7 +6,7 @@ package hawk.exceptions;
*/
class Exception {
- private var message:String;
+ private var message : String;
/**
* Creates a new exception
@@ -28,7 +28,7 @@ class Exception {
* Returns the Exception's message
* @return the Exception's message
*/
- public function getMessage():String {
+ public function getMessage() : String {
return this.message;
}
}
@@ -22,7 +22,7 @@ class AbstractModule implements Module {
* Returns all the URLs mapping that belongs to this module
* @return A list of all the URL mappings contained in the module
*/
- public function getURLMappings():Iterable<URLMapping> {
+ public function getURLMappings() : Iterable<URLMapping> {
return this.urlMappings;
}
@@ -32,7 +32,7 @@ class AbstractModule implements Module {
* @param controller The controller to call
* @param controllerFunctionName The controller's function to call
*/
- private function addURLMapping(urlReg : EReg, controllerClass : Class<Controller>, controllerFunctionName : String) {
+ private function addURLMapping(urlReg : EReg, controllerClass : Class<Controller>, controllerFunctionName : String) : Void {
this.urlMappings.add(new URLMapping(urlReg, controllerClass, controllerFunctionName));
}
@@ -10,12 +10,16 @@ import hawk.exceptions.Exception;
*/
class AbstractServerConfiguration implements ServerConfiguration {
- /*************************************/
- /* PRIVATE FIELDS */
- /*************************************/
+ /**************************************************************************/
+ /* PRIVATE FIELDS */
+ /**************************************************************************/
- //The list of modules of the server side of your application
- private var modules:List<Module>;
+ // The list of modules of the server side of your application
+ private var modules : List<Module>;
+
+ /**************************************************************************/
+ /* PUBLIC METHODS */
+ /**************************************************************************/
/**
* Constructs a default implementation of the server configuration
@@ -24,10 +28,6 @@ class AbstractServerConfiguration implements ServerConfiguration {
this.modules = new List<Module>();
}
- /*************************************/
- /* PUBLIC METHODS */
- /*************************************/
-
/**
* Dispatch event - called when the queried URL corresponds to a controller
* (the URL has been dispatched). Call done before the controller is called
@@ -49,9 +49,9 @@ class AbstractServerConfiguration implements ServerConfiguration {
*/
public function onClose() : Void {}
- /*************************************/
- /* GETTERS */
- /*************************************/
+ /**************************************************************************/
+ /* GETTERS */
+ /**************************************************************************/
/**
* Returns the modules contained in the application
@@ -61,9 +61,9 @@ class AbstractServerConfiguration implements ServerConfiguration {
return this.modules;
}
- /*************************************/
- /* PRIVATE METHODS */
- /*************************************/
+ /**************************************************************************/
+ /* PRIVATE METHODS */
+ /**************************************************************************/
/**
* Adds a server module in the configuration's list of modules
@@ -12,5 +12,5 @@ interface Module {
* Returns all the URLs mapping that belongs to this module
* @return A list of all the URL mappings contained in the module
*/
- public function getURLMappings():Iterable<URLMapping>;
+ public function getURLMappings() : Iterable<URLMapping>;
}
@@ -18,16 +18,16 @@ import server.UserConfiguration;
*/
class ServerMain {
- //This contains the user's server-side configuration
- private static var userConfiguration:ServerConfiguration;
- //Our URL dispatcher
- private static var urlDispatcher:URLDispatcher;
+ // This contains the user's server-side configuration
+ private static var userConfiguration : ServerConfiguration;
+ // Our URL dispatcher
+ private static var urlDispatcher : URLDispatcher;
/**
* Program's entry point, starts up pretty much everything and handles
* the recieved request.
*/
- public static function main() {
+ public static function main() : Void {
// Load the configuration
userConfiguration = new UserConfiguration();
@@ -62,7 +62,7 @@ class ServerMain {
* @param url The url in which to append the slash
* @return The url, with the trailing slash
*/
- private static function appendSlash(url:String):String {
+ private static function appendSlash(url : String) : String {
if(url.charAt(url.length - 1) != "/") {
url += "/";
@@ -11,16 +11,16 @@ import hawk.exceptions.ServerErrorException;
*/
class URLDispatcher {
- /*************************************/
- /* PRIVATE FIELDS */
- /*************************************/
+ /**************************************************************************/
+ /* PRIVATE FIELDS */
+ /**************************************************************************/
// The server's configuration
- private var serverConfiguration:ServerConfiguration;
+ private var serverConfiguration : ServerConfiguration;
//The modules that this dispatcher handles
- private var modules:Iterable<Module>;
+ private var modules : Iterable<Module>;
//The URL that is currently being processed
- private var currentURL:String;
+ private var currentURL : String;
/**
* Constructor
@@ -31,45 +31,45 @@ class URLDispatcher {
this.serverConfiguration = serverConfiguration;
}
- /*************************************/
- /* BEHAVIOR */
- /*************************************/
+ /**************************************************************************/
+ /* PUBLIC METHODS */
+ /**************************************************************************/
/**
* Dipatches the URL to the correct view
* @param url The URL to process
*/
- public function dispatch(url:String):Void {
+ public function dispatch(url:String) : Void {
this.currentURL = url;
var dispatched:Bool = false;
var moduleIterator:Iterator<Module> = this.serverConfiguration.getModules().iterator();
- //Scan all the URLS
+ // Scan all the URLS
while(!dispatched && moduleIterator.hasNext()) {
dispatched = this.scanURLs(moduleIterator.next());
}
- //If the URL could not have been dispatched, throw some kind of 404
+ // If the URL could not have been dispatched, throw a 404 error
if(!dispatched) {
throw new NotFoundException();
}
}
- /*************************************/
- /* PRIVATE METHODS */
- /*************************************/
+ /**************************************************************************/
+ /* PRIVATE METHODS */
+ /**************************************************************************/
/**
* Try matching the URLS with one of the module's regexes.
* @return Scan status (true if URL has been found, false otherwize)
*/
- private function scanURLs(module:Module):Bool {
+ private function scanURLs(module : Module) : Bool {
var foundURL = false;
var mappingIterator : Iterator<URLMapping> = module.getURLMappings().iterator();
var currentMapping : URLMapping = null;
var controller : Controller = null;
- var controllerFunction:Dynamic = null;
- var controllerFunctionParams:Array<String> = null;
+ var controllerFunction : Dynamic = null;
+ var controllerFunctionParams : Array<String> = null;
// Try matching a pattern
while(!foundURL && mappingIterator.hasNext()) {
@@ -83,18 +83,19 @@ class URLDispatcher {
// Call the dispatch event
this.serverConfiguration.onDispatch(currentMapping);
+ // Create the controller instance and find its function
controller = Type.createInstance(currentMapping.getControllerClass(), [this.serverConfiguration]);
controllerFunction = Reflect.field(controller, currentMapping.getControllerFunctionName());
// Make the call with the correct parameters
if(Reflect.isFunction(controllerFunction)) {
// Handle request
if(controller.handleRequest()) {
- Reflect.callMethod(
- controller,
- controllerFunction,
- this.extractParameters(currentMapping)
- );
+ Reflect.callMethod(
+ controller,
+ controllerFunction,
+ this.extractParameters(currentMapping)
+ );
}
} else {
// Controller function was not found - error!
@@ -111,18 +112,18 @@ class URLDispatcher {
* Extract the parameters tha the controller needs from the URL
* @param urlMapping The URLMapping in which to extract the parameters
*/
- private function extractParameters(urlMapping:URLMapping):Array<String> {
- var parameters:Array<String> = new Array();
- var regEx:EReg = urlMapping.getURLReg();
- var counter:Int = 0;
- var parameter:String = regEx.matched(counter + 1);
+ private function extractParameters(urlMapping:URLMapping) : Array<String> {
+ var parameters : Array<String> = new Array();
+ var regEx : EReg = urlMapping.getURLReg();
+ var counter : Int = 1;
+ var parameter : String = null;
// Get trough all the groups and fill the needed parameters
- while(parameter != null) {
+ do {
+ parameter = regEx.matched(counter);
parameters.push(parameter);
counter++;
- parameter = regEx.matched(counter + 1);
- }
+ } while(parameter != null);
return parameters;
}
View
@@ -9,50 +9,58 @@ import hawk.server.Controller;
*/
class URLMapping {
- /*************************************/
- /* PRIVATE FIELDS */
- /*************************************/
+ /**************************************************************************/
+ /* PRIVATE FIELDS */
+ /**************************************************************************/
//The regular expression that corresponds to the URL
- private var urlReg:EReg;
+ private var urlReg : EReg;
//The controller class to instanciate if the URL is matched
- private var controllerClass:Class<Controller>;
+ private var controllerClass : Class<Controller>;
//The controller's function to call
- private var controllerFunctionName:String;
+ private var controllerFunctionName : String;
+
+ /**************************************************************************/
+ /* PUBLIC METHODS */
+ /**************************************************************************/
/**
* Construct a new URL Mapping
* @param urlReg The expression that matches the sent URL
* @param controller The controller to call
* @param controllerFunctionName The controller's function to call
*/
- public function new(urlReg:EReg, controllerClass:Class<Controller>, controllerFunctionName:String) {
+ public function new(urlReg : EReg, controllerClass : Class<Controller>, controllerFunctionName : String) {
this.urlReg = urlReg;
this.controllerClass = controllerClass;
this.controllerFunctionName = controllerFunctionName;
}
+ /**************************************************************************/
+ /* GETTERS */
+ /**************************************************************************/
+
/**
* Returns the URL regex contained in the mapping
* @return The URL regex contained in the mapping
*/
- public function getURLReg():EReg {
+ public function getURLReg() : EReg {
return this.urlReg;
}
/**
* Returns the controller contained in the mapping
* @return The controller contained in the mapping
*/
- public function getControllerClass():Class<Controller> {
+ public function getControllerClass() : Class<Controller> {
return this.controllerClass;
}
/**
* Returns the regex groups contained in the mapping
* @return The regex groups contained in the mapping
*/
- public function getControllerFunctionName():String {
+ public function getControllerFunctionName() : String {
return this.controllerFunctionName;
}
}
View
@@ -29,7 +29,7 @@ class View extends ViewComposite {
* @param macros Template macros
* @return The rendered template
*/
- public override function render(context : Dynamic, macros : Dynamic = null) {
+ public override function render(context : Dynamic, macros : Dynamic = null) : String {
var subResult : String = this.renderTemplate(context, macros);
// Set child view in the template context
@@ -2,11 +2,11 @@ package server;
import hawk.server.AbstractServerConfiguration;
-import server.blog.Blog;
+import server.test.Test;
/**
- * This contains the user's configuration - do it the way you want,
- * as long as you implement de needed methods, described in the interface.
+ * This contains the user's configuration. Refer to the ServerConfiguration
+ * interface to see the available methods
*/
class UserConfiguration extends AbstractServerConfiguration {
@@ -15,7 +15,7 @@ class UserConfiguration extends AbstractServerConfiguration {
*/
public function new() {
super();
- this.addModule(new Blog());
+ this.addModule(new Test());
}
}
File renamed without changes.
Oops, something went wrong.

0 comments on commit 11eb6e8

Please sign in to comment.