Skip to content

Commands, Generators, and Tasks

Lance Pollard edited this page Sep 24, 2012 · 4 revisions

Tower console commands

New app

tower new <app-name> [options]

Server

tower server

Note: node server works well and is pure node.

Console

Use the Tower.js console to programmatically mess around with your application data.

tower console

You can also run the console in CoffeeScript!

tower console -c

Generators

tower generate <generator> [args] [options]

See the available Generators for details on how to use them.

Generate Modules (todo)

tower generate module my-library

Generators

Application Generator

Tower comes with a full application skeleton generator similar to the Rails variant. To use the app generator, simply execute the following in a console.

tower new my-app

The generated application will have the following structure:

|-- app
|   |-- client
|   |   |-- stylesheets
|   |   |   `-- application.stylus
|   |   |-- config
|   |   |   `-- assets.coffee
|   |-- controllers
|   |   `-- applicationController.coffee
|   |-- models
|   |-- views
|   |   |-- layouts
|   |   |   `-- application.coffee
|   |   |-- index.coffee
|   `-- helpers
|   |   `-- applicationHelper.coffee
|-- Cakefile
|-- config
|   |-- application.coffee
|   |-- environments
|   |   |-- development.coffee
|   |   |-- production.coffee
|   |   `-- test.coffee
|   |-- locale
|   |   `-- en.coffee
|   |-- routes.coffee
|   |-- database.coffee
|-- lib
|-- package.json
|-- public
|   |-- favicon.ico
|   |-- humans.txt
|   `-- robots.txt
|-- README.md
|-- spec
|   |-- helper.coffee
|   |-- models
|   `-- acceptance
`-- vendor
|   |-- javascripts
|   |   |-- tower.js
|   |   |-- underscore.js
|   `-- stylesheets
`-- Watchfile

Options for the new command:

The following options are currently supported:

--javascripts <format>  Format for JavaScripts (coffee, js)
--stylesheets <format>  Format for StyleSheets (styl, less, css)
--views <format>        Format for Views (coffee, jade, mustache)
--database <type>       Database type (mongodb, memory, sqlite3)
--test <framework>      Testing framework (jasmine, vows, qunit, assert)
--docs <format>         Documentation format (md, markdown, textile, txt)
-v, --version           Output the version number
-h, --help              Output usage information

In a future release Tower will likely support a --locales option.

Scaffold Generator

tower generate scaffold Post title:string body:text belongsTo:user

Generates:

|-- app
|   |-- controllers
|   |   |   `-- usersController.coffee
|   |-- models
|   |   |   `-- user.coffee
|   |-- views
|   |   |-- users
|   |   |   `-- _form.coffee
|   |   |   `-- edit.coffee
|   |   |   `-- index.coffee
|   |   |   `-- new.coffee
|   |   |   `-- show.coffee
|   `-- helpers
|   |   |   `-- userHelper.coffee
`-- spec
|    |-- models
|   |   |   `-- userSpec.coffee

Model Generator

tower generate model Post title:string body:text belongsTo:user

Generates:

|-- app
|   |-- models
|   |   |   `-- post.coffee

The Post model generated:

class App.Post extends Tower.Model
  @field "id", type: "Id"
  @field "title"
  @field "body"
  @belongs_to "user", type: "User", foreignKey: "userId"
  @field "createdAt", type: "Time", default: -> new Date()

View Generator

tower generate view Post title:string body:text belongsTo:user

Generates:

|-- app
|   |-- views
|   |   |-- users
|   |   |   `-- _form.coffee
|   |   |   `-- edit.coffee
|   |   |   `-- index.coffee
|   |   |   `-- new.coffee
|   |   |   `-- show.coffee

Controller Generator

To create a Controller for the User model, execute the Controller Generator like this:

tower generate controller Post

The controller should generate a single controller file:

|-- app
|   |-- controllers
|   |   |   `-- postsController.coffee

The controller will initially be empty:

class App.PostsController extends Tower.Controller

Fill it out as needed:

class App.PostsController extends Tower.Controller
  @respondTo "html", "json"

  new: ->
    @posts = Post.all()

Clone this wiki locally