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

chibiprint

v1.0.0-final.1511271807

Published

A really tiny template engine for Node.js.

Downloads

2

Readme

ChibiPrint

A really tiny template engine for Node.js. It takes a template file and a JSON data file and produces a rendered string. ChibiPrint templates can include other template files, too!

Installation

npm install -g chibiprint

Using ChibiPrint from the command line

Printing the rendered output:

chibiprint template.html data.json

Writing the output to a file:

chibiprint template.html data.json output.html

Using ChibiPrint as a JavaScript module

var fs = require("fs");
var render = require("chibiprint").render;
var data = JSON.parse(fs.readFileSync("data.json"));

fs.writeFileSync("output.html", render("template.html", data));

Template example

File data.json:

{
    "title": "My cool blog",
    "posts": [
        {
            "title": "Today I ate noodles",
            "text": "They were really delicious. I can recommend it.",
            "tags": [
                "noodles", "delicious"
            ]
        },
        {
            "title": "Went to see Iron Maiden",
            "text": "Best. Concert. Ever. 'Nough said."
        }
    ]
}

File template.html:

{!include header.html}
        <h1>{$title}</h1>
        
        <div class="posts">
            {!list $posts post.html}
        </div>
    </body>
</html>

File header.html:

<!DOCTYPE html>
<html>
    <header>
        <title>{$title}</title>
    </header>
    <body>

File post.html:

            <div class="post">
                <h2>{$title}</h2>
                <div class="body">
                    {$text}
                </div>
                {!? $tags include tags.html}
            </div>

File tags.html:

                <div class="tags">
                    {!list $tags tag.html}
                </div>

File tag.html:

                    <a class="tag" href="tag/{$content}/">{$content}</a>

Syntax

{$[variable name]}

Prints the content of a variable. If the variable doesn't exist, nothing is printed.

{!list [variable] [template file]}

The list command renders the items in an array or object using another template file.

If the item itself is an object, the object's properties are available in the list template as variables. The parent template's variables are available in the list template prefixed with "parent.", e.g. {$parent.title}.

If the item is a primitve value like string or number, {$key} can be used for the item's key or index, and {$content} prints the item's value.

{!include [template file]}

The include command renders another template with the current template's variables.

{!? $[variable name] [command name] [arg1] ... [argN]}

The ? command executes another command with arg1 to argN as the arguments if the specified variable exists and is truthy.

Adding new commands

You can extend ChibiPrint by adding new commands it can utilize:

var render = require("chibiprint").render;

render.commands["hello-world"] = function (base, vars /*, arg1, ..., argN */) {
    
    // base is the base path / folder of the current template
    // vars is an object containing the available variables
    
    // commands can have any number of optional arguments
    
    // commands must return a string:
    return "Hello world!";
};

API

render(templateFile, data)

Renders the file located at templateFile using the key-value pairs in data as variables.

render.commands

The available commands. This object can be extended to add new commands to ChibiPrint.

engine()

Creates a new render function. This is useful if you want to have render functions with a different command vocabulary.

License

BSD-3-Clause. See LICENSE file for details.