0.0.1 • Published 4 years ago

ninjacks v0.0.1

Weekly downloads
5
License
MIT
Repository
github
Last release
4 years ago

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
})