Default code-generator for pug. It generates HTML via a JavaScript template function.
Default code-generator for pug. It generates HTML via a JavaScript template function.


npm install pug-code-gen
``js`
var generateCode = require('pug-code-gen');
Generate a JavaScript function string for the given AST.
ast is a fully expanded AST for Pug, with all inclusion, extends, and filters resolved.
options may contain the following properties that have the same meaning as the options with the same names in pug:
- pretty (boolean): default is falsetrue
- compileDebug (boolean): default is undefined
- doctype (string): default is false
- inlineRuntimeFunctions (boolean): default is []
- globals (array of strings): default is false
- self (boolean): default is
In addition to above, pug-code-gen has the following unique options:
- includeSources (object): map of filename to source string; used if compileDebug is true; default is undefined'template'
- templateName (string): the name of the generated function; default is
`js
var lex = require('pug-lexer');
var parse = require('pug-parser');
var wrap = require('pug-runtime/wrap');
var generateCode = require('pug-code-gen');
var funcStr = generateCode(parse(lex('p Hello world!')), {
compileDebug: false,
pretty: true,
inlineRuntimeFunctions: false,
templateName: 'helloWorld'
});
//=> 'function helloWorld(locals) { ... }'
var func = wrap(funcStr, 'helloWorld');
func();
//=> '\n
Hello world!
'The constructor for the internal class of the code generator. You shouldn't need to use this for most purposes.
MIT