1 2 //////////////////////////////////////////////////////////////////////////////////////////// 3 // Copyright (c) 2012 Christopher Nicholson-Sauls // 4 // // 5 // Permission is hereby granted, free of charge, to any person obtaining a copy of this // 6 // software and associated documentation files (the "Software"), to deal in the // 7 // Software without restriction, including without limitation the rights to use, copy, // 8 // modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, // 9 // and to permit persons to whom the Software is furnished to do so, subject to the // 10 // following conditions: // 11 // // 12 // The above copyright notice and this permission notice shall be included in all // 13 // copies or substantial portions of the Software. // 14 // // 15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, // 16 // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A // 17 // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT // 18 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF // 19 // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE // 20 // OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // 21 //////////////////////////////////////////////////////////////////////////////////////////// 22 23 module controllers.application; 24 25 import zeal.zeal; 26 27 abstract class ApplicationController : Controller { 28 29 protected this () { 30 } 31 32 } 33 34 /+ 35 New Controllers are written by subclassing your ApplicationController, each in their own 36 module. For example, given a Thing resource you might write a RESTful controller like so: 37 38 module controllers.things; 39 40 import models.thing; // this implementation is not yet part of Zeal 41 42 final class ThingsController : ApplicationController { 43 44 final void new_ ( Request req, Resposne res ) { 45 //... 46 } 47 48 final void create ( Request req, Resposne res ) { 49 //... 50 } 51 52 final void index ( Request req, Resposne res ) { 53 //... 54 } 55 56 final void show ( Request req, Resposne res ) { 57 //... 58 } 59 60 final void edit ( Request req, Resposne res ) { 61 //... 62 } 63 64 final void update ( Request req, Resposne res ) { 65 //... 66 } 67 68 final void destroy ( Request req, Resposne res ) { 69 //... 70 } 71 72 } 73 74 To route this resource you might either edit your config module like this: 75 76 enum resources = [ "things" ]; 77 78 Or you can route it from your app module: 79 80 static this () { 81 auto app = ZealApplication(); 82 83 with ( app.router ) { 84 resource!"things"; 85 } 86 } 87 88 } 89 +/