{"_id":"@dryfeld/fractal-nunjucks","_rev":"1-aa89ebab2f1f65e1202a08954651a106","name":"@dryfeld/fractal-nunjucks","dist-tags":{"latest":"0.0.4"},"versions":{"0.0.3":{"name":"@dryfeld/fractal-nunjucks","version":"0.0.3","description":"Nunjucks template adapter for Fractal (fork).","main":"index.js","repository":{"type":"git","url":"git+https://github.com/jsutcliffe/fractal.git","directory":"packages/nunjucks"},"license":"MIT","dependencies":{"@dryfeld/fractal-core":"^0.0.3","bluebird":"^3.7.2","lodash":"^4.17.21","nunjucks":"^3.2.3"},"publishConfig":{"access":"public"},"gitHead":"dd6cd938653b24cd23456d10b9c28d3bc436c4c3","bugs":{"url":"https://github.com/jsutcliffe/fractal/issues"},"homepage":"https://github.com/jsutcliffe/fractal#readme","_id":"@dryfeld/fractal-nunjucks@0.0.3","_nodeVersion":"19.1.0","_npmVersion":"8.19.3","dist":{"integrity":"sha512-aU4/4Beb3tBE5rMUBKb4uInbM8h9vsvN0tzZK+8Kmw1Bs7Tu2KSfbFXIHqzIK0paTtcv3MvDo5B7d7CrrWPtBg==","shasum":"1bfb78cdb1571dd15b369813ecf76df4efce616f","tarball":"https://registry.npmjs.org/@dryfeld/fractal-nunjucks/-/fractal-nunjucks-0.0.3.tgz","fileCount":11,"unpackedSize":20235,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCAfqqnWs9qSJvC4p5OxjK4ZBvNadDHtjZmnIlkhSpdmwIhALmWeynyT8wGf/heR3TAIoWDqzKlo/cRlKxm0R+OOArC"}]},"_npmUser":{"name":"dryfeld","email":"jonathan.a.sutcliffe@gmail.com"},"directories":{},"maintainers":[{"name":"dryfeld","email":"jonathan.a.sutcliffe@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fractal-nunjucks_0.0.3_1700565878583_0.8064885468954124"},"_hasShrinkwrap":false},"0.0.4":{"name":"@dryfeld/fractal-nunjucks","version":"0.0.4","description":"Nunjucks template adapter for Fractal (fork).","main":"index.js","repository":{"type":"git","url":"git+https://github.com/jsutcliffe/fractal.git","directory":"packages/nunjucks"},"license":"MIT","dependencies":{"@dryfeld/fractal-core":"^0.0.4","bluebird":"^3.7.2","lodash":"^4.17.21","nunjucks":"^3.2.3"},"publishConfig":{"access":"public"},"gitHead":"dd6cd938653b24cd23456d10b9c28d3bc436c4c3","bugs":{"url":"https://github.com/jsutcliffe/fractal/issues"},"homepage":"https://github.com/jsutcliffe/fractal#readme","_id":"@dryfeld/fractal-nunjucks@0.0.4","_nodeVersion":"19.1.0","_npmVersion":"8.19.3","dist":{"integrity":"sha512-wMp1Ws5hf5TUnMgXijGATc/ilgyEeWHmuhLzVmdJJftAXd55II/f+oDysJuQwE85+MHxsQyfX1YUllGtPJJ2sA==","shasum":"432bd04330dddfebd76caa521a9df31af15b0caa","tarball":"https://registry.npmjs.org/@dryfeld/fractal-nunjucks/-/fractal-nunjucks-0.0.4.tgz","fileCount":11,"unpackedSize":20235,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHThjcDVLhDG0Cx6ubmbbL2zXVzQBXAakXmNAO5LTN1PAiEArFCPKR7ZMHc+ytqMM2bihXYYbgUuaaVt4GRCkBQkNBc="}]},"_npmUser":{"name":"dryfeld","email":"jonathan.a.sutcliffe@gmail.com"},"directories":{},"maintainers":[{"name":"dryfeld","email":"jonathan.a.sutcliffe@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fractal-nunjucks_0.0.4_1700570344737_0.865983994089526"},"_hasShrinkwrap":false}},"time":{"created":"2023-11-21T11:24:38.486Z","0.0.3":"2023-11-21T11:24:38.921Z","modified":"2023-11-21T12:39:05.124Z","0.0.4":"2023-11-21T12:39:04.968Z"},"maintainers":[{"name":"dryfeld","email":"jonathan.a.sutcliffe@gmail.com"}],"description":"Nunjucks template adapter for Fractal (fork).","homepage":"https://github.com/jsutcliffe/fractal#readme","repository":{"type":"git","url":"git+https://github.com/jsutcliffe/fractal.git","directory":"packages/nunjucks"},"bugs":{"url":"https://github.com/jsutcliffe/fractal/issues"},"license":"MIT","readme":"# @dryfeld/nunjucks\n\n[Nunjucks](http://mozilla.github.io/nunjucks/) template engine adapter for [Fractal](http://github.com/frctl/fractal).\n\n[![NPM Version](https://img.shields.io/npm/v/@dryfeld/nunjucks)](https://www.npmjs.com/package/@dryfeld/nunjucks)\n\n## 🚨 Breaking changes in v2.0\n\n- `render` tag - Arrays in context data are **no longer merged** with those in the default component context\n- **Autoescaping** - this is now **disabled by default**. Preview templates will need to be updated to mark the `yield` output as safe using the Nunjucks `safe` filter: `{{ yield | safe }}`. Alternatively this can be enabled globally again using the environment options when [configuring the adapter](#customisation) (not recommended).\n- **Nunjucks version** - bumped to 3.x\n\n## Installation\n\n```bash\nnpm i @dryfeld/nunjucks --save\n```\n\n## Usage\n\n```javascript\nfractal.components.engine(\"@dryfeld/nunjucks\"); // register the Nunjucks adapter for your components\nfractal.components.set(\"ext\", \".njk\"); // look for files with a .njk file extension\n```\n\n## Customisation\n\nIf you want to register custom [filters](https://mozilla.github.io/nunjucks/api.html#custom-filters), global variables or [extensions](https://mozilla.github.io/nunjucks/api.html#custom-tags) to the underlying Nunjucks engine then you can configure an instance as follows:\n\n```javascript\nconst nunj = require(\"@dryfeld/nunjucks\")({\n  env: {\n    // Nunjucks environment opts: https://mozilla.github.io/nunjucks/api.html#configure\n  },\n  filters: {\n    // filter-name: function filterFunc(){}\n  },\n  globals: {\n    // global-name: global-val\n  },\n  extensions: {\n    // extension-name: function extensionFunc(){}\n  }\n});\n\nfractal.components.engine(\n  nunj\n); /* set as the default template engine for components */\n```\n\nFor example, to register the 'shorten' filter example from the [Nujucks docs](https://mozilla.github.io/nunjucks/api.html#custom-filters):\n\n```javascript\nconst nunj = require(\"@dryfeld/nunjucks\")({\n  filters: {\n    shorten: function(str, count) {\n      return str.slice(0, count || 5);\n    }\n  }\n});\n```\n\nWhich you could then use in your component or documentation views as follows:\n\n```nunjucks\n{# Show the first 5 characters #}\nA message for you: {{ message|shorten }}\n\n{# Show the first 20 characters #}\nA message for you: {{ message|shorten(20) }}\n```\n\n## Including and extending non-component view templates\n\nBy default, the Nunjucks adapter expects you to use the Fractal component `@handle` syntax to refer to components to include or extend in your templates.\n\nHowever, if you wish to include (or extend) non-component templates, you can also specify a path (or an array of paths) of directories for Nunjucks to search in for non-component templates when configuring your Nunjucks instance. For example:\n\n```javascript\nconst nunj = require(\"@dryfeld/nunjucks\")({\n  paths: [\"path/to/files\"]\n});\n```\n\n```html\n{% include 'foo.html' %}\n```\n\nIn this example the file `foo.html` would be searched for in the `path/to/files` directory and included if found.\n\n> Using additional search paths in this manner **does not** prevent standard `@handle` syntax includes working as well.\n\n## Extensions\n\nThe following Nunjucks extensions come **automatically pre-installed**. These are often useful when building or documenting Fractal-based component libraries.\n\nIf you **do not wish** to include these extensions, set `pristine: true` when configuring your Nunjucks adapter instance.\n\n### render\n\nThe `render` extension renders a component (referenced by it's handle) using the context data provided to it in the template. If no data is provided, it will use the context data defined within it's configuration file, if present.\n\n**This can be very useful as an alternative to using an `include` to import sub-components.** `Include`'d components do not pull in their own context so using `render` instead can help prevent repetition of context data in the configuration files of components that include sub-components.\n\n```html\n<!-- pass in data for rendering -->\n{% render '@example', {title: 'An Example'} %} {% render '@example', someData %}\n\n<!-- use the config file data for rendering -->\n{% render '@example' %}\n```\n\nYou can also pass in a _partial_ data object (i.e. containing only some of the properties the component expects) and then pass a third argument of `true` to the tag to populate the missing items from the default context data. This allows you to override only the items you need to for this instance of the rendered component.\n\n```html\n<!-- will get any missing properties from the component context data -->\n{% render '@another-example', {title: 'Another Example'}, true %}\n```\n\n### context\n\nOutputs the resolved context data for a component.\n\n```html\n{% context '@example' %}\n\n<!--\n  Outputs:\n  {\n      \"foo\": \"bar\",\n      \"baz\": \"bar\"\n  }\n-->\n```\n\n### view\n\nOutputs the raw view template contents for the specified component.\n\n```html\n{% view '@example' %}\n\n<!--\n  Outputs:\n  <p>{{ text }}</p>\n-->\n```\n\n## Filters\n\nThe following Nunjucks filters come **automatically pre-installed**. As with the extensions, setting `pristine: true` in the Nunjucks adapter instance config will prevent them being added.\n\n### path\n\nTakes a root-relative path and re-writes it if required to make it work in static HTML exports.\n\n**It is strongly recommended to use this filter whenever you need to link to any static assets from your templates.**\n\n```html\n{{ '/css/my-stylesheet.css' | path }}\n```\n\nThe path argument should begin with a slash and be relative to the web root. During a static HTML export this path will then be re-written to be relative to the current page.\n\n## Special variables\n\nThe Nunjucks adapter also makes a few special variables available to your templates. They all have names prefixed with an underscore to help prevent clashes with any context data variables that are set by the user.\n\nNote that using these may tie your templates a little more tightly into Fractal so you may choose not to use them for that reason.\n\n### \\_config\n\nContains the full Fractal configuration object. Useful for when you want to refer to a configuration item in your documentation (or components).\n\n```html\n{{ _config.project.title }}\n<!-- outputs the project title -->\n{{ _config.components.ext }}\n<!-- outputs the extension used for components -->\n```\n\n### \\_self\n\nContains a simple data object representation of the top-level item (i.e. component or page) being rendered.\n\n```html\n{{ _self.title }}\n<!-- outputs 'Button' -->\n```\n\n### \\_target\n\nThis variable is only set in component preview layouts, and contains a simple data object representation of the item (i.e. component or page) being rendered _within_ the preview layout.\n\n```html\n{{ _target.title }}\n<!-- outputs 'Button' -->\n```\n","readmeFilename":"README.md"}