https://github.com/mcasimir/swig-traverse
A Swig plugin providing tags to traverse tree structures.
https://github.com/mcasimir/swig-traverse
Last synced: 2 months ago
JSON representation
A Swig plugin providing tags to traverse tree structures.
- Host: GitHub
- URL: https://github.com/mcasimir/swig-traverse
- Owner: mcasimir
- License: mit
- Created: 2015-01-08T14:00:27.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-01-15T03:00:18.000Z (over 10 years ago)
- Last Synced: 2025-03-03T07:22:36.502Z (3 months ago)
- Language: JavaScript
- Size: 129 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# swig-traverse
A [Swig](http://paularmstrong.github.io/swig/) plugin providing tags to traverse tree structures.
**swig-traverse** assumes tree nodes to be objects with a `children` property that
is either `undefined` or an array of child nodes.``` js
var tree = {
// ...
children: [
{
// ...
children: [
// ...
]
}
]
};
```## Install
``` sh
npm i swig-traverse --save-dev
```## Usage
``` js
var swig = require('swig'),
swigTraverse = require('swig-traverse');swigTraverse( swig );
`````` html
{% traverse node in tree -%}
{% postvisit -%}
{% endtraverse -%}
```Note. `{% postvisit %}` section is optional:
``` html
{% traverse node in tree -%}
{% endtraverse -%}
```You can pass array as tree, in that case it will considered to be a _"children"_ array. Useful
to exclude root from traversing:```
{% traverse child in node.children -%}
{% endtraverse -%}
```### Example
``` html
Description:{{ node.description }}
Submodules:
-
{{child.title}}
{% endif -%}
{% postvisit -%}
{% if child.type == 'module' %}
{% traverse child in node.children -%}
{% if child.type == 'module' %}
{% endif -%}
{% endtraverse -%}
```
## License
Released under the [MIT license](https://github.com/mcasimir/swig-traverse/blob/master/LICENSE).