![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
grunt-nunjucks-2-html
Advanced tools
If you haven't used Grunt before, be sure to check out the Getting Started guide.
Once plugin has been installed include it in your Gruntfile.js
grunt.loadNpmTasks('grunt-nunjucks-2-html');
Task targets and options may be specified according to the grunt Configuring tasks guide.
nunjucks: {
options: {
data: grunt.file.readJSON('data.json'),
paths: 'templates'
},
render: {
files: {
'index.html' : ['index.html']
}
}
}
templates/index.html
(relative to the gruntfile) is now compiled with data.json
!
nunjucks: {
options: {
data: grunt.file.readJSON('data.json')
},
render: {
files: [
{
expand: true,
cwd: "bundles/",
src: "*.html",
dest: "build/",
ext: ".html"
}
]
}
}
You'll get a set of html files in build
folder.
$ npm test
Read JSON from file using grunt.file.readJSON
or specify object just inside your Gruntfile
.
You should specify a function to construct each data object for every of your templates. Execution context for the function would be a grunt file object. If you specify a data option it would be passed inside the function as an argument.
For instance, you could include name of the file inside an every data object
nunjucks: {
options: {
preprocessData: function(data) {
var page = require('path').basename(this.src[0], '.html');
var result = {
page: page,
data: data
};
return result;
},
data: grunt.file.readJSON('data.json')
},
render: {
files: [
{
expand: true,
cwd: "bundles/",
src: "*.html",
dest: "build/",
ext: ".html"
}
]
}
}
You could specify root path for your templates, paths
would be set for nunjucks' configure
You could use nunjucks' environment API to set some global options. Use configureEnvironment
function the same way as preprocessData
.
As the second argument for the function you have nunjucks` instance, so you can do some extra work before rendering. For instance, you can pre-render some string in custom filter or extension.
nunjucks: {
options: {
configureEnvironment: function(env, nunjucks) {
// for instance, let's set a global variable across all templates
env.addGlobal('foo', 'bar');
}
},
render: {
files: [
{
expand: true,
cwd: "bundles/",
src: "*.html",
dest: "build/",
ext: ".html"
}
]
}
}
Check out nunjucks' API to know a list of available methods for environment object.
You can use nunjucks' configure API as options for plugin.
If you want different tokens than {{ and the rest for variables, blocks, and comments, you can specify different tokens as the tags option:
nunjucks: {
options: {
tags: {
blockStart: '<%',
blockEnd: '%>',
variableStart: '<$',
variableEnd: '$>',
commentStart: '<#',
commentEnd: '#>'
},
data: grunt.file.readJSON('data.json')
},
render: {
files: [
{
expand: true,
cwd: "bundles/",
src: "*.html",
dest: "build/",
ext: ".html"
}
]
}
}
By default, nunjucks escapes all output. Details
Throw errors when outputting a null/undefined value
Automatically remove trailing newlines from a block/tag
Automatically remove leading whitespace from a block/tag
FAQs
Grunt task for rendering nunjucks` templates to HTML
The npm package grunt-nunjucks-2-html receives a total of 71 weekly downloads. As such, grunt-nunjucks-2-html popularity was classified as not popular.
We found that grunt-nunjucks-2-html demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.