pug-vdom
The pug-vdom can compile a pug template into a render function that
can create a virtual dom tree by using a library such as virtual-dom
Install
npm install pug-vdom
Usage
var pugVDOM =var ast = pugVDOMvar compiler = astvar code = compiler
The code variable contain a render function with this signature:
{return Array ...}
The return value is a list of hyperscript node, the hyperscript function (https://github.com/hyperhype/hyperscript) is the one provided as the second parameter.
An convenient function can be used to compile your pug files into directly usable module
var vDom =vDom
Then typically you can use the resulting file like this
var render = // importing the render function of this templatevar h = // we use virtual hyperscript functionvar diff =var patch =var createElement =//runtime library is required and puts 'pugVDOMRuntime' into the global scope.var tree =var rootNode = // we expect only node at the root from our templatedocument{var newTree =var domDiff =tree = newTree}
If you are using Browserify, a transform is available https://github.com/gryphonmyers/pugvdomify