jeremyben / nunjucks-cli Goto Github PK
View Code? Open in Web Editor NEWSimple Nunjucks CLI wrapper and templates watcher
Home Page: https://www.npmjs.com/package/nunjucks-cli
License: MIT License
Simple Nunjucks CLI wrapper and templates watcher
Home Page: https://www.npmjs.com/package/nunjucks-cli
License: MIT License
in watch mode:
when there is a parse error in the njk template, it produces empty output files
the error is not printed to the console
when i fix the error in template, it does not recover from the error
nunjucks-cli refuses to render any files that have the .html
extension to "avoid overwriting your templates". That can only happen if the the rendered files were to be written to the same folder as where the input resides. Often that is not the case, e.g. when specifying the output folder explicitly to be a different one.
Hey,
I'd like to use nunjucks with npm. So I installed nunjucks with:
npm i -g nunjucks-cli
If I try to run nunjucks from commandline with:
nunjucks index.html
or just nunjucks
I get this error:
env: node\r: No such file or directory
Has someone the same issue?
I am running on OSX 10.11.4
I'm not able to make macros and variables work properly in partials that I include.
I have an entry file called index.tpl, this includes a module. Inside this module I want to include a macro, I declare this at the top of the page;
{% include 'macros/content-block.tpl' %}
after which I want to use it
{{ contentblock() }}
Then I get an error that contentblock is undefined or falsy. However if I include and use it on the entry file, it does seem to work. My modules all start with an underscore to prevent them from being rendered, but still watched.
Pls help :)
It seems I'm unable to use macro's that have camelcasing. The below doesn't work. If I change it to all lowercase ('contentblock'), it does work.
{% include 'macros/content-block.tpl' %}
{{ contentBlock() }}
Trying to build a simple test.njk file using npx nunjucks-cli "test.njk" but getting an error about the path
argument being undefined
when it's expecting a string:
npx nunjucks-cli "test.njk"
node:internal/validators:120
throw new ERR_INVALID_ARG_TYPE(name, 'string', value);
^
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
at new NodeError (node:internal/errors:371:5)
at validateString (node:internal/validators:120:11)
at resolve (node:path:1098:7)
at Object.<anonymous> (/private/tmp/11ty-2184/node_modules/nunjucks-cli/main.js:55:18)
at Module._compile (node:internal/modules/cjs/loader:1097:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1149:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47 {
code: 'ERR_INVALID_ARG_TYPE'
}
Node.js v17.3.1
Give it an empty -p
argument:
npx nunjucks-cli "test.njk" -p ""
Rendering: test.njk
I've previously been using Grunt to compile my templates as part of my build process, but now I'd like to move to npm scripts. The documentation for the Nunjucks CLI is limited, and I'm having trouble figuring out how to express my grunt task in the CLI. Here is my Grunt task:
nunjucks: {
options: {
data: grunt.file.readJSON('template-data.json'),
paths: ['', '../templates/']
},
html: {
files: [{
expand: true,
cwd: 'dev/',
src: ['*.html.njk'],
dest: 'dev/',
ext: '.html'
}]
},
scss: {
files: [{
expand: true,
cwd: 'dev/css/',
src: ['*.scss.njk'],
dest: 'dev/css/',
ext: '.scss'
}]
}
},
How can I do the same thing with the Nunjucks CLI?
I've been trying the watch functionality and it seems to be broken a bit. The script seems to cache the initial version of the template files when you first started them, instead of actually refreshing the contents when a change occurred.
I'm using El Capitan and Node v7.2.1
Same rationale as this:
It would be handy if there was a way to expose dynamic properties — like, say, the date or Node.js version — to templates. A common way of achieving this is to load files with a
.js
extension and operate on their default export (i.e. viamodule.exports
). This is done by e.g. jpm and various other tools and libraries.
e.g.:
$ cat context.js
const pkg = require('./package.json')
const year = new Date().getFullYear()
module.exports = { pkg, year }
➜ nunjucks -u -p templates/*.tpl -o rendered
Error: template not found: templates/index.tpl
Files are created and if you can see from error it get's file name as it is - index.tpl, but doesn't work with that
I believe it's path issue or so, because if I wrote just a name of the file it works well, if I wrote path with /
- it throws an error template not found
, if I use *.html
or *.tpl
it throws Unexpected token <
when face first html-tag
The basic examples in the README don't work because the -p
option is apparently required.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.