coffeedoc / codo

CoffeeScript API documentation generator. It's like YARD but for CoffeeScript!
Other
625 stars 92 forks source link

customizing files #173

Closed timaschew closed 10 years ago

timaschew commented 10 years ago

First of all thanks for this great tool :pray:

I want to customize the output for files (non classes). I already debug codo and find out that I have access to the complete syntax tree. So it should possible but I'm not sure where (in which file) and how I should do the modifications to let it be optimal.

I don't found any detailed documentation for that ;)

So I want to generate a documentation for my server.coffee with REST routes. I'm using express an wrap the route definitions into a register function:

express = require('exprss)
app = express()

# @block
register = (app) ->
    # helper
    helper = (param) ->
        foo()

    # rest call1
    # @rest
    # @param {string} firstname
    # @param {string} lastname
    app.get '/bar/:firstname/:lastname', (req, res, next) ->
        bar()

    # rest call2
    # @rest
    app.use '/qux', (req, res, next) ->
        qux()

So @block does look into the value.body of a node (the body of the register function). The helper function is no problem but the rest routes aren't function definitions, just expressions and the comment above each of them is not part of the node.

So my questions are:

  1. Where I should add the @block feature?
  2. How and where I can provide a feature to assign comments for an expression?
inossidabile commented 10 years ago

Codo traverses the tree with the following steps:

  1. It tries to locate all the nodes listed in ./lib/entites. Every file has looksLike method allowing you to describe the node.
  2. Every found node gets checked for the documentation block that afterwards gets parsed with class Documentation.

In your case it's already a defined node Entities.Method. All you have to do is to teach Codo how to parse @block inside of Documentation class.