Classes and Functions inside a top-level function won't be parsed
Cybolic opened this issue · 5 comments
I'm writing my code using a namespacing convention, meaning all my files start with something like namespace 'ModuleName', ->
and that seems to be causing CoffeeDoc to ignore the entire file.
Is there any way to get CoffeeDoc to just ignore the namespace
function?
For now coffeedoc only documents top-level functions and classes in a file, at least when the commonjs parser is used. The reasoning is that nested functions and classes do not generally form part of the API, and do not need to be documented in the same way. Of course if you nest everything in a top-level function it won't work.
This should be easy to fix though, just write a custom Parser
class that knows where to look in the coffeescript AST. Have a look at how the requirejs parser is written, it does something similar. Shout if you get stuck
I'm with @Cybolic.
We too use namespacing for our api, and we're doing it like this (using underscore.js):
_.extend nsName, varOne: "a value" methodOne: -> ...
I understand that this can be manually done by extending the BaseParser ourselves, but that requires to get to know your code, and since it's reasonable to put your api into a namespace, maybe it's worth to add this as a feature as well?
I appreciate that lots of people use namespacing as a way to write modular code, but it would be quite tricky to write a generic parser that could handle all namespacing techniques. Some people put everything in a top-level object, other people attach public properties to a named wrapper function using this
, @nitm uses underscore... the possibilities are endless. How does coffeedoc know where to look in the general case?
If someone can hack something together I'm happy to merge it in, but it seems like a lot of work, especially when you can just use commonjs/requirejs and have everything just work.
I was actually looking at doing that before posting here, by simply copying the require class and replace all the "require" strings with "namespace", but that didn't work and I didn't have the time to look into it further.
I'm guessing the problem of where to look can be solved by having a --namespace argument that takes a parameter which is the name of the function to look for?
I already forked the project, and will hopefully have enough time to make it work for what I need, then I'll try to tackle the generic issue.
Thanks for the great project.