Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
simple management of helpers and partials for handlebars
Handlebars is super simple, but there's a learning curve to getting it set up with template files, helpers and partials.
A tool that provides:
The helpers provided are the ones in
Include the package:
npm i barbells
Then:
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)
For instance, {{capitalizeFirst 'just wow'}}
produces Just wow
and {{and value1 value2}}
will result in the value1 && value2
(useful for `{{#if}} for instance).
{{safe text}}
shows text
without escape characters. That is helpful if you are getting unwanted escapes of certain special characters such as quote marks.{{curly true}}
produces a left curly brace {
, {{curly false}} returns }
.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.
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:
This example shows some subdirectories and a number of examples. Many clauses that appear in multiple types of files are used.
#API
prepareHandlebars(projectDir: string)
Returns a handlebars with all of the built in and provided handlers and partials provided.
The projectDir
is the path to a directory containing optional partials
and handlers
folders.
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, typcially 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.
FAQs
[//]: # ( ns__file unit: standard, comp: README.md )
The npm package barbells receives a total of 8 weekly downloads. As such, barbells popularity was classified as not popular.
We found that barbells demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.