Skip to content

pacexy/ninjacks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ninjacks

A simple wrapper for nunjucks.

Usage

import ninjacks from 'ninjacks'

const env = ninjacks.configure({
  templatesPath: 'your-templates-path',
})

env.renderFile('your-template-name', 'your-output-path', context)

APIs

configure

configure method is wrapped and will return an Environment.

ninjacks.configure(configuration: Configuration): Environment

interface Configuration {
  templatesPath?: string | string[]
  options?: nunjucks.ConfigureOptions
  prettierrc?: prettier.Options | null
}

Environment

Environment extends the raw nunjucks.Environment with a renderFile method who can render, format (with prettier), and write.

env.renderFile(
  templateName: string,
  outputPath: string,
  context?: object
)

Prettier

The default prettierrc is

{
  singleQuote: true,
  semi: false,
  htmlWhitespaceSensitivity: 'ignore',
  trailingComma: 'all',
}

You can specify a parser in prettierrc.

import ninjacks, { defaultPrettierrc } from 'ninjacks'

const env = ninjacks.configure({
  templatesPath: 'your-templates-path',
  // This will override the default prettierrc.
  prettierrc: { parser: 'html' },
  // If you don't want this, import the default prettierrc and use it.
  prettierrc: { ...defaultPrettierrc, parser: 'html' },
  // Also, you can disable prettier.
  prettierrc: null
})

About

A simple wrapper for nunjucks.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published