New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

fly-nunjucks-render

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fly-nunjucks-render - npm Package Compare versions

Comparing version 0.0.0 to 1.0.0

54

index.js

@@ -9,34 +9,40 @@ 'use strict';

var defaults = {
data: {},
dataPath: null,
watch: false
base: '.',
data: {},
dataPath: null
};
module.exports = function () {
var self = this;
self.filter('nunjucks', function (source, options) {
options = assign({}, defaults, options || {});
return self.defer(compile.bind(self))(options);
});
var self = this;
self.filter('nunjucks', function (source, options) {
options = assign({}, defaults, options || {});
return self.defer(compile.bind(self))(source, options);
});
};
function compile(options, cb) {
var self = this;
function compile(src, opts, cb) {
var self = this;
var env = nunjucks.configure(options);
// setup env
nunjucks.configure(opts.base, opts);
// check for a dataPath first, else resort to `options.data`
var data = options.dataPath ? getData(options.dataPath) : options.data;
// check for a dataPath first, else resort to `options.data`
var data = opts.dataPath ? getData(self.root, opts.dataPath) : opts.data;
return self.unwrap(function (files) {
env.render(files, data, function (err, buf) {
if (err) {
return self.emit('plugin_error', {
plugin: 'fly-nunjucks',
error: err.message
});
}
cb(null, buf.toString());
});
})
// render single file
return nunjucks.renderString(src.toString(), data, function (err, buf) {
if (err) {
return self.emit('plugin_error', {
plugin: 'fly-nunjucks-render',
error: err.message
});
}
cb(null, buf.toString());
});
}
function getData(dir, file) {
file = path.resolve(dir, file);
return JSON.parse(fs.readFileSync(file, 'utf8'));
}
{
"name": "fly-nunjucks-render",
"version": "0.0.0",
"description": "Use the Nunjucks templating engine with Fly!",
"version": "1.0.0",
"description": "Render Nunjucks templates with Fly!",
"license": "MIT",
"repository": "https://github.com/lukeed/fly-nunjucks",
"repository": "https://github.com/lukeed/fly-nunjucks-render",
"main": "index.js",

@@ -14,11 +14,9 @@ "files": [

"fly-plugin",
"nunjucks"
"nunjucks",
"template",
"html"
],
"scripts": {
"setup": "npm i && npm test",
"spec": "npm run test | tspec",
"test": "npm run tape",
"build": "echo No build task specified.",
"deploy": "npm run test && git push origin master && npm publish",
"tape": "node --harmony --harmony_arrow_functions ./node_modules/tape/bin/tape test/*.js"
"test": "xo",
"build": "echo No build task specified."
},

@@ -35,4 +33,3 @@ "author": {

"devDependencies": {
"tap-spec": "^4.1.1",
"tape": "^4.2.2"
"xo": "*"
},

@@ -39,0 +36,0 @@ "engines": {

@@ -24,3 +24,2 @@ <div align="center">

### Example
```js

@@ -30,2 +29,3 @@ export default function* () {

.nunjucks({
base: 'src/partials',
data: {name: 'Luke Edwards'},

@@ -39,2 +39,29 @@ // or

```html
<p>Hello, {{ name }}!</p>
```
## API
#### base
Type: `string`<br>
Default: *`.`, the current working directory*
Tells _nunjucks_ where your templates live.
#### data
Type: `object`<br>
Default: *`{}`, optional*
Context data that are passed to your view templates.
#### dataPath
Type: `string`<br>
Default: *`null`, optional*
Same as `options.data`, but parses JSON from an external file. Useful for large datasets.
## License

@@ -41,0 +68,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc