You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

pug-code-gen

Package Overview
Dependencies
Maintainers
2
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pug-code-gen

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


Version published
Weekly downloads
1.5M
decreased by-1.52%
Maintainers
2
Install size
5.36 MB
Created
Weekly downloads
 

Package description

What is pug-code-gen?

The pug-code-gen package is a part of the Pug templating engine ecosystem. It is responsible for generating JavaScript code from Pug templates. This package is typically used internally by the Pug compiler to convert Pug syntax into executable JavaScript functions.

What are pug-code-gen's main functionalities?

Generate JavaScript Code from Pug Templates

This feature allows you to generate JavaScript code from a Pug template's Abstract Syntax Tree (AST). The generated code can then be executed to render HTML.

const pugCodeGen = require('pug-code-gen');
const ast = { /* Abstract Syntax Tree of a Pug template */ };
const options = { /* options for code generation */ };
const jsCode = pugCodeGen(ast, options);
console.log(jsCode);

Custom Code Generation Options

This feature allows you to customize the code generation process by providing various options such as disabling debug information or formatting the output code to be more readable.

const pugCodeGen = require('pug-code-gen');
const ast = { /* Abstract Syntax Tree of a Pug template */ };
const options = { compileDebug: false, pretty: true };
const jsCode = pugCodeGen(ast, options);
console.log(jsCode);

Other packages similar to pug-code-gen

Readme

Source

pug-code-gen

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

Build Status Dependency 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 false
  • 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 generateCode = require('pug-code-gen');

var funcStr = generateCode(parse(lex('p Hello world!')), {
  compileDebug: false,
  pretty: true,
  inlineRuntimeFunctions: false,
  templateName: 'helloWorld'
});

var func = Function('locals', funcStr);
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

Keywords

FAQs

Package last updated on 15 Mar 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc