Git Product home page Git Product logo

jstransformer-nunjucks's Introduction

jstransformer-nunjucks

Nunjucks support for JSTransformers.

Build Status Coverage Status NPM version

Installation

npm install jstransformer-nunjucks

API

const jstransformer = require('jstransformer')
const nunjucks = jstransformer(require('jstransformer-nunjucks'))

nunjucks.render('Hello, {{ name }}!', {name: 'World'}).body
//=> 'Hello, World!'

const options = {
  filters: { repeat: (str, num) => str.repeat(n || 2) }
};

nunjucks.render(
  '{{ "Hello, " | repeat(echoes + 1) }}{{ name }}!',
  options,
  {name: 'World', echoes: 2}
).body

//=> 'Hello, Hello, Hello, World!'

See the JSTransformers documentation for other API methods.

By default, this transformer matches the .njk and .nunjucks input file extensions, and outputs .html.

Available options

Many of the API methods accept an options dictionary object. The following option keys are supported:

  • filename: The filename and path of the Nunjucks template being compiled. Default is null, which disables any imports or includes using relative path names.

  • root: The base path used to configure the Nunjucks environment. This defines the highest-level directory that can be searched for templates and macros. Any import or include references to files outside this root directory will fail. Default is to use the parent directory of the filename path, if it is specified, or null (which causes Nunjucks to default to the current working directory).

  • path: Alternative name for root.

  • filters: A set of custom Nunjucks filters to add. The value of filters should be a dictionary object where the keys are the filter names to use in the templates. The dictionary values define the filter functions, either as JavaScript function objects, or as the name of a Node module (as a string). If you specify a module name, that module's default export will be used as the filter function.

  • extensions: A set of Nunjucks extensions to add. The value of extensions should be a dictionary object where the keys are the extension names to use in the templates. The dictionary values define the extension functions, either as JavaScript function objects, or as the name of a Node module (as a string).

  • globals: A set of global variables available to all templates. The value of globals is a dictionary object defining the keys and values of the global data properties.

  • Any other options supported by Nunjuck's configure method.

License

MIT

jstransformer-nunjucks's People

Contributors

36degrees avatar ameliabr avatar bashaus avatar calebeby avatar forbeslindesay avatar gijswijs avatar greenkeeper[bot] avatar greenkeeperio-bot avatar hemanth avatar robloach avatar timothygu avatar tunnckocore avatar webketje avatar wernerglinka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

jstransformer-nunjucks's Issues

An in-range update of xo is breaking the build 🚨

The devDependency xo was updated from 0.25.4 to 0.26.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

xo is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Release Notes for v0.26.0

Breaking

  • Require Node.js 10 d7fa875
  • Move $ xo --init to $ npm init xo 6463dfe

New rules

20 new rules πŸ‘Œ

ESLint
Unicorn
Other

Enhancements

Fixes

  • Fix compatibility with being run in a child process (#405) 08af7c1

v0.25.3...v0.26.0

Commits

The new version differs by 10 commits ahead by 10, behind by 2.

  • c2bb1bf 0.26.0
  • eb5ea2c Set the es2020 environment by default
  • 08af7c1 Fix compatibility with being run in a child process (#405)
  • d7fa875 Require Node.js 10
  • ab3e01a Temporarily disable the import/order rule
  • c50eaf0 Add some overrides to unicorn/prevent-abbreviations
  • e8c43d2 Replace destructing import with one-by-one import (#417)
  • 5cddaec Replace singular Lodash packages with the main one (#413)
  • 1fdc2f9 Fix Node.js range for prefer-object-spread rule (#408)
  • 6463dfe Move xo --init to npm init xo

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of test-jstransformer is breaking the build 🚨

The devDependency test-jstransformer was updated from 1.0.2 to 1.0.3.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

test-jstransformer is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Commits

The new version differs by 9 commits.

  • cb7fe6f 1.0.3
  • 47f61e7 Merge pull request #37 from jstransformers/travis-10-11
  • 612b98d travis: Add Node.js 10 and 11 to Travis
  • ef34b50 Merge pull request #36 from jstransformers/update
  • e907f32 Fix travis
  • 5c8c10f Update xo
  • 9708aac Update dependencies
  • 3c92d41 Merge pull request #33 from jstransformers/node-9
  • d1520b3 Add Node 9 to Travis testing

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Pull Requests

@tunnckoCore If you're suggesting changes, then it is usually best to work with the rest of the team through the use of Pull Requests.

I've put some comments inline on your comments, and opened this issue to track those requests.

Those are at:

An in-range update of xo is breaking the build 🚨

The devDependency xo was updated from 0.24.0 to 0.25.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

xo is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Commits

The new version differs by 27 commits.

  • 1c8e762 0.25.0
  • 042b726 Disable some problematic rules
  • 97e32b9 Upgrade dependencies
  • 5cde9aa Fix lint test error on Windows (#401)
  • f6bf4c0 Respect .eslintignore (#377)
  • 05c30e2 Disable the unicorn/prevent-abbreviations rule temporarily
  • 97aa2b0 Upgrade dependencies
  • ee145cb Disable the import/named rule for now
  • 03daca9 Minor code refactor (#397)
  • d09f87c Readme tweaks
  • c55f962 Make the unicorn/prevent-abbreviations rule less strict
  • 8a213ef Require Node.js 8
  • 4f50816 Lint fixes
  • 8d6c5c5 Add option to import/no-useless-path-segments rule
  • 77e9e93 Update eslint-plugin-unicorn

There are 27 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of test-jstransformer is breaking the build 🚨


☝️ Important announcement: Greenkeeper will be saying goodbye πŸ‘‹ and passing the torch to Snyk on June 3rd, 2020! Find out how to migrate to Snyk and more at greenkeeper.io


The devDependency test-jstransformer was updated from 1.0.3 to 1.1.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

test-jstransformer is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Commits

The new version differs by 13 commits.

  • 2723095 Merge pull request #46 from jstransformers/update
  • 70c2ea4 Update coverage with nyc
  • a0ffefe Merge pull request #42 from YasharF/master
  • e1312b4 Merge pull request #43 from YasharF/patch-1
  • cb1b686 Merge pull request #44 from YasharF/patch-2
  • 2f5ed58 fix: Use current versions of NodeJS for builds
  • 79edecc fix: david-dm badge
  • fa8f33a Migrate from istanbul to nyc
  • e18ae8a Merge pull request #41 from jstransformers/travis
  • 2d56348 Update travis
  • 17096c3 Fix xo
  • 7393c7e Merge pull request #39 from jstransformers/greenkeeper/foreground-child-2.0.0
  • 80a9c6b fix(package): update foreground-child to version 2.0.0

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of xo is breaking the build 🚨

Version 0.21.0 of xo was just published.

Branch Build failing 🚨
Dependency xo
Current Version 0.20.3
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

xo is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details

Release Notes v0.21.0

Highlights

New rules

Removed rules

Commits

The new version differs by 8 commits.

  • b633e92 Do not override default options with absent CLI flags (#316)
  • cec0853 Update plugins and add some new rules
  • d1eb47c Require Node.js 6
  • 6254110 GitHub now natively supports SVG
  • 4fd6991 Disable number-literal-case rule when using Prettier (#311)
  • 7190640 Remove import/prefer-default-export rule
  • f67ff58 Default Prettier trailingComma conf to none (#305)
  • 11c35c8 Upgrade prettier to last version (#306)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Include only works for file at the same level or below

See this test repo: https://github.com/ismay/nunjucks-include

Running node index.js:

// Deps
var nunjucks = require('jstransformer')(require('jstransformer-nunjucks'));
var fs = require('fs');
var path = require('path');

// Render
function render (file) {
  var filename = path.join(__dirname, file);
  var contents = fs.readFileSync(filename).toString();
  var locals = null;
  var options = { filename: filename };

  return nunjucks.render(contents, options, locals).body;
}

// Outcome
console.log(render('src/include-sibling.nunjucks'));
console.log(render('src/include-child.nunjucks'));
console.log(render('src/include-parent.nunjucks'));

Demonstrates how includes work for files on the same level, or below it, but fail for includes of files located above the parent. It fails with the following error:

Template render error: (/Users/ismay/Projects/nunjucks/src/include-parent.nunjucks)
  Template render error: (/Users/ismay/Projects/nunjucks/src/include-parent.nunjucks)
  Error: template not found: /Users/ismay/Projects/nunjucks/lib/include.html
    at Object.exports.prettifyError (/Users/ismay/Projects/nunjucks/node_modules/jstransformer-nunjucks/node_modules/nunjucks/src/lib.js:34:15)
    at /Users/ismay/Projects/nunjucks/node_modules/jstransformer-nunjucks/node_modules/nunjucks/src/environment.js:485:31
    at root [as rootRenderFunc] (eval at <anonymous> (/Users/ismay/Projects/nunjucks/node_modules/jstransformer-nunjucks/node_modules/nunjucks/src/environment.js:564:24), <anonymous>:21:3)
    at Obj.extend.render (/Users/ismay/Projects/nunjucks/node_modules/jstransformer-nunjucks/node_modules/nunjucks/src/environment.js:478:15)
    at Transformer.render (/Users/ismay/Projects/nunjucks/node_modules/jstransformer/index.js:289:25)
    at render (/Users/ismay/Projects/nunjucks/index.js:13:19)
    at Object.<anonymous> (/Users/ismay/Projects/nunjucks/index.js:19:13)
    at Module._compile (module.js:435:26)
    at Object.Module._extensions..js (module.js:442:10)
    at Module.load (module.js:356:32)

Could not find anything in the nunjucks' documentation indicating that this should not work. Any idea whether this is related to this lib, or is it nunjucks related?

The weird thing is that the path in the error Error: template not found: /Users/ismay/Projects/nunjucks/lib/include.html exists..

An in-range update of nunjucks is breaking the build 🚨

Version 3.1.3 of nunjucks was just published.

Branch Build failing 🚨
Dependency nunjucks
Current Version 3.1.2
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

nunjucks is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details

Release Notes v3.1.3
  • Add forceescape filter. Fixes #782

  • Fix regression that prevented template errors from reporting line and column number. Fixes #1087 and #1095.

  • Fix "Invalid type: Is" error for {% if value is defined %}. Fixes #1110

  • Formally drop support for node v4 (the upgrade to babel 7 in v3.1.0 made the build process incompatible with node < 6.9.0).

Commits

The new version differs by 15 commits.

  • 9a0ce36 3.13 release - fix typo in CHANGELOG
  • c2de0e4 Release 3.1.3
  • 4d8a4cc Update chokidar optionalDependency. Fixes #1103
  • d140280 Update CONTRIBUTING.md to reflect supported node releases [ci skip]
  • af6427d Update CHANGELOG
  • 1b76fb8 Update package.json engines to reflect supported node versions
  • 8afacce Add unit tests for {% if x is [not] defined %}. refs #1110
  • 248cf56 Fix "Invalid type: Is" error when using {% if x is defined %}
  • 2eaea16 Drop node v4 support, add node v9
  • 8041120 Include file/lineno in TemplateError message. fixes #1087, #1095
  • 1b4558d Merge pull request #1090 from TheDancingCode/forceescape
  • f478b06 Add "forceescape" filter
  • de49d33 Merge pull request #1089 from gingerrific/master
  • 3ab849c Update remaining src links
  • dedb978 Update API.md links to use correct paths

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Incompatible with sharp module

This module seems incompatible with sharp.

Using Node 12.16.3 installing npm install jstransformer-nunjucks (1.0.0) and then

npm install sharp

returns this:

> [email protected] install /Users/js/Downloads/test-sharp/node_modules/fsevents
> node-gyp rebuild

gyp: binding.gyp not found (cwd: /Users/js/Downloads/test-sharp/node_modules/fsevents) while trying to load binding.gyp
gyp ERR! configure error 
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:305:16)
gyp ERR! stack     at ChildProcess.emit (events.js:310:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
gyp ERR! System Darwin 18.7.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/js/Downloads/test-sharp/node_modules/fsevents
gyp ERR! node -v v12.16.3
gyp ERR! node-gyp -v v3.4.0
gyp ERR! not ok 

> [email protected] install /Users/js/Downloads/test-sharp/node_modules/sharp
> (node install/libvips && node install/dll-copy && prebuild-install --runtime=napi) || (node-gyp rebuild && node install/dll-copy)

info sharp Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.9.1/libvips-8.9.1-darwin-x64.tar.gz

Without jstransformer-nunjucks this problem doesn't exist. Is there anything I should do differently?

Thanks.

An in-range update of nunjucks is breaking the build 🚨

The dependency nunjucks was updated from 3.1.3 to 3.1.4.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

nunjucks is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Commits

The new version differs by 7 commits.

  • 11262e5 Release v3.1.4
  • bcd45fc Merge pull request #1165 from stigkj/master
  • 40480f0 Fix engine version for Node v11.1.0
  • 3512ca6 Merge pull request #1161 from jonathanchu/master
  • 9dc07dc Fix dependency version for node v11.0.0
  • 39bb716 Merge pull request #1126 from TheDancingCode/issue-126
  • 4d4dc40 Escape unicode newlines when compiling

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of xo is breaking the build 🚨

The devDependency xo was updated from 0.23.0 to 0.24.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

xo is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Commits

The new version differs by 13 commits.

  • a64ffc4 0.24.0
  • 71ea1e3 Update dependencies
  • 510d02e CI updates (#360)
  • 7017abe Add no-useless-catch rule
  • 0b411fb Add eslint-plugin-eslint-comments ESLint plugin (#359)
  • 3dd8f7e Update readme to match #305 (#357)
  • dd2c015 Drop support for Babel 6 in the import/no-unassigned-import rule
  • 61f9582 Support parsing ES2019
  • 92f2870 Various code style improvements
  • 9e75826 Add some new eslint-plugin-node rules
  • c7054f3 Update dependencies
  • e656fd4 Mention the badgen.net XO badges in the readme
  • d1fd3e1 Move default ESLint cache to node_modules/.cache/xo. (#351)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of nunjucks is breaking the build 🚨


☝️ Important announcement: Greenkeeper will be saying goodbye πŸ‘‹ and passing the torch to Snyk on June 3rd, 2020! Find out how to migrate to Snyk and more at greenkeeper.io


The dependency nunjucks was updated from 3.2.0 to 3.2.1.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

nunjucks is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Commits

The new version differs by 7 commits.

  • 53d1223 Release v3.2.1
  • 93129bf Replace yargs with commander
  • 17691da Chokidar bump
  • 40dfdf0 Remove dead link
  • cefb1cf Prevent optional dependency Chokidar from loading when not watching
  • 1485a44 Add badges in README.md
  • 2246457 Add Mozilla Code of Conduct file

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Error: The Transform "nunjucks" does not support rendering synchronously.

Hi!

I have a very typical nunjucks setup on Metalsmith

I can output variables, and overwrite blocks in child templates:

{% extends "layouts/page.njk" %}

{% block content %}

  child content block

  {{ i18n.heading }}

{% endblock %}

but as soon as I want to do something like:

{% extends "layouts/page.njk" %}

{% block content %}

  child content block

  {{ default(i18n.heading, 'Welcome!') }}

{% endblock %}

I get the following error:

Error: The Transform "nunjucks" does not support rendering synchronously.
    at Transformer.render (/Users/stoaty/Dev/websites/menu-translators/static/node_modules/jstransformer/index.js:291:13)
    at resolve (/Users/stoaty/Dev/websites/menu-translators/static/node_modules/metalsmith-in-place/lib/index.js:60:33)
    at new Promise (<anonymous>)
    at render (/Users/stoaty/Dev/websites/menu-translators/static/node_modules/metalsmith-in-place/lib/index.js:29:10)
    at Promise.all.validFiles.map.filename (/Users/stoaty/Dev/websites/menu-translators/static/node_modules/metalsmith-in-place/lib/index.js:142:7)
    at Array.map (<anonymous>)
    at Ware.<anonymous> (/Users/stoaty/Dev/websites/menu-translators/static/node_modules/metalsmith-in-place/lib/index.js:141:16)
    at Ware.<anonymous> (/Users/stoaty/Dev/websites/menu-translators/static/node_modules/wrap-fn/index.js:45:19)
    at next (/Users/stoaty/Dev/websites/menu-translators/static/node_modules/ware/lib/index.js:85:20)
    at /Users/stoaty/Dev/websites/menu-translators/static/node_modules/wrap-fn/index.js:121:18
error Command failed with exit code 1.

The message is a bit vague to me - I though I was doing things synchronously?

Does anyone have any experience with this error?

I've looked around all afternoon and I can't find much except this SO post:

https://stackoverflow.com/questions/49799507/using-nunjucks-includes-with-metalsmith-in-place-causing-rendering-error

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.