https://github.com/pacexy/ninjacks
A simple wrapper for nunjucks.
https://github.com/pacexy/ninjacks
Last synced: about 2 months ago
JSON representation
A simple wrapper for nunjucks.
- Host: GitHub
- URL: https://github.com/pacexy/ninjacks
- Owner: pacexy
- License: mit
- Created: 2020-10-24T17:09:47.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2020-10-29T15:34:10.000Z (over 5 years ago)
- Last Synced: 2026-02-10T10:14:22.699Z (4 months ago)
- Language: TypeScript
- Size: 21.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ninjacks
A simple wrapper for nunjucks.
## Usage
```typescript
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`.
```typescript
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.
```typescript
env.renderFile(
templateName: string,
outputPath: string,
context?: object
)
```
## Prettier
The default prettierrc is
```typescript
{
singleQuote: true,
semi: false,
htmlWhitespaceSensitivity: 'ignore',
trailingComma: 'all',
}
```
You can specify a parser in `prettierrc`.
```typescript
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
})
```