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 🙏

© 2025 – Pkg Stats / Ryan Hefner

html-maker

v1.3.2

Published

Yet another HTML builder

Downloads

23

Readme

html-maker

Minimalistic HTML builder based on space-pen. Intended to be used from CoffeeScript.

Installation

npm install html-maker --save

Examples:

Here's a CoffeeScript example. The html is generated by a function that is evaluated in the scope of an HtmlMaker instance, so it has access to methods for each HTML element through this:

HtmlMaker = require 'html-maker'
view = ->
  @h1 'Greetings'
  @div class: 'x', =>
    @span class: 'first', 'hi'
    @span class: 'second', 'there!'
  @p 'paragraph'
  @p =>
    @text 'yet'
    @b 'another'
    @text 'paragrah'
html = HtmlMaker.render view

The generated HTML text will be as follows (albeit without the indentation):

<h1>Greetings</h1>
<div class="x">
  <span class="first">hi</span>
  <span class="second">there!</span>
</div>
<p>paragraph</p>
<p>yet<b>another</b>paragrah</p>

Instead of evaluating the html-building closure in the scope of an HtmlMaker (i.e. having the builder in this), the builder can be passed as an argument to the closure by using render_external instead of render:

HtmlMaker = require 'html-maker'
view = (html) ->
  html.h1 'Greetings'
  html.div class: 'x', ->
    html.span class: 'first', 'hi'
    html.span class: 'second', 'there!'
  html.p 'paragraph'
  html.p ->
    html.text 'yet'
    html.b 'another'
    html.text 'paragrah'
html = HtmlMaker.render_external view

This form is more amenable to be used from JavaScript, but still not as nice:

var Maker = require('html-maker');
var view = function(html) {
  html.h1( 'Greetings' );
  html.div({ class: 'x' }, function() {
    html.span({ class: 'first' },  'hi' );
    html.span({ class: 'second' }, 'there!' );
  });
  html.p( 'paragraph' );
  html.p(function() {
    html.text( 'yet' );
    html.b( 'another' );
    html.text( 'paragrah' );
  });
};
var html = Maker.render_external(view);

Partial view helpers

Helper methods that generate partial view can be used with the render method:

form_field = (name) ->
  @p =>
    @text name
    @text ' '
    @input type: 'text', name: name

form = (action, fields) ->
  @form action: action, =>
    for field in fields
      @render form_field, field
    @input type: 'submit', value: 'Submit'

form_html = HtmlMaker.render form, 'send.address.com', ['name', 'address']

Result (indented):

<form action="send.address.com">
  <p>name <input type="text" name="name"></p>
  <p>address <input type="text" name="address"></p>
  <input type="submit" value="Submit">
</form>

If the alternative style using an HtmlMaker argument is desired we could have written:

form_field = (H, name) ->
  H.p ->
    H.text name
    H.text ' '
    H.input type: 'text', name: name

form = (H, action, fields) ->
  H.form action: action, ->
    for field in fields
      form_field H, field
    H.input type: 'submit', value: 'Submit'

form_html = HtmlMaker.render_external form, 'send.address.com', ['name', 'address']

Note the differences:

  • No fat arrows needed (for HtmlMaker's shake, maybe they're needed for other reason)
  • No internal render method needed

Data attributes

Data attributes can be defined in a single data object:

card = (name, address) ->
  @div data: { name: name, city: city }, =>
    @text name
console.log HtmlMaker.render card, 'John', 'Springfield'

Result:

<div data-name="John" data-city="Springfield">John</div>

Which is equivalent to:

card = (name, city) ->
  @div 'data-name': name, 'data-city': address, =>
    @text name

Note that data attribute names can use camelCase:

card = (name) ->
  @div data: { personName: name }, =>
    @text name
console.log HtmlMaker.render card, 'John'

And they will be automaticalley dasherized:

<div data-person-name="John">John</div>

Style attributes

Like data, style attributes can be defined with an object (and property names can be camelized as well):

card = (name) ->
  @div name,
    data: { personName: name }
    style:
      textAlign:  'center',
      lineHeight: '100px'
      border:     '10px solid blue'
console.log HtmlMaker.render card, 'John'

The result (formatted for convenience):

<div
  data-person-name="John"
  style="text-align: center; line-height: 100px; border: 10px solid blue">
  John
</div>