npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hapi-orchestra-view

v3.0.8

Published

Library for composing handlebar html templates into a single page

Downloads

11

Readme

Build Status Coverage Status

Hapi orchestra view

Library for composing handlebar html templates into a single page. With a director file you define the skeleton of a page and then it is composed from templates. First each template is compiled and then the director with the compiled templates as input. The function h.viewOrchestra(options) is used to returned the final html where options.params object holds the parameters available to all templates. Please se example below for more options.

Installation

Copy files in lib/views to preferred folder in project

Open the director.html and edit it accordingly to your preference. Each triple handlebar import corresponds to the compiled output (except for raw.html) of files in lib/view/templates.

Run npm install --save git+https://[email protected]/mickelindahl/hapi_orchestra_view.git

Usage

'use strict'

const Hapi = require( 'hapi' );

const server = new Hapi.Server( { port: 3000 } );

server.register( {
   register: require( 'hapi-page-view' ),
   options:  {
      templates: [
         { id: 'my_head', param: 'head', path: 'orchestra/templates/head.html', compile:true },
         { id: 'my_body', param: 'body', path: 'main.html', compile:true },
         { id: 'my_raw', param: 'raw', path: 'orchestra/templates/raw.html', compile:false },
        ],
   directors: [{ id: 'my_director', path: 'orchestra/director.html' }],
   views: './lib/views',
   actions:[{
        template_id:'my_head',
        callbacks:[async (params)=>{params.page_title='Super site'}]
        }]

        }
    }).then(()=>{

    server.route([
        {
            method: 'GET',
            path: '/'
            handler: async (request, h)=>{
                return h.viewOrchestra({
                            director:'my_director',
                            include: ['my_head', 'my_body','my_body_2',  'my_raw', 'my_wrong'],
                            params: {title:'A title'},
                            callbacks:[async (params)=>{params.name='Humphrey Bogard'}]
                    }),
                }
            }
        ])
});

Methods

The handler is attached to hapijs server.methods

handler

handler.plugin

Hapi plugin options

  • options Object with the following keys
    • templates {array} List with available templates. Multiple templates having the same name will be merged
      • [].id {string} Template identifier
      • [].param {string} Director parameter name where template should be inserted
      • [].path {string} Path to template relative view directory
      • [].compile {boolean} Indicates weather template should be compiled or not
    • directors {array} List with available directors
      • [].id {string} Director identifier
      • [].path {string} Path to director
    • views {string} Path to view folder
    • actions {object} Actions that are always evoked
      • template_id {string} Template it should add parameters to
      • callback(params, h) {async function}
        • params {object} Template parameter object
        • h {object} hapi response toolkit object

Kind: static property of handler

handler~viewOrchestra() ⇒ Promise

Create a view by composing files in the templates directory through the director.html

  • options {object} with the following keys
    • callbacks {array} Array with async function(params). The h toolkit instance is available as this e.g. you have request at this.request and server at this.request.server)
      • []( params, h) {async function}
        • params {object} object holding params used at template compilation
        • h {object} hapi response toolkit object
    • director {string} id of director to use
    • include {string} Template ids to include
    • params Object {key:values} made available to templates for handlebars.compile

Kind: inner method of handler

Test

npm run-script test

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.