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

@journeyapps-solutions/cc-pdf-handlebars

v1.1.0

Published

Journey Apps Handlebars Util Module

Downloads

2,191

Readme

cc-util-handlebar

CircleCI

This is a implementation of unique reusable functions for Journey Apps. This module is considered compatible with sharedJS and CloudCode.

Any function that is deemed reusable and not available in lodash should/can be added here.

Familiarize yourself with the functions of Lodash https://lodash.com/

Usage

To use, add the following at the top of your Cloud Code or sharedJS

const ccPDFHandlebars = require('@journeyapps-solutions/cc-pdf-handlebars');
ccPDFHandlebars.init(handlebars); //Will add all the handlebars to the runtime

Modules

Format

Format is helpful to get the data to display correctly. Code Here

// All examples use the data below:
let _data = {
    example_date : new Date(1988,9,20),
    example_number: 100
} 

Format Dates

Format the date to default or custom format. The dates are formatted using node moment module.

{{format_date example_date}} //Output : 1988/10/20
{{format_date example_date "DD/MM/YYYY"}} //Output : 10/20/1988

//These are quick references to common formats
{{format_date_toEuropean example_date}} //Output : 20/10/1988
{{format_date_toAmerican example_date}} //Output : 20/10/1988
{{format_date_toSouthAfrican example_date}} //Output : 1988/10/20
{{format_date_toInternational example_date}} //Output : 1988/10/20

//You can also format time HH:mm
{{format_time example_date}} //Output : 00:00

Format Numbers

Formatting of numbers to limit the decimals

{{format_number_toFixed example_number 2}} //Output : 100.00

Operators

Operators will most likely be your most used helpers, They are extreamly valuable to add logic to your handlebars template. Code Here

Note: All Examples below are written to show the <h1>Display Me</h1> tag.

Default Known Operators

Available Operators:

  • eq (equal)
  • ne (Not Equal)
  • lt (Less Than)
  • gt (Greater Than)
  • lte (Less or Equal Than)
  • gte (Greater or Equal Than)
  • and (And)
  • or (Or)
//Quick Example
{{#if (eq "one" "one")}} <h1>Display Me</h1>{{/if}}
{{#if (ne "one" "two")}} <h1>Display Me</h1>{{/if}}
{{#if (lt 1 2)}} <h1>Display Me</h1>{{/if}}
{{#if (gt 2 1)}} <h1>Display Me</h1>{{/if}}
{{#if (lte 2 2)}} <h1>Display Me</h1>{{/if}}
{{#if (gte 2 2)}} <h1>Display Me</h1>{{/if}}
{{#if (and (eq "one" "one") (eq "two" "two"))}} <h1>Display Me</h1>{{/if}}
{{#if (or (eq "one" "one") (eq "one" "two"))}} <h1>Display Me</h1>{{/if}}

//Chaining Example
{{#if (and (gt 2 1) (or (eq "one" "one") (ne "one" "two")))}} <h1>Display Me</h1>{{/if}}

// As you can see you can chain all the operators using `and` or `or` 

Custom Operators

{{#if (isBlank "")}} <h1>Display Me</h1>{{/if}} //Checks if value is blank
{{#if (exists "")}} <h1>Display Me</h1>{{/if}} //Checks if value exists, opposite of isBlank
let example_data = [{id: 123, name: "James", state:"complete"},{id: 321, name: "Damian", state:"pending"},{id: 2133, name: "roger", state:"pending"}];

//Checks if the id is contained in the object array 
{{#if (includes_id example_data 123)}} <h1>Display Me</h1>{{/if}} 
let example_data = ["James", "Roger", "Mark","Polo"];

//Check if the object is contained in the array
{{#if (includes_item example_data "Roger")}} <h1>Display Me</h1>{{/if}}
let _multiChoice = [{key: "completed", display: "Completed"},{key: "pending", display: "Pending"},{key: "failed", display: "Failed"}]

//Check if the key is in the array, usefull for multiple selects
{{#if (includes_key _multiChoice "completed")}} <h1>Display Me</h1>{{/if}}

Filter

You want to filter something, we have got you covered. Code Here

You can filter by a specific field

let example_data = [{name:"James"},{name:"Justin"},{name:"Tammy"},];

<table>
    {{#each (filter_by_field example_data "name" "James" )}}
        <tr>
            <td>{{name}}</td>
        </tr>
    {{/each}}
</table>

You can filter by a specific field that uses key (Example: Singe Choice, Multi Choice)

let example_data = [{"state": {key: "completed", display: "Completed"}},{"state": {key: "pending", display: "Pending"}},{"state": {key: "failed", display: "Failed"}},];

<table>
    {{#each (filter_by_key example_data "state" "completed" )}}
        <tr>
            <td>{{state.display}}</td>
        </tr>
    {{/each}}
</table>

You can break down the array into groups for better display. Example, having only 2 photos per row. This is usefull in splitting up things that wont fit.

let example_data = ["Photo 1", "Photo 2", "Photo 3", "Photo 4"];

<table>
    {{#grouped_each example_data 2}}
    <tr>
        {{#each this}}
            <td>{{this}}</td>
        {{/each}}
        </tr>
    {{/grouped_each}}
</table>

PDF Sass

These are custom helpers to use with Rocket PDF. Code Here

Display a signature with a line below it safely

{{printSignature example_signature}} //Prints out the signature

When using checkbox (Docs Here) you can use the below helper to indicate a check.

let example_data = { sex: {
    key: "male",
    display: "Male"
}};

<div class="row-13">
    <label class="column-2 form-label">Male</label>
    <div class="column-10">
        <div class="checkbox {{isChecked sex.key "male"}} flush-left"></div>
    </div>
</div>
<div class="row-13">
    <label class="column-2 form-label">Female</label>
    <div class="column-10">
        <div class="checkbox {{isChecked sex.key "female"}} flush-left"></div>
    </div>
</div>

Documentation

All code is clearly documented, please see code for more details.

Installation

Per machine

yarn add @journeyapps-solutions/cc-pdf-handlebars --save

Per CloudCode task

yarn add @journeyapps-solutions/cc-pdf-handlebars

Deploying

yarn version

Development

This lib is meant to work for both CloudCode and SharedJs. What this means is that we need to ensure we only create functions that will work in both environments.

Every function must have a corresponding Unit Test.

Testing

We use tape and yarn to test the functions.

yarn test