{"_id":"@dryfeld/fractal-twig","_rev":"1-def682e16977b83c20ac4430976e0519","name":"@dryfeld/fractal-twig","dist-tags":{"latest":"0.0.4"},"versions":{"0.0.3":{"name":"@dryfeld/fractal-twig","version":"0.0.3","description":"Twig template adapter for Fractal (fork).","main":"index.js","repository":{"type":"git","url":"git+https://github.com/jsutcliffe/fractal.git","directory":"packages/twig"},"license":"MIT","dependencies":{"@dryfeld/fractal-core":"^0.0.3","lodash":"^4.17.21","twig":"^1.15.4"},"publishConfig":{"access":"public"},"gitHead":"dd6cd938653b24cd23456d10b9c28d3bc436c4c3","bugs":{"url":"https://github.com/jsutcliffe/fractal/issues"},"homepage":"https://github.com/jsutcliffe/fractal#readme","_id":"@dryfeld/fractal-twig@0.0.3","_nodeVersion":"19.1.0","_npmVersion":"8.19.3","dist":{"integrity":"sha512-nDSO4LmlU0jtgmjVxRY2jj5AZMg8Yl9M3tsPHRWsE8I5znWYJ6z56w3TQj2HYFg2YtB9i9kmHQmgexE/BUoWfQ==","shasum":"495b3096465e30f3cb3c74541e06ea0accd5be6f","tarball":"https://registry.npmjs.org/@dryfeld/fractal-twig/-/fractal-twig-0.0.3.tgz","fileCount":14,"unpackedSize":21747,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC4WyS/Z6tr9pd4yEs0jOAxxcJitKnPhDR46TM79CFIGgIhAJOOsiIB7GaL6dNeP9NlP7wMA1ZVomxRDPhybCNUqOjC"}]},"_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-twig_0.0.3_1700565904940_0.038652290117751065"},"_hasShrinkwrap":false},"0.0.4":{"name":"@dryfeld/fractal-twig","version":"0.0.4","description":"Twig template adapter for Fractal (fork).","main":"index.js","repository":{"type":"git","url":"git+https://github.com/jsutcliffe/fractal.git","directory":"packages/twig"},"license":"MIT","dependencies":{"@dryfeld/fractal-core":"^0.0.4","lodash":"^4.17.21","twig":"^1.15.4"},"publishConfig":{"access":"public"},"gitHead":"dd6cd938653b24cd23456d10b9c28d3bc436c4c3","bugs":{"url":"https://github.com/jsutcliffe/fractal/issues"},"homepage":"https://github.com/jsutcliffe/fractal#readme","_id":"@dryfeld/fractal-twig@0.0.4","_nodeVersion":"19.1.0","_npmVersion":"8.19.3","dist":{"integrity":"sha512-HkO/T8IQq0PkQE2bjaIdtPQuEprVv91vAdn/RmEsbYLPFquPzMnD3bqNtCfShuNPJvA1tVRszh0IvyaHRYRuEw==","shasum":"f8c259e6ed3a6d48e8c73e252ce277a2791d0287","tarball":"https://registry.npmjs.org/@dryfeld/fractal-twig/-/fractal-twig-0.0.4.tgz","fileCount":14,"unpackedSize":21747,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCql1l7cxL/PWvxk5/Jx2ENTPuMIPzUQ0G+e7Mz+wbRnAIhAK8OeM3brZ5Re+Wf2ic6kDd7H09pSIwp//fMySWhD9Gf"}]},"_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-twig_0.0.4_1700570330836_0.554301477477972"},"_hasShrinkwrap":false}},"time":{"created":"2023-11-21T11:25:04.817Z","0.0.3":"2023-11-21T11:25:05.106Z","modified":"2023-11-21T12:38:51.234Z","0.0.4":"2023-11-21T12:38:51.063Z"},"maintainers":[{"name":"dryfeld","email":"jonathan.a.sutcliffe@gmail.com"}],"description":"Twig 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/twig"},"bugs":{"url":"https://github.com/jsutcliffe/fractal/issues"},"license":"MIT","readme":"# @dryfeld/twig\n\n[Twig](https://github.com/twigjs/twig.js) template enginge adapter for [Fractal](http://github.com/frctl/fractal).\n\n[![NPM Version](https://img.shields.io/npm/v/@dryfeld/twig)](https://www.npmjs.com/package/@dryfeld/twig)\n\nRequires Fractal v1.1.0 or greater.\n\nTo install this adapter run this command:\n\n`npm install @dryfeld/twig`\n\nthen open your fractal.js file and add following lines:\n\n```js\n/*\n * Require the Twig adapter\n */\nconst twigAdapter = require('@dryfeld/twig')();\nfractal.components.engine(twigAdapter);\nfractal.components.set('ext', '.twig');\n```\n\n## Using Twig for docs\n\nTo use Twig for docs, set the docs engine to `@dryfeld/twig`:\n```js\nfractal.docs.engine(twigAdapter);\n```\n\n\n## Extending with a custom config\n```js\n/*\n * Require the Twig adapter\n */\nconst twigAdapter = require('@dryfeld/twig')({\n    // if pristine is set to true, bundled filters, functions, tests\n    // and tags are not registered.\n    // default is false\n    pristine: false,\n\n    // if importContext is set to true, all include calls are passed\n    // the component's context\n    // default is false\n    importContext: false,\n\n    // use custom handle prefix\n    // this will change your includes to {% include '%button' %}\n    // default is '@'\n    handlePrefix: '%',\n\n    // set a base path for twigjs\n    // Setting base to '/' will make sure all resolved render paths\n    // start at the defined components dir, instead of being relative.\n    // default is null\n    base: '/',\n\n    // should missing variable/keys emit an error message\n    // If false, they default to null.\n    // default is false\n    strict_variables: true,\n\n    // define Twig namespaces, see https://github.com/twigjs/twig.js/wiki#namespaces\n    // this may break some fractal functionality, like including components via their handles and the render tag\n    namespaces: {\n        'Components': './components'\n    },\n\n    // use twig.js default template loader\n    // this will allow including templates via relative paths, like twig.js or PHP Twig does by default\n    // changing this will break including components via their fractal handles\n    // changing this will break the custom render tag\n    // default is 'fractal'\n    method: 'fs',\n\n    // register custom filters\n    filters: {\n        // usage: {{ label|capitalize }}\n        capitalize: function(str) {\n            if (!str) return '';\n\n            return str.charAt(0).toUpperCase() + str.slice(1);\n        }\n    },\n\n    // register custom functions\n    functions: {\n        // usage: {{ capitalize(label) }}\n        capitalize: function(str) {\n            if (!str) return '';\n\n            return str.charAt(0).toUpperCase() + str.slice(1);\n        }\n    },\n\n    // register custom tests\n    tests: {\n        // usage: {% if label is equalToNull %}\n        equalToNull: function(param) {\n            return param === null;\n        }\n    },\n\n    // register custom tags\n    tags: {\n        flag: function(Twig) {\n            // usage: {% flag \"ajax\" %}\n            // all credit to https://github.com/twigjs/twig.js/wiki/Extending-twig.js-With-Custom-Tags\n            return {\n                // unique name for tag type\n                type: \"flag\",\n                // regex match for tag (flag white-space anything)\n                regex: /^flag\\s+(.+)$/,\n                // this is a standalone tag and doesn't require a following tag\n                next: [ ],\n                open: true,\n\n                // runs on matched tokens when the template is loaded. (once per template)\n                compile: function (token) {\n                    var expression = token.match[1];\n\n                    // Compile the expression. (turns the string into tokens)\n                    token.stack = Twig.expression.compile.apply(this, [{\n                        type:  Twig.expression.type.expression,\n                        value: expression\n                    }]).stack;\n\n                    delete token.match;\n                    return token;\n                },\n\n                // Runs when the template is rendered\n                parse: function (token, context, chain) {\n                    // parse the tokens into a value with the render context\n                    var name = Twig.expression.parse.apply(this, [token.stack, context]),\n                        output = '';\n\n                    flags[name] = true;\n\n                    return {\n                        chain: false,\n                        output: output\n                    };\n                }\n            };\n        }\n    }\n});\n\n```\n\n\n## Using external plugins\n\nAn example to use [twig-js-markdown](https://github.com/ianbytchek/twig-js-markdown):\n```js\nconst twigMarkdown = require('twig-markdown');\nconst instance = fractal.components.engine(twigAdapter);\n\n// instance.twig refers to the twig.js instance\ninstance.twig.extend(twigMarkdown);\n\n```\n\n## Included filters\n\n### path\nTakes a root-relative path and re-writes it if required to make it work in static HTML exports.\n\nIt is strongly recommended to use this filter whenever you need to link to any static assets from your templates.\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\nUsage:\n```twig\n{{ '/css/my-stylesheet.css'|path }}\n```\n\n## Included tags\n\n### render\nThe render tag renders a component (referenced by its handle) using the context data provided to it. If no data is provided, it will use the context data defined within the component's configuration file, if it has one.\n\nUsage:\n```twig\n{% render \"@component\" with {some: 'values'} %}\n```\n","readmeFilename":"README.md"}