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

boxwood

v0.80.0

Published

Compile HTML templates into JS

Downloads

125

Readme

boxwood

npm build

Server side templating engine written in JavaScript

boxwood was created to achieve the following design goals:

  1. templates can be split into components
  2. css is hashed per component
  3. css is automatically minified
  4. critical css is inlined
  5. templates can import other dependencies
  6. inline images or svgs
  7. i18n support
  8. server side
  9. good for seo
  10. small (1 file, 700 LOC~)
  11. easy to start, familiar syntax
  12. easy to test

The template starts with a standard js file, which builds a tree of nodes, that get rendered to html.

Table of Contents

Install

npm install boxwood

Usage

const { compile } = require("boxwood")
const { join } = require("path")
// ...
const path = join(__dirname, "index.js")
const { template } = compile(path)
// ...
const html = template({ foo: "bar" })
console.log(html)

You can use express-boxwood for express.

Syntax

// example/index.js
const layout = require("./layout")
const banner = require("./banner")

module.exports = () => {
  return layout({ language: "en" }, [
    banner({
      title: "Hello, world!",
      description: "Lorem ipsum dolor sit amet",
    }),
  ])
}
// example/layout/index.js
const { component, css, doctype, html, body } = require("boxwood")
const head = require("./head")

const styles = css.load(__dirname)

module.exports = component(
  ({ language }, children) => {
    return [
      doctype(),
      html({ lang: language }, [
        head(),
        body({ className: styles.layout }, children),
      ]),
    ]
  },
  { styles }
)
// example/layout/head/index.js
const { head, title } = require("boxwood")

module.exports = () => {
  return head([title("example")])
}
// example/banner/index.js
const { component, css, h1, p, section } = require("boxwood")

const styles = css.load(__dirname)

module.exports = component(
  ({ title, description }) => {
    return section({ className: styles.banner }, [
      h1(title),
      description && p(description),
    ])
  },
  { styles }
)
// example/banner/index.test.js
const test = require("node:test")
const assert = require("node:assert")
const { compile } = require("boxwood")

test("banner renders a title", async () => {
  const { template } = compile(__dirname)
  const html = template({ title: "foo" })
  assert(html.includes("<h1>foo</h1>"))
})

test("banner renders an optional description", async () => {
  const { template } = compile(__dirname)
  const html = template({ title: "foo", description: "bar" })
  assert(html.includes("<h1>foo</h1>"))
  assert(html.includes("<p>bar</p>"))
})

You can check the test dir for more examples.

Maintainers

@emilos

Contributing

All contributions are highly appreciated. Please feel free to open new issues and send PRs.

License

MIT