{"_id":"@whitespace/twig-extension-attribute-helpers","_rev":"33-5f2c9bc21e69992301b1bff044b92190","name":"@whitespace/twig-extension-attribute-helpers","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@whitespace/twig-extension-attribute-helpers","version":"1.0.0","keywords":["twig","twig extension","twig function","attributes","html attributes"],"author":{"name":"Whitespace"},"license":"MIT","_id":"@whitespace/twig-extension-attribute-helpers@1.0.0","maintainers":[{"name":"jeanfredrik","email":"jeanfredrik@gmail.com"},{"name":"whitespace-new","email":"code@whitespace.se"}],"homepage":"https://github.com/whitespace-se/twig-extension-attribute-helpers#readme","bugs":{"url":"https://github.com/whitespace-se/twig-extension-attribute-helpers/issues"},"dist":{"shasum":"488ccae78c49968ec472cf271a560f19748b08ab","tarball":"https://registry.npmjs.org/@whitespace/twig-extension-attribute-helpers/-/twig-extension-attribute-helpers-1.0.0.tgz","fileCount":25,"integrity":"sha512-WaSau3OkN1pea62XjkbJG1pPxA9t7NWttTOY+ue5Auq+N1KlIDSM4rnwkNK3WUYR06OdzoB43ffboM1in6or/Q==","signatures":[{"sig":"MEQCIDzo1hOAt4e0zm2hzsYo69eXoWqs7qfPszmGrVYRNTk/AiBnCVVnUUq2BQ17+Mq9F96gEGiaLBZXaZh7nDH5hm2gng==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":90003,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJd2usiCRA9TVsSAnZWagAAPDQP/2mJhkRoKxQOFcrSHAgh\nuvsrlqzinyBMdDH19i/2jxfdIDQIK5n0xVKI9MkRoE8VtegQfgw6dBi5qmEY\n8KVJWSjuZJvp+dtm9LCREDtzbYE3P5kZAl16SP+Rd3CQ3+/lEUacBUx7cJrx\nboillxAB+8n43wc5W7k0wFHEAWRBI0srILenwblZTx12ByUH6BTPCw3jom9O\nWpsDw9Na//P5uBFPPP9W2/uIqNnT8KCqrQLogVPebkni2ktWpyBEsJT64qXG\nLN0A6yauCSWpA+1EpPGSa1hZibRS4VLSLtn0fJ7KUMIOAj89mYOZGIiL4OCS\nYxmgBBkb1A9/aUI7HQI4MA5pOnbgMWO1m4QVqDzbXgjWyXoUfkH6WENSFCab\nPOmRLKFhJRK7D7b22P9zwwQ3CT+vMB9cGyNrIv6gCri1av7FKn3ip12c4Sxd\ndsfzLWgjCRHI4ZLHBZpOoO+1bCLEfIISNAzK0YPLytsfs+RziKRDk6gnz1/q\nUpC1Fzo15r1tRs7TguVwNfWzWRlf0+Seup6TJLLTzdiRM0g7misJ5IJbomXz\n5PlNji1nD1/rNGukknxkIJj5yTeiMFlqq43LvExOY0PpB316zzSnfb1MHIUb\nqgBIxqljwIuf1BdQzUktzbYfW+FOHMgvQVDkMSJsFJy7ZIB5dlTmtj1rjZAw\nhliV\r\n=OvSe\r\n-----END PGP SIGNATURE-----\r\n"},"main":"index.js","gitHead":"a916def3f3b6b3936b8e4a8b7069ed27b0c1618a","scripts":{"test":"jest --coverage","build":"npm run clean & babel -d ./lib ./src","clean":"rm -rf ./lib","prepare":"npm run build","prettier":"prettier --write '**/*.{js,json,md,yml}'","test:watch":"jest --watch --coverage","build:watch":"babel --watch -d ./lib ./src"},"_npmUser":{"name":"jeanfredrik","email":"jeanfredrik@gmail.com"},"repository":{"url":"git+https://github.com/whitespace-se/twig-extension-attribute-helpers.git","type":"git"},"_npmVersion":"6.13.0","description":"A Twig.js extension that allows you to work more easily with html attributes inside Twig templates","directories":{},"_nodeVersion":"10.15.3","dependencies":{"he":"^1.2.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^24.9.0","twig":"^1.14.0","eslint":"^6.7.0","prettier":"^1.19.1","@babel/cli":"^7.7.0","@babel/core":"^7.7.4","babel-eslint":"^10.0.3","@babel/preset-env":"^7.7.4","eslint-plugin-jest":"^23.0.4"},"_npmOperationalInternal":{"tmp":"tmp/twig-extension-attribute-helpers_1.0.0_1574628130321_0.7245531018466949","host":"s3://npm-registry-packages"}}},"time":{"created":"2019-11-24T20:42:10.066Z","modified":"2025-03-12T09:22:29.827Z","1.0.0":"2019-11-24T20:42:10.468Z"},"bugs":{"url":"https://github.com/whitespace-se/twig-extension-attribute-helpers/issues"},"author":{"name":"Whitespace"},"license":"MIT","homepage":"https://github.com/whitespace-se/twig-extension-attribute-helpers#readme","keywords":["twig","twig extension","twig function","attributes","html attributes"],"repository":{"url":"git+https://github.com/whitespace-se/twig-extension-attribute-helpers.git","type":"git"},"description":"A Twig.js extension that allows you to work more easily with html attributes inside Twig templates","maintainers":[{"email":"jeanfredrik@gmail.com","name":"jeanfredrik"},{"email":"code@whitespace.se","name":"whitespace-se"},{"email":"paul.brotherton@whitespace.se","name":"pbrotherton"},{"email":"ynwuay@gmail.com","name":"ynwuay"},{"email":"johan.westin@whitespace.se","name":"johan-westin"},{"email":"johan.de.geer@whitespace.se","name":"degeer"},{"email":"benjamin@tsubarah.com","name":"tsubarah"},{"email":"ruslanalogosha@gmail.com","name":"ruslana_zholobnytska"}],"readme":"# Attribute helpers for Twig.js\n\nA Twig.js extension that allows you to work more easily with html attributes inside Twig templates. The API mimics the Attribute objects in Drupal.\n\n## Getting started\n\n```bash\nnpm install --save @whitespace/twig-extension-attribute-helpers\n```\n\nImport the extension and pass it your Twig object:\n\n```js\nimport Twig from 'twig';\nimport extendWithAttributeHelpers from '@whitespace/twig-extension-attribute-helpers';\n\n// Adds the `attributes` function\nextendWithAttributeHelpers(Twig);\n\nlet data = `<a{{ attributes({\n  href: '#',\n  class: ['btn', 'btn-primary']\n}) }}>`;\nlet output = Twig.twig({ data }).render();\n// output === `<a href=\"#\" class=\"btn btn-primary\">`\n});\n```\n\n## Twig API\n\n### `attributes(attrs)`\n\nCreates and Attribute object containing the passed attributes and values. `attrs` should be an object. When rendered it is serialized as HTML attributes. Example:\n\n```twig\n<a{{ attributes({\n  href: '#',\n  class: ['btn', 'btn-primary']\n}) }}>\n```\n\nOutput:\n\n```twig\n<a href=\"#\" class=\"btn btn-primary\">\n```\n\n### `.setAttibute(attr, value)`\n\nSets an attribute on an already created Attribute object:\n\n```twig\n{% set linkAttributes = attributes({\n  href: '#'\n}) %}\n<a{{ linkAttributes.setAttribute('target', '_blank') }}>\n```\n\nOutput:\n\n```twig\n<a href=\"#\" target=\"_blank\">\n```\n\n### `.removeAttibute(attr)`\n\nUnsets a previously set attribute\n\n```twig\n{% set linkAttributes = attributes({\n  href: '#',\n  target: '_blank'\n}) %}\n<a{{ linkAttributes.removeAttribute('target') }}>\n```\n\nOutput:\n\n```twig\n<a href=\"#\">\n```\n\n### `.addClass(...classNames)`\n\nAdds one or more classes to the `class` attribute.\n\n```twig\n{% set linkAttributes = attributes({\n  href: '#'\n}) %}\n<a{{ linkAttributes.addClass('btn', 'btn-primary') }}>\n```\n\nOutput:\n\n```twig\n<a href=\"#\" class=\"btn btn-primary\">\n```\n\n### `.removeClass(...classNames)`\n\nRemoves one or more classes from the `class` attribute.\n\n```twig\n{% set linkAttributes = attributes({\n  href: '#',\n  class: ['btn', 'btn-primary']\n}) %}\n<a{{ linkAttributes.removeClass('btn-primary') }}>\n```\n\nOutput:\n\n```twig\n<a href=\"#\" class=\"btn\">\n```\n\n### Other functions\n\n- `setAttributes(attrs)`\n- `getAttribute()`\n- `getAttributes()`\n- `hasAttribute(attr)`\n- `getClass()`\n- `hasClass(className)`\n","readmeFilename":"README.md"}