1. pug-code-gen
Default code-generator for pug. It generates HTML via a JavaScript template function.
pug-code-gen
Package: pug-code-gen
Created by: pugjs
Last modified: Sat, 25 Jun 2022 00:01:40 GMT
Version: 2.0.3
License: MIT
Downloads: 6,773,273
Repository: https://github.com/pugjs/pug/tree/master/packages/pug-code-gen

Install

npm install pug-code-gen
yarn add pug-code-gen

pug-code-gen

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

Dependencies Status
npm version

Installation

npm install pug-code-gen

Usage

 var generateCode = require('pug-code-gen');

generateCode(ast, options)

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 false
  • compileDebug (boolean): default is true
  • doctype (string): default is undefined
  • inlineRuntimeFunctions (boolean): default is false
  • globals (array of strings): default is []
  • self (boolean): default is false

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
  • templateName (string): the name of the generated function; default is 'template'
 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<p>Hello world!</p>'

new generateCode.CodeGenerator(ast, options)

The constructor for the internal class of the code generator. You shouldn't need to use this for most purposes.

License

MIT

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin