Skip to content

Commit

Permalink
getNodes and getFullName moved to helpers.coffee
Browse files Browse the repository at this point in the history
  • Loading branch information
Omar Khan committed Aug 4, 2011
1 parent 9ef1500 commit cc83ab7
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 54 deletions.
38 changes: 5 additions & 33 deletions lib/coffeedoc.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/docgen.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions lib/helpers.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 4 additions & 21 deletions src/coffeedoc.coffee
@@ -1,11 +1,14 @@
###
Documentation functions
=======================
These functions extract relevant documentation info from AST nodes as returned
by the coffeescript parser.
###

coffeescript = require('coffee-script')
helpers = require(__dirname + '/helpers')
getNodes = helpers.getNodes
getFullName = helpers.getFullName

exports.documentModule = (script, parser) ->
###
Expand Down Expand Up @@ -35,26 +38,6 @@ exports.documentModule = (script, parser) ->

return doc

getNodes = (script) ->
###
Generates the AST from coffeescript source code. Adds a 'type' attribute
to each node containing the name of the node's constructor, and returns
the expressions array
###
root_node = coffeescript.nodes(script)
root_node.traverseChildren false, (node) ->
node.type = node.constructor.name
return root_node.expressions

getFullName = (variable) ->
###
Given a variable node, returns its full name
###
name = variable.base.value
if variable.properties.length > 0
name += '.' + (p.name.value for p in variable.properties).join('.')
return name

documentClass = (cls) ->
###
Evaluates a class object as returned by the coffeescript parser, returning
Expand Down
1 change: 1 addition & 0 deletions src/docgen.coffee
@@ -1,6 +1,7 @@
###
Documentation generator
=======================
This script generates html documentation from a coffeescript source file
###

Expand Down
29 changes: 29 additions & 0 deletions src/helpers.coffee
@@ -0,0 +1,29 @@
###
AST helper functions
====================
Useful functions for dealing with the CoffeeScript parse tree.
###

coffeescript = require('coffee-script')

exports.getNodes = (script) ->
###
Generates the AST from coffeescript source code. Adds a 'type' attribute
to each node containing the name of the node's constructor, and returns
the expressions array
###
root_node = coffeescript.nodes(script)
root_node.traverseChildren false, (node) ->
node.type = node.constructor.name
return root_node.expressions

exports.getFullName = (variable) ->
###
Given a variable node, returns its full name
###
name = variable.base.value
if variable.properties.length > 0
name += '.' + (p.name.value for p in variable.properties).join('.')
return name

0 comments on commit cc83ab7

Please sign in to comment.