peerlibrary/codo

Name: codo

Owner: PeerLibrary

Description: CoffeeScript API documentation generator. It's like YARD but for CoffeeScript!

Forked from: coffeedoc/codo

Created: 2016-03-01 06:13:12.0

Updated: 2016-03-01 06:13:13.0

Pushed: 2016-02-14 09:31:17.0

Homepage: http://coffeedoc.info

Size: 2127

Language: CoffeeScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Codo Build Status

Codo is a CoffeeScript API documentation generator, similar to YARD. Its generated documentation is focused on CoffeeScript class syntax for classical inheritance.

Features
Codo in action

Annotate your source with Codo tags to add semantic information to your code. It looks like this:

se class for all animals.

xample How to subclass an animal
class Lion extends Animal
  move: (direction, speed): ->

s Example.Animal

The Answer to the Ultimate Question of Life, the Universe, and Everything
NSWER = 42

Construct a new animal.

@param [String] name the name of the animal
@param [Date] birthDate when the animal was born

nstructor: (@name, @birthDate = new Date()) ->

Move the animal.

@example Move an animal
  new Lion('Simba').move('south', 12)

@param [Object] options the moving options
@option options [String] direction the moving direction
@option options [Number] speed the speed in mph

ve: (options = {}) ->

Then generate the documentation with the codo command line tool. You can browse some generated Codo documentation on CoffeeDoc.info to get a feeling how you can navigate in various ways through your code layers.

In the Example namespace you'll find some classes and mixins that makes absolutely no sense, its purpose is only to show the many features Codo offers.

Installation

Codo is available in NPM and can be installed with:

m install -g codo

Please have a look at the CHANGELOG when upgrading to a newer Codo version with npm update.

Tags

You have to annotate your code with Codo tags to give it some meaning to the parser that generates the documentation. Each tag starts with the @ sign followed by the tag name. See the following overview for a minimal description of all available tags. Most tags are self-explaining and the one that aren't are described afterwards in more detail.

Tags can take multiple lines, just indent subsequent lines by two spaces.

Overview

The following table shows the list of all available tags in alphabetical order with its expected options. An option in parenthesis is optional and the square brackets are part of the Codo tag format and must actually be written. Some tags can be defined multiple times and they can be applied to different contexts, either in the comment for a class, a comment for a mixin or in a method comment.

Tag format Multiple occurrences Classes Mixins Methods
@namespace namespace
@abstract (message)
@author name
@concern mixin
@copyright name
@deprecated
@example (title)
  Code
@extend mixin
@include mixin
@note message
@method signature
  Method tags
@mixin
@option option [type] name description
@event name [description]
  Event tags
@overload signature
  Method tags
@param [type] name description
@param name [type] description
@private
@property [type] description
@return [type] description
@see link/reference
@since version
@throw message
@todo message
@version version
@nodoc
Alternative syntax

You can also use curly braces instead of square brackets if you prefer:

ve the animal.

xample Move an animal
new Lion('Simba').move('south', 12)

aram {Object} options the moving options
ption options {String} direction the moving direction
ption options {Number} speed the speed in mph

: (options = {}) ->

It's also possible to use CoffeeScript block comments instead of the normal comments. If you solely use block comments, you may want to use the --cautious flag to disable the internal comment conversion.


 the animal.

mple Move an animal
w Lion('Simba').move('south', 12)

am [Object] options the moving options
ion options [String] direction the moving direction
ion options [Number] speed the speed in mph

: (options = {}) ->

If you want to compile your JavaScript with Google Closure and make use of the special block comments with an asterisk, you want to use the --closure flag so that Codo ignores the asterisk.

Parameters

There are two different format recognized for your parameters, so you can chose your favorite. This one is with the parameter after the parameter type:

ed the animal

aram [World.Food] food the food to eat
aram [Object] options the feeding options
ption options [String] time the time to feed

: (food) ->

And this one with the name before the type:

ed the animal

aram food [World.Food] the food to eat
aram options [Object] the feeding options
ption options time [String] the time to feed

: (food) ->

The parameter type can contain multiple comma separated types:

ed the animal

aram [String, Char] input
eturn [Integer, Float] output

(input) ->

Each known type will be automatically linked. Also named parameters are recognized:

s Classmate

@param {string} name Full name (first + last)
@param {string} phone Phone number
@param {obj} picture JPG of the person
nstructor: ( {@name, @phone, picture} ) ->

@param {string} reason Why I'm no longer friends
@param {Date} revisit_decision_on When to reconsider
friend: ( {reason, revisit_decision_on} ) ->
Options

If you have an object as parameter and you like to define the accepted properties as options to the method, you can use the @options tag:

ed the animal

aram [Object] options the calculation options
ption options [Integer] age the age of the animal
ption options [Integer] weight the weight of the animal

ctationOfLife: (options) ->

The first parameter to the option tag is the parameter name it describes, followed by the parameter type, name and description.

Types

The object types for the @param, @option and @return tags are parsed for known classes or mixins and linked. You can also define types for Arrays with:


aram [World.Region] region the region of the herd
eturn [Array<Animals>] the animals in the herd

erdMembers: (regions) ->
Properties

You can mark an instance variable as property of the class by using the @property tag like:

s Person

@property [Array<String>] the nicknames
cknames: []

In addition, the following properties pattern is detected:

s Person

t = (props) => @::__defineGetter__ name, getter for name, getter of props
t = (props) => @::__defineSetter__ name, setter for name, setter of props

@property [String] The person name
t name: -> @_name
t name: (@_name) ->

The persons age
t age: -> @_age

If you follow this convention, they will be shown in the generated documentation with its read/write status shown. To specify type of the property, use the @property tag.

Method overloading

If you allow your method to take different parameters, you can describe the method overloading with the @overload tag:

is is a generic Store set method.

verload set(key, value)
Sets a value on key
@param [Symbol] key describe key param
@param [Object] value describe value param

verload set(value)
Sets a value on the default key `:foo`
@param [Object] value describe value param
@return [Boolean] true when success

 (args...) ->

The @overload tag must be followed by the alternative method signature that will appear in the documentation, followed by any method tag indented by two spaces.

Virtual methods

If you copy over functions from other objects without using mixins or concerns, you can add documentation for this virtual (or dynamic) method with the @method tag:

is class has a virtual method, that doesn't
ist in the source but appears in the documentation.

ethod #set(key, value)
Sets a value on key
@param [Symbol] key describe key param
@param [Object] value describe value param

s VirtualMethods

The @method tag must be followed by the method signature that will appear in the documentation, followed by any method tag indented by two spaces. The difference to the @overload tag beside the different context is that the signature should contain either the instance prefix # or the class prefix ..

Mixins

It's common practice to mix in objects to share common logic when inheritance is not suited. You can read more about mixins in the The Little Book on CoffeeScript.

Simply mark any plain CoffeeScript object with the @mixin tag to have a mixin page generated that supports many tags:

eed calculation for animal.

ixin
uthor Rockstar Ninja

ple.Animal.Speed =

Get the distance the animal will put back in a certain time.

@param [Integer] time Number of seconds
@return [Integer] The distance in miles

stance: (time) ->

Next mark the target object that includes one or multiple mixins:

nclude Example.Animal.Speed
s Example.Animal.Lion

and you'll see the mixin methods appear as instance methods in the lion class documentation. You can also extend a mixin:

xtend Example.Animal.Speed
s Example.Animal.Lion

so its methods will show up as class methods.

Concerns

A concern is a combination of two mixins, one for instance methods and the other for class methods and it's automatically detected when a mixin has both a ClassMethods and an InstanceMethods property:

eed calculations for animal.

ixin
uthor Rockstar Ninja

ple.Animal.Speed =

stanceMethods:

# Get the distance the animal will put back in a certain time.
#
# @param [Integer] time Number of seconds
# @return [Integer] The distance in miles
#
distance: (time) ->

assMethods:

# Get the common speed of the animal in MPH.
#
# @param [Integer] age The age of the animal
# @return [Integer] The speed in MPH
#
speed: (age) ->

You can use @concern to include and extend the correspondent properties:

oncern Example.Animal.Speed
s Example.Animal.Lion
Non-class methods and variables

You can also document your non-class, top level functions and constants within a file. As soon Codo detects these types within a file, it will be added to the file list and you can browse your file methods and constants.

Text processing
GitHub Flavored Markdown

Codo class, mixin and method documentation and extra files written in Markdown syntax are rendered as full GitHub Flavored Markdown.

The @return, @param, @option, @see, @author, @copyright, @note, @todo, @since, @version and @deprecated tags rendered with a limited Markdown syntax, which means that only inline elements will be returned.

Automatically link references

Codo comments and all tag texts will be parsed for references to other classes, methods and mixins, and are automatically linked. The reference searching will not take place within code blocks, thus you can avoid reference searching errors by surround your code block that contains curly braces with backticks.

There are several ways of link types supported and all can take an optional label after the link.

The @see tag supports the same link types, just without the curly braces:

 http://en.wikipedia.org/wiki/Lion The wikipedia page about lions
Generate

After the installation you will have a codo binary that can be used to generate the documentation recursively for all CoffeeScript files within a directory.

do --help
e: codo [options] [source_files [- extra_files]]

ons:
help, -h          Show this help                          
version           Show version                            
extension, -x     Coffee files extension                                 [default: "coffee"]
output, -o        The output directory                                   [default: "./doc"]
min-coverage, -m  Require a minimum percentage to be documented or fail  [default: 0]
test, -t          Do not create any output files. Use with min-coverage  [default: 0]
theme             The theme to be used                                   [default: "default"]
name, -n          The project name used                   
readme, -r        The readme file used                    
quiet, -q         Supress warnings                                       [default: false]
verbose, -v       Show parsing errors                                    [default: false]
undocumented, -u  List undocumented objects                              [default: false]
closure           Try to parse closure-like block comments               [default: false]
private, -p       Show privates                                          [default: false]
analytics, -a     The Google analytics ID                                [default: false]
title, -t         HTML Title                                             [default: "Codo Documentation"]

Codo wants to be smart and tries to detect the best default settings for the sources, the readme, the extra files and the project name, so the above defaults may be different on your project.

Project defaults

You can define your project defaults by writing your command line options to a .codoopts file:

me       "Codo"
adme     README.md
tle      "Codo Documentation"
ivate
iet
tension  coffee
tput     ./doc
c

NSE
GELOG.md

Put each option flag on a separate line, followed by the source directories or files, and optionally any extra file that should be included into the documentation separated by a dash (-). If your extra file has the extension .md, it'll be rendered as Markdown.

Keyboard navigation

You can quickly search and jump through the documentation by using the fuzzy finder dialog:

In frame mode you can toggle the list naviation frame on the left side:

You can focus a list in frame mode or toggle a tab in frameless mode:

You can focus and blur the search input:

In frameless mode you can close the list tab:

Report issues

Issues hosted at GitHub Issues.

The Codo specs are template based, so make sure you provide a code snippet that can be added as failing spec to the project when reporting an issue with parsing your CoffeeScript code. The other thing that might be useful is the actual exception happening (run with -d).

Development

Source hosted at GitHub.

Pull requests are very welcome! Please try to follow these simple rules if applicable:

Alternatives
Core Team
Acknowledgment
License

(The MIT License)

Copyright (c) 2012-2016 Michael Kessler, Boris Staal

Template components are derivative works of YARD (http://yardoc.org)
Copyright (c) Loren Segal and licensed under the MIT license

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Bitdeli Badge


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.