{"_id":"@blade-sensei/mustache-layout","_rev":"1-3637b038cb452428ae0fc1f9e186d7ef","name":"@blade-sensei/mustache-layout","dist-tags":{"latest":"2.0.0"},"versions":{"2.0.0":{"name":"@blade-sensei/mustache-layout","version":"2.0.0","description":"Package to mustache express that enables to build Layouts (extends) views","main":"index.js","scripts":{"lint":"eslint .","lint:fix":"eslint . --fix","test":"echo \"Error: no test specified\" && exit 1"},"engines":{"node":">=10.0.0"},"repository":{"type":"git","url":"git+https://github.com/blade-sensei/mustache-layout.git"},"author":"","license":"ISC","bugs":{"url":"https://github.com/blade-sensei/mustache-layout/issues"},"homepage":"https://github.com/blade-sensei/mustache-layout#readme","dependencies":{},"devDependencies":{"eslint":"^6.8.0","eslint-config-sensei":"^2.0.4"},"gitHead":"e08f92dc9419e9dadbda9c5746b220e5e0d1e8fc","_id":"@blade-sensei/mustache-layout@2.0.0","_nodeVersion":"10.13.0","_npmVersion":"6.11.3","dist":{"integrity":"sha512-lnGtKvvX2rwHi9IyLjKzv9FZ3ywXFOBFq1oROrJIm0+2lUgnE3NAF8mCTTzFZqjICqyRBm9fGs3DhFAOebWpVQ==","shasum":"964e68eb3fe522bcdd6c1280f892e5e6547d205f","tarball":"https://registry.npmjs.org/@blade-sensei/mustache-layout/-/mustache-layout-2.0.0.tgz","fileCount":4,"unpackedSize":4929,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJed2xSCRA9TVsSAnZWagAAlGsP/2ecEn+3K3r4nZaq8prl\neFFED/kuAv2QY0kxcxOqwF0LQC9/gwe/fJ1NGPcRHqC+EcvRk6CE+OpVhv6V\nFywH3m/YEmJHQ9TuIw+YLQGIEhi5Rr4vqnHoaxXgUxxVRloizQL6aQcik6qy\nBkeQe9WmTooHQCnk2R1Ck4xLix36qwzTt4xUpyCxaQsosz2okRPKVAMptWaJ\nVaLyQGJnXuajhGp99kmn4cMEUyCkfZyDXCT63AINx0ppL1fft6jYc9Z1aaD0\n1gTqQrpb4+YNwUyPoSOFKzqFsOrOXGgyiNfIv5QSIGH7LttWPAMLUZJMLpyT\nM39pikKboovX0ntU0OvhDbvdgPGpARCPLULa7kmM5fRDn0Jqjp1FSQ9QK14F\nNF3aSMtNdzuEUJiYJ40mvbpqT/l/TVEp/c1j3X39AtTpqly+AyTSf2A/j3PI\noN0TKZoDwrHaXaWbAIl+5VM5eLOp45hZ2mHqySejvJVOgnJWboqLzRBXHKr8\nt+R2RMSnzNxfr2XY36o+jocMYtFjlDDxeEEkHOR9dInkoRsKlK2vGOLfECkO\n3u0vKFNGsji5uS06NOr0UvVicyaHZYNTnqox1hQoKkCGYxsuTzOgPfLjmHYb\nB3kkoH4p02IET6WRCuJR7EnFgLWCmvPWq16B8dkEF9hNG6iC0NaQ8Ikgxt3b\nzB+X\r\n=86t5\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDkiJQw11Zul3seQNULRpb0nkaGrO/f838ikNQSalbrPgIgAsxVfJHDAO8LJhPpJmVHEltpWT9ltPLGWlvwOErz3n4="}]},"maintainers":[{"name":"blade-sensei","email":"jcoyla123@gmail.com"}],"_npmUser":{"name":"blade-sensei","email":"jcoyla123@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/mustache-layout_2.0.0_1584884817624_0.809903251241106"},"_hasShrinkwrap":false}},"time":{"created":"2020-03-22T13:46:57.395Z","2.0.0":"2020-03-22T13:46:57.813Z","modified":"2022-04-04T19:23:13.506Z"},"maintainers":[{"name":"blade-sensei","email":"jcoyla123@gmail.com"}],"description":"Package to mustache express that enables to build Layouts (extends) views","homepage":"https://github.com/blade-sensei/mustache-layout#readme","repository":{"type":"git","url":"git+https://github.com/blade-sensei/mustache-layout.git"},"bugs":{"url":"https://github.com/blade-sensei/mustache-layout/issues"},"license":"ISC","readme":"# @blade-sensei/mustache-layout\n\nPackage for mustache-express that enables to build Layouts (extends) views.\n\n## Problem\n\nIf you use [mustache-express](https://www.npmjs.com/package/mustache-express) you can include/import views (partials), but you can't extend your view, by extend i mean 'inherit'.\n\nYou have a solution to this problem: https://stackoverflow.com/questions/7925931/can-mustache-templates-do-template-extension, but mustache-layout package suggest an alternative solution.\n\n## Use case\n\nIf you don't want to copy/paste the header/footer, or maybe an menu bar that is repeated in all admin sub sections,\neach time you render a page/view, you just need to use the function: `build`\n\n\n\n![](https://i.imgur.com/xxaZZ9z.pngg)\n\n\n## Install\n\n```bash\nnpm i @blade-sensei/mustache-layout\n```\n\n## How to use it with example\n\nIn your server.js file of express app, add the app instance to our package.\n\nMustache-express package implementation is also explained.\n\n```js\nconst mustacheExpress = require('mustache-express');\nconst mustacheLayout = require('@blade-sensei/mustache-layout');\n\nconst app = express();\n\n// set template engine mustache-express\napp.engine('html', mustacheExpress());\napp.set('view engine', 'html');\napp.set('views', __dirname + '/views');\n\n\nmustacheLayout.setExpressApp(app);\n```\n\n### Controller\n\nPut all the layer in the buildLayout function as parameters, \n\n> **warning**: \n> - you need to respect order, from the smallest layout to the bigger (base.html)\n> - data properties should be named as in the view\n\n```js\nconst layout = require('@blade-sensei/mustache-layout');\n\nrouter.get('/edit', async (_, res) => {\n    const user = 'admin'\n    const html = await layout.build(\n        { name: 'admin/edition/editor.view.html', data: { user } },\n        { name: 'admin/admin.view.html' },\n        { name:'layout/base.view.html' }\n    )\n    return res.send(html);\n});\n```\n\n### View\n\n> **warning** You need to use the keyword `child` in layout view pages.\n> don't forget triple braces {{{ }}}\n\nUse your passed data here\n\n```html\n<!-- ditor.view.html -->\n<div> {{ user }} </div>\n```\n\n```html\n<!-- admin.view.html -->\n<h3> Admin section layout </h3> \n<div class=\"admin-content\">\n    {{{ child }}}\n</div>\n```\n\n```html\n<!-- base.view.html -->\n<!DOCTYPE html>\n<html lang=\"en\">\n<body>\n    {{ > layout/header.view }}\n    <div class=\"main\">\n        <div class=\"layout-content\">\n            {{{ child }}}\n        </div>\n    </div>\n    {{ > layout/footer.view }}\n</body>\n</html>\n```\n\n## Docs\n![](https://i.imgur.com/Fq7SWEp.png)\n","readmeFilename":"README.md"}