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

@beforesemicolon/html-plus

v0.7.0

Published

HTML Template Engine/Language

Downloads

46

Readme

HTML+

HTML Template system to build websites

license npm Mac Build Linux Build

<variable name="page" value="$data.pages.home"></variable>

<include partial="layout" data="page">
    <!--  reference SASS, LESS, and STYLUS files directly  -->
    <link rel="stylesheet" href="./home.scss" inject-id="style">
    <link rel="stylesheet" href="./../node_modules/material/styles/theme.css" inject-id="style">
    
    <include partial="header"></include>
    <include partial="banner"></include>
    
    <section class="posts">
        <a #repeat="posts as post" href="{post.link}">
            <h2>{post.title}</h2>
            <h2>{post.thumbnail}</h2>
            <p>{post.description}</p>
        </a>
    </section>
    
    <include partial="footer"></include>
    
    <!--  reference typescript files directly  -->
    <link rel="stylesheet" href="./home.ts" inject-id="script">

</include>

Install

Install the engine inside your project directory.

npm install @beforesemicolon/html-plus

Basic Express Server Setup

You can get started quickly with express with this few lines of code:

// server.js
const express = require('express');
const http = require('http');
const path = require('path');
const {engine} = require('@beforesemicolon/html-plus');

const app = express();

(async () => {
  // initialize the engine by passing the express app
  // and the absolute path to the HTML pages directory
  // everything else is taken care of for you
  // from routing to processing linked files on your pages
  await engine(app, path.resolve(__dirname, './pages'));
  
  const server = http.createServer(app);
  
  server.listen(3000, () => {
    console.log('listening on port 3000');
  })
})()

With the above setup you can organize your html files in a structure that you would like your page routes to be.

The way you organize your page structure will be used to create your website route.

# File Structure             # Routes

- server.js
- pages
   - index.html                /
   - contact.html              /contact
   - about.html                /about
   - 404.html                  /404
   - projects
      - index.html             /projects
      - todo-project.html      /projects/todo-project

Template Tags & Attributes

HTML+ comes with couple of built-in tags that are meant to aid you with your pages. These are:

  • include: lets you include reusable partial html parts
  • inject: lets you inject html into partial files. Works like html slot
  • variable: lets you create scope data inside your template
  • fragment: lets you exclude the wrapping tag from rendering as a place to add logic

There are also some built-in attributes that let you control your tags even further. These are:

  • if: lets you conditionally render a tag
  • repeat: allows you to specify how the tag repeats bases on data you provide
  • fragment: has the same purpose as the tag version of it

These list have the potential to grow but you can also create your own tags and attributes that fits your project. You can come up with your own rules and behavior for the template and this is what makes HTML+ more appealing. It allows you to extend the template easily

Template Data Binding

HTML+ also lets you bind data from files directly into your templates. All data is scoped and immutable. This is done using curly braces. Take the following file structure as example:

- pages
    index.html
  data
    posts.json

You can reference the post.json file inside your template like so.

<div #repeat="$data.posts as post">
    <h2>{post.title}</h2>
    <p>{post.description}</p>
</div>

For special attributes you don't need the curly braces to bind data, but everywhere else you need to wrap your data reference inside curly braces. Check full DOC to learn more.