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

barbells

v1.4.0

Published

[//]: # ( ns__file unit: standard, comp: README.md )

Downloads

26

Readme

simple file management for handlebars, including helpers, partials and template files

codecov Version Downloads/week License

Geenee Template

:clipboard: Why

Handlebars is super simple, but there's a learning curve to getting it set up with template files, helpers and partials.

:white_check_mark: What

A tool that provides:

  1. the popular libraries of helpers out of the box
  2. automatic registration of custom helpers and partials
  3. a tool for loading a template from a file.

:wrench: Basic Usage

Include the package:

npm i barbells

Then:

  1. create a handlebars instance with all the handlebars helpers and partials for the project;
  2. use it by loading a template from a file.
const {prepareHandlebars} = require('barbells')
const {loadFileTemplate} = require('barbells')
const projectDir = "path/to/parentDir" // where parentDir has optional `partials` and `helpers` directories

const Handlebars = await prepareHandlebars(projectDir)

const myContext = {foo: "bar"}  // an object with whatever you want...
cond pathString = "~/templates/myTemplate.hbs"

const fileTemplate = await loadFileTemplate(pathString, null, Handlebars)

const fileText = await fileTemplate(context)

:paperclip: Built In Handlers

  1. You have full use of two packages of helpers:
  1. There are a few added helpers, really just for legacy usage:
    • {{safe text}} shows text without escape characters. That is helpful if you are getting unwanted escapes of certain special characters such as quote marks.
    • {{openCurly}} produces a left curly brace {, {{closeCurly}} returns }.

And if you want to use this with a geenee template you can add the geenee abbreviations as well.

:thumbsup: Adding Helpers

  1. The helpers directory should contain any additional helpers that you create. Since geenee-rate is written with typescript, your helpers should be in typescript as well, with a .ts extension.

    See this example for some ideas.

:computer: Adding Partials

You have access everywhere to the full list of partials in the partials directory. A partial is specified within a Handlebars file of the same name (not counting the file extension). You can add as many as you like, and create as many subdirectories as you need. But, there are two naming constraints:

  1. The name of each partial must be unique.
  2. Each partial file should have an '.hbs' extension.

This example shows some subdirectories and a number of examples. Many clauses that appear in multiple types of files are used.

:ledger: API

prepareHandlebars function

prepareHandlebars(projectDir: string) 

Returns a handlebars with all the built-in and provided handlers and partials provided.

The projectDir is the path to a directory containing optional partials and handlers folders.

loadFileTemplate function

async function loadFileTemplate(
  pathString: string, 
  Handlebars: any, 
  fileFilter: string|null, noFileInfo = false
)

The pathString tells where the template to load is stored. The file contains the contents of the template.

The Handlebars is a handlebars instance, typically created with prepareHandlebars.

You can optionally provide a fileFilter string to loadFileTemplate which is a glob. barbells will then prepare a template for use in with the geenee-rate generator by adding a geenee file info tag at the beginning of the template whenever a filename matches the fileFilter.

noFileInfo suppresses generation of a file info tag even if the filename matches the fileFilter.