Changeset 9128

Show
Ignore:
Timestamp:
06/19/08 16:59:55 (3 months ago)
Author:
matthias
Message:

* Added Robert's unit testing lib
* Added basic Rails style controller filter mechansim

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/aida/demo-app/app/controllers/say_controller.js

    r9111 r9128  
    1313function SayController(req, res, session) { 
    1414    
    15    this.bla = "bla" 
     15   beforeFilter(authenticate); 
     16   afterFilter(afterFilter1); 
     17   afterFilter(afterFilter2); 
     18    
     19   this.bla = "bla"; 
    1620    
    1721   function hidden() { 
     
    2428    
    2529   this.index_action = function() { 
     30      /* 
    2631      res.writeln("---" + getShortName()) 
    2732      res.writeln("---" + this.foo1) 
    2833      res.writeln("---" + this.foo2) 
     34      */ 
    2935   } 
    3036    
     
    5965      res.writeln("Hello World!" + __name__ + ":" + bar + ":" + getShortName()); 
    6066   }    
     67 
     68   // filters 
     69    
     70   function authenticate() { 
     71      return (req.data.action === "index"); 
     72   } 
     73    
     74   function afterFilter1() { 
     75      logger.info("do some logging after request:" + req.route) 
     76   } 
     77    
     78   function afterFilter2(content) { 
     79      return content + "!!!!!!!!"; 
     80   }    
     81    
    6182    
    6283} 
  • sandbox/aida/demo-app/app/models/article.js

    r9095 r9128  
    1717   var article = new Article(props); 
    1818   db.save(article); 
    19    return 'Article "' + article.title + '" was created successfully.'
     19   return article
    2020} 
    2121 
     
    2525   article.updateTime = new java.util.Date(); 
    2626   db.save(article); 
    27    return 'Article "' + article.title + '" was updated successfully.'
     27   return article
    2828} 
    2929 
     
    3131   var article = db.get('Article', id); 
    3232   db.remove(article); 
    33    return 'Article "' + article.title + '" was deleted successfully.'
     33   return article
    3434} 
  • sandbox/aida/demo-app/main.js

    r9115 r9128  
    11importModule('helma.app', 'app'); 
    22importModule('helma.rhino', 'rhino'); 
    3 importModule('helma.logging', 'logging'); 
     3 
     4// this is just for convinience while developing/debugging aida - i will remove this in the future 
    45importModule("helma.shell", "shell"); 
    5 // this is just for convinience while developing/debugging aida - i will remove this in the future 
    66global.shell = shell; 
    77 
    8 logging.setConfig(getResource('config/log4j.properties').name); 
     8// this is just for convinience while developing/debugging aida - i will remove this in the future 
     9importModule('helma.logging', 'logging'); 
     10logging.setConfig(getResource('config/environments/development/log4j.properties').name); 
    911global.logger = logging.getLogger(); 
    1012 
  • sandbox/aida/modules/aida/controller.js

    r9115 r9128  
     1 
     2importModule('helma.logging', 'logging'); 
     3logging.setConfig(getResource('config/environments/development/log4j.properties').name); 
     4var logger = logging.getLogger(__name__); 
     5 
    16importModule('helma.skin'); 
    27importModule('templating.este', 'este'); 
     
    49importModule('javascript.prototype'); 
    510importModule('routing'); 
    6  
    7 importFromModule("config.environments.development", "config"); 
     11importFromModule("filters", "*"); 
     12 
     13importFromModule("config.environments.development.development", "config"); 
    814 
    915this.context = {}; 
     16this.helpers = []; 
    1017 
    1118function getControllerInstance(name, req, res, session) { 
     
    3744function handleRequest(controllerName, req, res, session) { 
    3845   var routeSet = routing.loadRoutes(controllerName).routeSet; 
    39    var route = req.route = req.route || routeSet.recognizeRequest(req);    
    40    if (!route) return; // FIXME 404 
    41    var controller = getControllerInstance(route.controllerName, req, res, session); 
    42     
    43    Object.extend(req.data, route.params); 
    44    Object.extend(req.params, route.params); 
    45     
    46    route.handler = controller.getAction(route); 
     46   req.route = req.route || routeSet.recognizeRequest(req);    
     47   if (!req.route) return; // FIXME 404 
     48   var controller = getControllerInstance(req.route.controllerName, req, res, session); 
     49    
     50   Object.extend(req.data, req.route.params); 
     51   Object.extend(req.params, req.route.params); 
     52    
     53   req.route.handler = controller.getAction(req.route); 
     54   controller.actionName = req.route.action; 
     55    
    4756   var content = ""; 
     57   if (!controller.beforeFilters.all()) return; 
     58   var content = controller.callAction(req.route.handler, req, res, session); 
     59   for (var i=0; i<controller.afterFilters.length; i++) { 
     60      content = controller.afterFilters[i].call(controller, content, req, res, session) || content; 
     61   } 
     62   res.write(content); 
     63} 
     64 
     65 
     66function callAction(handler, req, res, session) { 
    4867   res.push(); 
    4968//   try { 
    50       route.handler.call(controller);       
     69      handler.call(this); 
    5170/*   } catch(e) { 
    5271      res.write(e.rhinoException); 
    5372   } */ 
     73   if (!res.calledRender) this.render(); 
    5474   content = res.pop(); 
    55    (res.calledRender) ? res.write(content) : controller.render(); 
    56 
    57  
     75   return content; 
     76
    5877 
    5978/** 
     
    371390} 
    372391 
     392 
    373393importFromModule("helma.file", "File"); 
    374394/**