Skip to content

posthtml/hapi-posthtml

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NPM Deps Tests Coverage Standard Code Style Chat

Hapi PostHTML

Install

npm i -S hapi-posthtml

Usage

import Hapi from 'hapi'

import vision from 'vision'
import posthtml from 'hapi-posthtml'

const server = new Hapi.Server()

// Create server
server.connection({
  host: 'localhost',
  port: 3000
})

// Vision for view support
server.register(vision, err => {
  if (err) {
    throw err
  }
  // PostHTML
  server.views({
    path: 'public/views/',
    engines: {
      'html': posthtml
    },
    relativeTo: __dirname,
    compileMode: 'async'
    compileOptions: {
      // PostHTML Plugins
      plugins: [/* Plugins */]
    }
  })
})

// Create route handlers
const handlers = {
  root: function (request, reply) {
    reply.view('index')
  },
  local: function (request, reply) {
    reply.view('index', { plugins: [/* Plugins */] })
  },
  extend: function (request, reply) {
    reply.view('index', { plugins: [/* Plugins */], extend: true})
  }
}

// Create routes
server.route({
  method: 'GET',
  path: '/',
  handler: handlers.root
})

server.route({
  method: 'GET',
  path: '/local',
  handler: handlers.local
})

server.route({
  method: 'GET',
  path: '/extend',
  handler: handlers.extend
})

server.start((err) => {
  if (err) {
    throw err
  }
  console.log('=> Server:', server.info.uri)
})

Maintainers


Michael Ciniawsky

Contributing

See PostHTML Guidelines and contribution guide.

LICENSE

MIT

About

PostHTML for Hapi

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published