Generating stubs
Our simple web site will have only two pages - one to generate the Fibonacci number sequence and a help page.
Although we could create all the required files manually, we'll
save a bit of work by using the Woof! application generator
wag. If you are
using bowwow.exe
, this is built into the program:
C:\fibo> bowwow url fibonacci/generate fibonacci/help
If you are not using bowwow.exe
, wag
has
to be invoked as a script:
~/fibo> tclsh scripts/wag.tcl url fibonacci/generate fibonacci/help
Invoking either of the above commands will result in the following output:
C:\fibo> bowwow url fibonacci/generate fibonacci/help Controller FibonacciController: File app/controllers/fibonacci_controller.tcl will be created. Class FibonacciController will be created. Methods to be added: generate, help. View stubs to be added: app/controllers/views/fibonacci-generate-main.wtf app/controllers/views/fibonacci-help-main.wtf Do you want to continue? [YN] y Created file app/controllers/fibonacci_controller.tcl Created class FibonacciController. Created action FibonacciController.generate. Created action FibonacciController.help. Created view app/controllers/views/fibonacci-generate-main.wtf. Created view app/controllers/views/fibonacci-help-main.wtf.
The url command generates stubs for the specified relative URL(s). So the above commands will generate stubs for Web pages accessed through /fibonacci/generate and /fibonacci/help on our web site.
The url command will first display the actions it will take in creating the stubs, and then prompt for the go-ahead to actually do so. In this Quick Start chapter, we will ignore the MVC-based naming conventions being used when generating the stubs. It suffices to know that the stub generator will create a class FibonacciController whose methods will be called to handle URL's that are prefixed with /fibonacci. The stub generator also creates two methods - generate and help - corresponding to the two URL's we specified on the command line.
If you edit the file app/controllers/fibonacci_controller.tcl under your BowWow directory, you will see the following contents:
oo::class create FibonacciController { superclass ApplicationController constructor args { # Very important to pass arguments to parent next {*}$args } } oo::define FibonacciController { method generate {} { # Raise an exception that allows woofer to detect unimplemented actions ::woof::errors::exception WOOF NotImplemented "Action generate has no supporting implementation." } method help {} { # Raise an exception that allows woofer to detect unimplemented actions ::woof::errors::exception WOOF NotImplemented "Action help has no supporting implementation." } }
As you can see, the stubs will generate exceptions if invoked. For example, navigating to http://localhost:8015/fibonacci/help will result in an error page being displayed in the browser.