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

@superhero/core.handlebars

v2.3.0

Published

Addon module to add a handlebars template view to the superhero/core module

Downloads

199

Readme

Core › Handlebars

Licence: MIT


npm version

This is an addon module to the superhero/core module. This addon will add a handlebars view option.

Install

npm install @superhero/core.handlebars

...or just set the dependency in your package.json file:

{
  "dependencies":
  {
    "@superhero/core.handlebars": "*"
  }
}

Example Application

Example Application › File structure

src
├── api
│   └── foobar.js
├── view
│   ├── foobar.hbs
│   └── layout.hbs
├── config.js
├── index.js
└── package.json

package.js

{
  "name": "Super Duper App",
  "version": "0.0.1",
  "description": "An example meant to describe the libraries fundamentals",
  "license": "MIT",
  "dependencies": {
    "superhero": "*",
    "@superhero/core.handlebars": "*"
  }
}

config.js

module.exports =
{
  handlebars:
  {
    partials:
    {
      layout  : 'view/layout'
    }
  },
  core:
  {
    http:
    {
      server:
      {
        routes:
        {
          'create-calculation':
          {
            url       : '/',
            method    : 'get',
            view      : '@superhero/core.handlebars',
            input     : false,
            template  : 'view/foobar',
            endpoint  : 'api/foobar'
          }
        }
      }
    }
  }
}

index.js

const
CoreFactory = require('superhero/core/factory'),
coreFactory = new CoreFactory,
core        = coreFactory.create()

core.add('api')
core.add('@superhero/core.handlebars')

core.load()

core.locate('bootstrap').bootstrap().then(() =>
core.locate('core/http/server').listen(80))

api/foobar.js

const Dispatcher = require('superhero/core/http/server/dispatcher')

class FoobarEndpoint extends Dispatcher
{
  async dispatch()
  {
    // Building a view model that we can use to render the view
    this.view.body.foo = 'bar'
  }
}

module.exports = FoobarEndpoint

view/layout.hbs

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>{{ title }}</title>
  </head>

  <body>
    <main>
      {{> @partial-block }}
    </main>
  </body>
</html>

view/foobar.hbs

{{#> layout title="Insert awesome title for the page here" }}
  <p>
    Write your markup here with support for variables, eg: "{{ foo }}"
  </p>
{{/ layout }}

Config overview

module.exports =
{
  handlebars:
  {
    // optional base path parameter that can be utelised to set the prefixed directory path for all view templates
    basepath: '',
    // The library has a few defined core helpers that are activated by default, but can be deactivated with a falsy flag
    helpers:
    {
      'calculate'       : '@superhero/core.handlebars/helper/calculate',
      'case'            : '@superhero/core.handlebars/helper/case',
      'concat'          : '@superhero/core.handlebars/helper/concat',
      'dateformat'      : '@superhero/core.handlebars/helper/dateformat',
      'escDoubleQuote'  : '@superhero/core.handlebars/helper/esc-double-quote',
      'escSingelQuote'  : '@superhero/core.handlebars/helper/esc-singel-quote',
      'if'              : '@superhero/core.handlebars/helper/if',
      'jsonStringify'   : '@superhero/core.handlebars/helper/json-stringify',
      'math'            : '@superhero/core.handlebars/helper/math',
      'padEnd'          : '@superhero/core.handlebars/helper/pad-end',
      'padStart'        : '@superhero/core.handlebars/helper/pad-start',
      'replace'         : '@superhero/core.handlebars/helper/replace',
      'slice'           : '@superhero/core.handlebars/helper/slice',
      'stripTags'       : '@superhero/core.handlebars/helper/strip-tags',
      'substr'          : '@superhero/core.handlebars/helper/substr',
      'switch'          : '@superhero/core.handlebars/helper/switch',
      'toFixed'         : '@superhero/core.handlebars/helper/to-fixed',
      'toLowerCase'     : '@superhero/core.handlebars/helper/to-lower-case',
      'toUpperCase'     : '@superhero/core.handlebars/helper/to-upper-case',
      'trim'            : '@superhero/core.handlebars/helper/trim',
      'unless'          : '@superhero/core.handlebars/helper/unless'

      // You can add a custom helper by specify it's name and the path to the service that returns a helper function through the method: "create"
      // example:
      // 'customHelper'    : 'path-to-helper'
    },
    partials:
    {
      // it's possible to register partials to be loaded and used through-out the application
      // example:
      // foo  : 'view/foobar'
    }
  }
}