Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dadi/web-pugjs
A Pug interface for DADI Web
https://github.com/dadi/web-pugjs
dadi dadi-web jade pug pug-js schema-less web-server
Last synced: 4 days ago
JSON representation
A Pug interface for DADI Web
- Host: GitHub
- URL: https://github.com/dadi/web-pugjs
- Owner: dadi
- Created: 2017-05-05T11:32:25.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-09T00:52:03.000Z (almost 2 years ago)
- Last Synced: 2024-04-14T04:32:35.589Z (7 months ago)
- Topics: dadi, dadi-web, jade, pug, pug-js, schema-less, web-server
- Language: JavaScript
- Size: 1.14 MB
- Stars: 0
- Watchers: 6
- Forks: 1
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Pug.js engine interface
[![npm (scoped)](https://img.shields.io/npm/v/@dadi/web-pugjs.svg?maxAge=10800&style=flat-square)](https://www.npmjs.com/package/@dadi/web-pugjs)
[![Coverage Status](https://coveralls.io/repos/github/dadi/web-pugjs/badge.svg?branch=master)](https://coveralls.io/github/dadi/web-pugjs?branch=master)
[![Build Status](https://travis-ci.org/dadi/web-pugjs.svg?branch=master)](https://travis-ci.org/dadi/web-pugjs)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](http://standardjs.com/)This module allows [Pug.js](https://pugjs.org) templates to be used with [DADI Web](https://github.com/dadi/web).
## Installation
- Add this module as a dependency:
```
npm install @dadi/web-pugjs --save
```- Include it in the `engines` array passed to Web:
```js
require('@dadi/web')({
engines: [
require('@dadi/web-pugjs')
]
})
```## Usage
### Include paths
Partials can be included using the `include` keyword and paths to the included files can be absolute or relative (see [Pug's documentation](https://pugjs.org/language/includes.html)).
The base directory for absolute paths is the `pages/` directory. Take the following directory tree.
```
pages/
|_ partials/
|_ |_ common/
|_ |_ |_ header.pug
|_ |_ contact-info.pug
|_ home.pug
```To include `header.pug` from `contact-info.pug`, you can do:
```pug
//- Absolute path
include /partials/common/header.pug//- Relative path
include common/header.pug
```### Helper functions
Add a DADI Web configuration setting for `helpers`, pointing to a directory containing helper files. Each `.js` helper file will be added as a property to template locals for use within templates.
#### Configuration
```
engines: {
pug: {
paths: {
helpers: 'test/workspace/helpers'
}
}
}
```#### Directory structure
```
helpers/
|_ trim.js
pages/
|_ partials/
|_ |_ common/
|_ |_ |_ header.pug
|_ |_ contact-info.pug
|_ home.pug
```#### Locals
The function is added to the template locals, along with data objects:
```
{
products: [
{ name: 'The Old Man and the Sea' }
],
trim: [Function]
}
```#### Usage
Use the function in templates like so:
```
h1= trim(product.name)
```