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

hotmess

v0.0.3

Published

Javascript templating engine focused on minimalism and performance.

Downloads

5

Readme

#Hotmess.js

Hotmess is a javascript templating engine focused on minimalism and performance.

##Features

  • Stupid fast!
  • Tiny! ~60 loc and <1kb minimized.
  • Use in the client and server.
  • Logic-less! With support for list iteration, "truthy" conditionals and default values.
  • Partials! Reuse templates and keep them concise.

##Usage

Include the script in your page:

<script src="https://rawgithub.com/rlauck/hotmess/master/hotmess.js">

Creating and rendering a template is as simple as:

var tmpl = hotmess.compile("<p>I'm afraid I just {{color}} myself</p>");
document.body.innerHTML = tmpl( {color:"blue"} );

###Variables

Variable tags render the named key from the current object/context. All variables are HTML escaped but can be rendered raw by prepending an {{& ampersand }}.

Code:

var data = {
  name: "Gob Bluth",
  job: "<b>magician</b>"
};
var out = hotmess.compile( "A {{&job}} never reveals his secrets! -{{name}}" )(data);

Output:

A <b>Magician</b> never reveals his secrets! -Gob Bluth

If a variable does not exist, nothing will be rendered unless you provide a default value. Surround default strings with quotes, or leave them off to name a different key as the default.

Code:

var tmpl = hotmess.compile( '{{yep}}, {{nope : "missing"}}, {{nope:meh}}' );
var out = tmpl({
  yep: "yep",
  meh: "well... ok"
});

Output:

yep, missing, well... ok

###Arrays

Arrays are iterated with the {{~list}} tag. A plain {{~}} tag closes the list and the inner template is repeated for each array element. The context in the inner template is set to each array element and is accessible with the equivalent {{this}} or {{.}} tag. Properties of the parent tag are accessed with the ../ prefix such as {{../parent_property}}.

First a simple example.

Code:

var tmpl = hotmess.compile( "{{~names}}{{.}} {{~}}" );
document.body.innerHTML = tmpl( { names: ["George", "Buster", "Lucille"] } );

Output:

George Buster Lucille

Now something more complex.

Template:

<ul>
{{~ names}}
  <li style="{{ style() }}">{{name}} {{../surname}}</li>
{{~}}
</ul>

Data:

{
  surname: "Bluth",
  
  names: [
    { name: "George", gender: "m" },
    { name: "Buster", gender: "m" },
    { name: "Lucille", gender: "f" }
  ],
  
  style: function(value, i) {
    // yep, you can call methods too
    
    var style = value.gender == "f" ? "color:pink;" : "color:blue;";
    
    // bold every other row
    if( i % 2 == 0 ){
      style += "font-weight:bold;";
    }
    
    return style;
  }
}

Output:

<ul>
  <li style="color:blue;font-weight:bold;">George Bluth</li>
  <li style="color:blue;">Buster Bluth</li>
  <li style="color:pink;font-weight:bold;">Lucille Bluth</li>
</ul>

###Conditionals

TODO: work in progress

###Partials

Any template may be called from within another template. There are some caveats currently:

  • The partial template must be compiled before the parent template is rendered.
  • No effort is made to prevent circular references, so infinite loops are possible.
  • The partial name refers to a variable in the global scope - this will change soon.

Syntax: {{>partial}}

TODO: create examples

##Benchmarks

I hope to create some more rigorous benchmarks but for now I created a variant of the popular Javascript template language shootoff jsPerf.

##About

I began this project to see how small and fast I could make a full featured template function. Hotmess is MIT Licensed and based on doT and Mustache.