Package Exports
- koa-bel
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (koa-bel) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
koa-bel

View engine for
koa
without any deps, built to be used withbel
. Any other engines that can be written in.js
files would work, too.
Install
npm i koa-bel --save
Usage
For more use-cases see the tests
const koaBel = require('koa-bel')
koaBel
Javascript template views for koa@2. You can use koa-convert if you want to work in koa@1.x version.
Cool thing about that, is it not requires your templates to be bel or something other like yo-yo, or any other DOM thingy. You can simple return a stream or buffer or anything that can be added to
ctx.body
. By default it calls.toString()
on the returned value, but you can bypass that if you passopts.toString: false
option.
Params
<dir>
{String|Buffer}: directory to read the views[opts]
{Object}: optional optionsreturns
{Function}: plugin for koa version 2
Example
const Koa = require('koa')
const bel = require('koa-bel')
const app = new Koa()
const port = 4290
app.use(bel('./views'))
app.use((ctx, next) => {
ctx.render('home', {
heading: 'Welcome page',
description: 'This is our cool landing page, man!',
subhead: 'What we offer?',
services: [
'Realtime Web Apps',
'Security and Simplicity',
'Logo Design and Prototypes'
]
})
return next()
})
app.listen(port, (err) => {
console.log(`Server start listening on http://localhost:${port}`)
})
Example views/home.js
Here you can even use yo-yo, instead of bel. Or just return a buffer or stream and just pass
options.toString: false
option.
'use strict'
var bel = require('bel')
module.exports = function home (state) {
return bel`<section>
<h1>${state.heading}</h1>
<p>${state.description}</p>
<h2>${state.subhead}</h2>
<ul>${state.services.map((service) => {
return bel`<li>${service}</li>`
})}</ul>
</section>`
}
Related
- bash-glob: Bash-powered globbing for node.js | homepage
- bel: A simple extension to native elements | homepage
- choo: A 5kb framework for creating sturdy frontend applications | homepage
- ip-filter: Validates valid IPs (IPv4 and IPv6) using micromatch - glob patterns, RegExp… more | homepage
- is-match-ip: Matching IPs using micromatch and ip-filter - glob patterns, RegExp, string or… more | homepage
- koa-better-body: Full-featured koa body parser! Support parsing text, buffer, json, json patch, json… more | homepage
- koa-ip-filter: Middleware for koa that filters IPs against glob patterns, RegExp, string or… more | homepage
- koa: Koa web app framework | homepage
- micromatch: Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch… more | homepage
- morphdom: Morph a DOM tree to another DOM tree (no virtual DOM needed) | homepage
- nanomatch: Fast, minimal glob matcher for node.js. Similar to micromatch, minimatch and multimatch… more | homepage
- vel: Create and render virtual-dom elements with ease | homepage
- yo-yo: A tiny library for building modular UI components using DOM diffing and… more | homepage
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.