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

@justeat/f-templates-loader

v0.1.1

Published

Locate and register shared templates and data.

Downloads

29

Readme


npm version Build Status Dependency Status

Setup

Add f-templates-loader to your project:

yarn add @justeat/f-templates-loader

Then, inside your script import the functions you need from f-templates-loader.

const { getTemplateNames, getCompiledTemplate } = require('@justeat/f-templates-loader');

const templateNames = getTemplateNames();

templateNames.forEach(templateName => {
    const compiledTemplate = getCompiledTemplate(templateName);
    ...
});

Methods

getTemplateNames

Looks for directories in the root /templates directory and returns an array containing their names. An optional parameter can be passed in which takes a list of directory names which should not be included in result list.

getMainTemplate

Locate and return the main template content.

getTemplateTranslations

Locate and return any translations data associated with a template. Returns any translations data found, or an empty object.

getTemplateDocsData

Locate and return any docs data associated with a template. Returns any docs data found, or an empty object.

getCompiledTemplate

Internally, this function calls registerPartials, getMainTemplate, getTemplateTranslations, and getTemplateDocsData.

Compiles a template using data from translation and docs data.

registerPartials

Registers any partials associated with a template.

Template path and filename conventions

There are certain conventions which need to be followed in order for the templates to be compiled and the data to be loaded correctly.

All files should live inside a /templates directory in the root of your application, under this there should be a /resources directory which contains translations and docs data for your template, and a directory with the name of your template which contains the actual template files.

As they say, a picture is worth a thousand words:

Template folder structure

Main template

Format: /templates/{templateName}/index.hbs

The main template should be called index.hbs and should live in the root of a directory which has the name of the template.

Example: /templates/header/index.hbs.

Template partials

Format: /templates/{templateName}/partials/{templateName}-*.hbs

Partials should have the template name prefixed in the filename in order to avoid conflict between shared templates e.g. header-logo.hbs.

They should live in a directory called /partials inside your template directory.

Example: /templates/header/partials/header-logo.hbs

Translations

Format: /templates/resources/{templateName}.json

The translations should be called {templateName}.json and should live in the resources directory.

Example: /templates/resources/header.json.

Docs Data

Format: /templates/resources/{templateName}-docs-data.json

Any documentation data (data to be used purely in documentation) should be called {templateName}-docs-data.json and should live in the resources directory.

Example: /templates/resources/header-docs-data.json.