Fork me on GitHub

Important Details

These are some specifics to caboose that you may need to know


Application directory structure

/project_root/
|-- app/
|   |-- controllers/
|   |   |-- application_controller.coffee
|   |-- helpers/
|   |   |-- application_helper.coffee
|   |-- views/
|   |   |-- application/
|   |   |   |-- index.html.ejs
|   |   |-- layouts/
|   |       |-- application.html.ejs
|-- config/
|   |-- application.coffee
|   |-- environments/
|   |   |-- development.coffee
|   |   |-- production.coffee
|   |-- initializers/
|   |-- middleware.coffee
|   |-- routes.coffee
|-- lib/
|-- package.json
|-- public/
|-- README.md
    

Naming conventions matter

Throughout caboose, file and class naming is very important. These conventions allow for flexibility and ease of use.

In some cases, files with js and coffee extensions are used completely differently. These cases will be identified in the documentation. In all other cases all code can be written in javascript rather than coffeescript. Just change the file extension to js and go to town.

The import keyword

Caboose introduces the import keyword as an easy and concise way to pull in controllers and helpers.

Basically,

import 'SomeController'
import 'SomeViewHelper'
    

actually translates to

SomeController = Caboose.get('SomeController')
SomeViewHelper = Caboose.get('SomeViewHelper')
    

The import keyword can be extended to recognize other modules too. The caboose-model plugin does this by adding support for model loading through the import keyword.

The enforcement of naming conventions and the directory where files are located make all of this possible.

The boot process

  • Parse routes from config/routes.coffee
  • Read json files into config
    • Read all json files in config directory
    • Read all json files in config/environments/[current environment] directory
  • Execute configuration files
    • Execute config/application.coffee
    • Execute config/environments/[current environment].coffee (if it exists)
  • Execute all initializers in config/initializers in alphanumeric order
  • Create http server using express
  • Execute config/middleware.coffee
  • Tell the http server to start listening on the configured port
  • Execute all post_boot hooks configured during initialization