The Lazy Gosuer
Less Code, More Beer

Web

The quickest way to get a web app up in Gosu is to use Ronin:

    http://ronin-web.org

Once you've downloaded Ronin, you can create a new Ronin application like so:

  Thumper carson$ ./ronin/roninit init ~/Desktop/sample_app
    Creating /Users/carson/Desktop/sample_app/build.vark
    Creating /Users/carson/Desktop/sample_app/db/init.sql
    ...
    Creating /Users/carson/Desktop/sample_app/support/vark/RoninVarkTargets.gsx

  A ronin application was created at /Users/carson/Desktop/sample_app.  To start the application:

    cd /Users/carson/Desktop/sample_app 
    vark server
      

Ronin uses Aardvark to manage the ronin application, so you should install that as well. Once you have that installed, you can follow Ronin's instructions and start up the development server:

  Thumper: carson$ cd ~/Desktop/sample_app/
  Thumper: carson$ vark server
  Buildfile: /Users/carson/Desktop/sample_app/build.vark
  [11:57:06] Done parsing Aardvark buildfile in 752 ms

  server:

  Starting server in socket debug mode at 8088
       [java] The args attribute is deprecated. Please use nested arg elements.
       [java] The jvmargs attribute is deprecated. Please use nested jvmarg elements.
       [java] Listening for transport dt_socket at address: 8088
       [java] 2010-12-12 11:57:10.159:INFO::Logging to STDERR via org.mortbay.log.StdErrLog
       [java] 2010-12-12 11:57:10.236:INFO::jetty-6.1.26
       [java] 2010-12-12 11:57:10.422:INFO::NO JSP Support for /, did not find org.apache.jasper.servlet.JspServlet
       [java] 2010-12-12 11:57:10.807:INFO::Started SocketConnector@0.0.0.0:8080
       [java] H2 DB started at jdbc:h2:file:/Users/carson/Desktop/sample_app/./runtime/h2/devdb STATUS:TCP server running on tcp://10.0.1.3:9092 (only local connections)
       [java] Creating DB from /Users/carson/Desktop/sample_app/./db/init.sql
       [java] Done
       [java] H2 web console started at http://10.0.1.3:8082 STATUS:Web server running on http://10.0.1.3:8082 (only local connections)
       [java] Use org.h2.tools.Server@59050a0 as your url, and a blank username/password to connect.
       [java] 
       [java] 
       [java] Your Ronin App is listening at http://localhost:8080
       [java] 
       [java]        
      
You can connect to the (currently uninteresting) app at http://localhost:8080.

Out of the box Ronin uses a Jetty/H2 web server/database combination.

Developing in Ronin

For a complete tutorial on how to use ronin, you should check out the main website.

To give you an idea of the flavor, though, here's a quick introduction:

Ronin maps URLs down to methods on Gosu classes located in the special (to Ronin) controller package. So a request like this:

  http://localhost:8080/Foo/bar
        
will get mapped to the bar() method on the class controller.Foo. There are conventions for passing arguments to these URLs that I won't go in to, but they aren't crazy.

Creating A Controller and View

Let's create a simple controller that answers to the URL above. Inside the src/controller directory in your Ronin project, create the a Foo.gs file with the following content:

          
  package controller

  uses ronin.*

  class Foo extends RoninController {
    function bar() {
      view.BarTemplate.render(Writer, "Hello Ronin!")
    }
  }
        
This is just a plain old Gosu class, calling through to a plain old Gosu template, located in the view package. Let's make that template:

In the src/view directory, create a file named BarTemplate.gst with the following content:

          
  <%@ params( message : String ) %>
  <html>
    <body>
      ${message}
    </body>
  </html>
        
Again, this is just a plain old Gosu template, as is available in every other Gosu program.

Note that the template takes a parameter, and that the render() method is strongly typed, taking the Writer to write the template to (in this case, the writer property inherited from RoninController, which is tied back to the HTTP request) as well as the message parameter.

Now when you navigate to http://localhost:8080/Foo/bar, the controller you created will be invoked and output the template.