{"id":13787240,"url":"https://github.com/webdevian/adonis-pug","last_synced_at":"2025-10-25T21:32:03.864Z","repository":{"id":46160831,"uuid":"80964782","full_name":"webdevian/adonis-pug","owner":"webdevian","description":"Pug templating provider for AdonisJs","archived":false,"fork":false,"pushed_at":"2024-09-06T10:28:35.000Z","size":588,"stargazers_count":9,"open_issues_count":7,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-31T10:51:12.682Z","etag":null,"topics":["adonisjs","provider","pug"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/webdevian.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-02-05T02:59:37.000Z","updated_at":"2020-06-09T17:53:03.000Z","dependencies_parsed_at":"2024-10-10T23:21:39.153Z","dependency_job_id":null,"html_url":"https://github.com/webdevian/adonis-pug","commit_stats":{"total_commits":70,"total_committers":6,"mean_commits":"11.666666666666666","dds":"0.19999999999999996","last_synced_commit":"1a2bceb9c5b6a36dd051249641415336e16a4ee5"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webdevian%2Fadonis-pug","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webdevian%2Fadonis-pug/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webdevian%2Fadonis-pug/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webdevian%2Fadonis-pug/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/webdevian","download_url":"https://codeload.github.com/webdevian/adonis-pug/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238212440,"owners_count":19434955,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["adonisjs","provider","pug"],"created_at":"2024-08-03T20:00:31.834Z","updated_at":"2025-10-25T21:32:03.515Z","avatar_url":"https://github.com/webdevian.png","language":"JavaScript","funding_links":[],"categories":["Templates"],"sub_categories":[],"readme":"[![NPM Package][npm-badge]][npm-link] [![License][license-badge]][license-link] [![Build Status][travis-badge]][travis-link] [![Coverage Status][coveralls-badge]][coveralls-link] [![Maintainability][cc-badge]][cc-link] [![Dependencies][dm-badge]][dm-link] [![Dev Dependencies][dmdev-badge]][dmdev-link] [![Greenkeeper badge][gk-badge]][gk-link]\n\n\n# Adonis Pug\n\n[Pug](https://github.com/pugjs/pug) templating provider for AdonisJs framework version 4.\n\n## Installation\n\nIn order to use adonis-pug\n\n```\nnpm install adonis-pug --save\n```\n\nOnce you have installed the provider from [npm](https://npmjs.org/packages/adonis-pug), make sure that the ViewProvider is registered as a provider inside start/app.js file.\n\n```javascript\nconst providers = [\n  'adonis-pug/providers/ViewProvider'\n]\n```\n\nMake sure the default edge provider (`@adonisjs/framework/providers/ViewProvider`) is not registered as they will conflict with each other.\n\n#### Compatibility\n\n*This package has been rebuilt for Adonis 4 and is incompatible with Adonis 3 and earlier. \nFor Adonis v3 install the previous version (3.01) with :*\n\n```\nnpm install adonis-pug@\u003c4.x --save\n```\n\n## Config\n\nPug options can be added to `config/pug.js`, these will be passed to the pug engine:\n\n```javascript\n  module.exports = {\n    pretty: false,\n    cache: false, // Recommend setting this to true for 10x big performance boost\n    doctype: undefined,\n    filters: undefined,\n    self: false,\n    compileDebug: false,\n    debug: false\n  }\n```\n\nSee the [Pug API documentation](https://pugjs.org/api/reference.html) for more info on these options.\n\n## Basic Usage\n\nLet’s start with the basic example of saying `Hello world` by rendering a pug template. All of the views are stored inside `resources/views` directory and end with `.pug` extension.\n\nCreate a pug template at `resources/views/hello.pug`. You can use an adonis/ace command to create the view.\n\n```sh\nadonis make:pug home\n\n    ✔ create  resources/views/home.pug\n```\n\nNow let's create a route that renders it:\n\n```javascript\nRoute.get('/', ({ view }) =\u003e {\n  return view.render('home')\n})\n```\n\nThe view.render method takes the relative path to the view file. There is no need to type .pug extension.\n\n\n## View Methods\n\nThese methods are available on the view context object in controllers and middleware.\n\n#### view.share(locals)\nShare variables as a local with this template context.\n\n\n| Param | Type | Description |\n| --- | --- | --- |\n| locals | \u003ccode\u003eObject\u003c/code\u003e | Key value pairs |\n\n###### *Example*\n\nQuite often you want to share request specific values with your views, this can be done in middleware or controllers by passing an object to the share method.\n\n```javascript\nclass SomeMiddleware {\n  async handle ({ view }, next) {\n    view.share({\n      apiVersion: request.input('version')\n    })\n\n    await next()\n  }\n}\n```\n\nInside your views, you can access it like any other variable\n\n```pug\np= apiVersion\n```\n\n#### view.render(template, locals) ⇒ \u003ccode\u003eString\u003c/code\u003e\nRender a pug template\n\n**Returns**: \u003ccode\u003eString\u003c/code\u003e - HTML rendered output  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| template | \u003ccode\u003eString\u003c/code\u003e | View file (.pug extension not required) |\n| locals | \u003ccode\u003eObject\u003c/code\u003e | Variables to be passed to the view |\n\n#### view.renderString(string, locals) ⇒ \u003ccode\u003eString\u003c/code\u003e\nRender a string of pug\n\n**Returns**: \u003ccode\u003eString\u003c/code\u003e - HTML rendered output  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| string | \u003ccode\u003eString\u003c/code\u003e | String to be rendered |\n| locals | \u003ccode\u003eObject\u003c/code\u003e | Variables to be passed to the view |\n\n\n## View Helpers\n\nA number of global methods and contextual helpers are injected into all views.\n\n### Request\n\nAll views have access to the current request object, and you can call request methods inside your templates as well.\n\n```pug\np The request URL is #{request.url()}\n```\n\nAlso, there is a direct helper to get the URL.\n\n```pug\np The request URL is #{url}\n```\n\n### style - *formerly css (deprecated)*\n\nAdd link tag to a CSS file. The file name should be relative from the public directory. Absolute links are left alone (for external CDNs etc)\n\n``` pug\n!= style('style')\n// Renders \u003clink rel='stylesheet' href=\"/style.css\"\u003e\n```\n\n### script\n\nSimilar to css, adds a script tag to the document\n\n``` pug\n!= script('my-script')\n// Renders \u003cscript type=\"text/javascript\" src=\"/my-script.js\"\u003e\u003c/script\u003e'\n```\n\n### assetsUrl\nReturns path of a file relative from the public directory.\n\n```pug\nimg(src=assetsUrl('logo.png'))\n// Renders \u003cimg src='/logo.png' /\u003e\n```\n\n### route\nGet actual URL for a route\n\nExpecting the route to be registered as following\n\n```javascript\nRoute.get('users/:id', 'UserController.show').as('profile')\n```\n\n```pug\na(href=route('profile', { id: 1 })) View Profile\n// Renders \u003ca href=\"/users/1\"\u003eView Profile\u003c/a\u003e\n```\n\nAlso, you can use the controller method name.\n\n```pug\na(href=\"route('UserController.show', { id: 1 }) View profile\n```\n\n### auth\nIf you are using the auth provider, then you can access the current logged in user using the `auth.user` object.\n\n### csrfField\nIf you are using the shield middleware, you can access the `csrfToken` and field using one of the following methods.\n\n```pug\n!= csrfField()\n// Renders \u003cinput type=\"hidden\" name=\"_csrf\" value=\"...\" /\u003e\n```\n\n### cspMeta\n\nWhen using shield middleware, the CSP headers are set automatically. However can also set them using HTML meta tags.\n\n```pug\nhead\n  != cspMeta()\n```\n\n## Extending views\n\nYou can also extend views by adding your own view globals. Globals should only be added once, so make sure to use the start/hooks.js file and add them using the after providersBooted hook.\n\n### Globals\n\n``` javascript\nconst { hooks } = require('@adonisjs/ignitor')\n\nhooks.after.providersBooted(() =\u003e {\n  const View = use('View')\n\n  View.global('currentTime', function () {\n    return new Date().getTime()\n  })\n})\n```\n\nAbove global returns the current time when you reference it inside the views.\n\n```pug\np The time is #{currentTime()}\n```\n\nYou can extract the code inside providersBooted to a different file and require it.\n\n### Globals scope\n\nThe value of `this` inside globals closure is bound to the template context so that you can access runtime values from it.\n\nTo use other global methods or values, make use of the this.globals object.\n\n```javascript\nView.global('messages', {\n  success: 'This is a success message',\n  warning: 'This is a warning message'\n})\n\nView.global('getMessage', function (type) {\n  return this.globals.messages[type]\n})\n```\n\n```pug\np= getMessage('success')\n// Renders \u003cp\u003eThis is a success message\u003c/p\u003e\n```\n[npm-badge]: https://img.shields.io/npm/v/adonis-pug.svg?maxAge=30\n[npm-link]:https://npmjs.com/package/adonis-pug\n[license-badge]: https://img.shields.io/npm/l/adonis-pug.svg\n[license-link]: https://github/webdevian/adonis-pug/blob/master/LICENSE\n[travis-badge]: https://travis-ci.org/webdevian/adonis-pug.svg?branch=master\n[travis-link]: https://travis-ci.org/webdevian/adonis-pug\n[coveralls-badge]: https://coveralls.io/repos/github/webdevian/adonis-pug/badge.svg?branch=master\n[coveralls-link]: https://coveralls.io/github/webdevian/adonis-pug?branch=master\n[cc-badge]: https://img.shields.io/codeclimate/maintainability/webdevian/adonis-pug.svg\n[cc-link]: https://codeclimate.com/github/webdevian/adonis-pug/maintainability\n[dm-badge]: https://img.shields.io/david/webdevian/adonis-pug.svg\n[dm-link]: https://david-dm.org/webdevian/adonis-pug\n[dmdev-badge]: https://img.shields.io/david/dev/webdevian/adonis-pug.svg\n[dmdev-link]: https://david-dm.org/webdevian/adonis-pug\n[gk-badge]: https://badges.greenkeeper.io/webdevian/adonis-pug.svg\n[gk-link]: https://greenkeeper.io/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebdevian%2Fadonis-pug","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebdevian%2Fadonis-pug","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebdevian%2Fadonis-pug/lists"}