Class: Traverser
Defined in: | node_modules/grunt-codo/node_modules/codo/lib/traverser.coffee |
Overview
The class takes CS nodes tree and recursively injects additional meta-data into it:
- For each possible node it tries every registered
entity and pushes an instance of it into tree if it suites. 2. For every suitable node it finds the suitable comment block
respecting things like
this.
andmodule.exports =
and links it to the tree as well.
Since the transformation is happening upside down, nested entities can interact with initialized parents (for instance a class can find parent class; method can find the class/mixin/file it belongs to).
Class Method Summary
- . (void) read(file, environment)
- . (void) linkAncestors(node) Attach each parent to its children, so we are able to traverse the ancestor parse tree.
- . (void) convertComments(content, closure = false) Convert the comments to block comments, so they appear in the nodes.
- . (String) whitespace(n) Whitespace helper function
Instance Method Summary
- # (void) prepare(node, file, Entity)
- # (Array<String>) leftTrimBlock(text) Detect whitespace on the left and removes the minimum whitespace ammount.
- # (void) inspect()
Class Method Details
.
(void)
read(file, environment)
.
(void)
linkAncestors(node)
Attach each parent to its children, so we are able
to traverse the ancestor parse tree. Since the
parent attribute is already used in the class node,
the parent is stored as ancestor
.
.
(void)
convertComments(content, closure = false)
Convert the comments to block comments, so they appear in the nodes.
The methods replaces starting # symbols with invisible unicode whitespace to keep empty lines formatted.
.
(String)
whitespace(n)
Whitespace helper function
Constructor Details
#
(void)
constructor(path, content, environment)
Instance Method Details
#
(void)
prepare(node, file, Entity)
#
(Array<String>)
leftTrimBlock(text)
Detect whitespace on the left and removes the minimum whitespace ammount.
The method additionally drops invisible UTF
whitespace introduced by convertComments
This will keep indention for examples intact.
Examples:
left trim all lines
leftTrimBlock(['', ' Escape at maximum speed.', '', ' @param (see #move)', ' '])
=> ['', 'Escape at maximum speed.', '', '@param (see #move)', '']
#
(void)
inspect()