2.5. Documenting Cookbook  page     

Documenting Cookbook

Documentation is a critical step in creating maintainable code. It's often burdensome on developers and becomes a neglected. JavaScriptMVC's integrated documentation makes it easy to document JavaScript.

Generating Documentation

Before creating the docs, put your app back in development mode:

<script type='text/javascript' 
       src='../steal/steal.js?cookbook,development'>
</script>

Create the docs by running:

> documentjs/doc cookbook/cookbook.html

In fact, you've already created documentation!

Viewing Documentation

Open cookbook_doc.html (in your root directory) and click RecipeController and then Recipe:

Writing Documentaion

Open recipe_controller.js:

 /**
  * @tag controllers, home
  * Displays a table of recipes.  Lets the user 
  * ["RecipeController.prototype.form submit" create], 
  * ["RecipeController.prototype.&#46;edit click" edit],
  * or ["RecipeController.prototype.&#46;destroy click" destroy] recipes.
  */
 jQuery.Controller.extend('RecipeController',
 /* @Static */
 {
    onDocument: true
 },
 /* @Prototype */
 {
    /**
     * When the page loads, gets all recipes to be displayed.
     */
    load: function(){
        if(!$("#recipe").length) 
            $(document.body).append($(document.createElement('div')).attr('id','recipe'))
        Recipe.findAll({}, this.callback('list'));
    },

You'll notice that the syntax for documentation is very similar to JavaDoc. However, there are some important differences. Consult the [include.Doc Documentation documentation] for more information.

Next steps

In the context of this trivial application, you've been exposed to major tenets of JavaScriptMVC: code separation, testing, compression, and documentation. This is pretty cool! Look at how simply you went from nothing to a compressed, tested, and documented application.

© Jupiter IT - JavaScriptMVC Training and Support