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

@crster/htmlike

v2.0.1

Published

html like template engine with added magic

Downloads

1

Readme

HTMLike

Htmlike is a template engine primarily used in expressjs

Syntax Example

<view {layout}>
    <block {body}>
        <p>This will be rendered inside "layout > body" block</p>
        <p>{variable.name} passed from render()</p>
    </block>

    <!-- This is a for loop sample -->
    <ul>
        <for {animal of animals}>
            <li>{animal}</li>
        </for>
    </ul>
</view>

Quick Start

Installation

npm install @crster/htmlike

nodejs

    var htmlike = require('@crster/htmlike');

    var data = { world: "Template engine" }
    var output = htmlike.render('<p>Hello {world}</p>', data);

    // <p>Hello Template engine</p>

express

    const express = require("express")
    const htmlike = require("@crster/htmlike")

    const app = express()

    app.engine("html", htmlike.expressViewEngine)
    app.set("view engine", "html")
    app.set("views", "./src/views")

Render Expression

<p>One + Two = {1 + 2}</p>

Escape Expression

<p>use this {{"Hello"}}</p>

// will be rendered to

<p>use this {Hello}</p>

Render List

<for {user of users}>
    <p>{user.name}</p>
</for>

Render Condition

<switch {users.length}>
    <case {0}>
        <p>No result found</p>
    </case>
    <case {1}>
        <p>The choosen one</p>
    </case>
    <case {5}>
        <p>The best five</p>
    </case>
    <case {}>
        <p>This is switch default</p>
    </case>
</switch>

// To render if else like statement
<switch {!!users}>
    <case {true}>
        <p>User is not null</p>
    </case>
    <case {false}>
        <p>User is null</p>
    </case>
</switch>

Whitelisted tags

<script>, <noscript>, <style> and <pre> are whitelisted. meaning braces {} will work as usual. to render the expression inside you must use two braces {{}}

data is { name: "Doe" }

<script>
  let name = "John";
  let alias = `${name}-{{name}}`;
</script>

// will render to
<script>
  let name = "John";
  let alias = `${name}-Doe`;
</script>

Render Layout + Extending Block

Create layout.chtml

<!-- This code inside layout file -->
<html>
    <head>
        <block {css}>
            <style>
                body {
                    color: blue;
                }
            </style>
        </block>
    </head>
    <body>
        <block {body}/>
        <block {script}/>
    </body>
</html>

Create welcome.chtml

<view {layout}>
    <block {css}>
        <style>body { color: red }</style>
    </block>

    <block {body}>
        <p>Markup goes here!</p>
    </block>
</view>