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

higanbana

v1.0.12

Published

A template engine of express framework

Downloads

27

Readme

Higanbana Template Engine

A template engine of express framework

You cand add properties to html tags to render templates, like :

<a href="{{urls.home}}">Home</a>
<a href="{{urls.login}}" hi-if="session.user">Login</a>

中文文档

Install

npm install --save higanbana

And then, you can configure your template engine in express like :

app.engine('html', require('higanbana')())		//not only "html", others are ok

For more information, see http://expressjs.com

Usage - Print

Using {{ $val }} to print a value to html,like:

<div>{{user.name.first}} {{user.name.last}}</div>

And you can write expressions into {{}}, such as:

<div>{{num1}} + {{num2}} = {{num1 + num2}}</div>

Usage - Conditions

Add hi-if、hi-else、hi-show、hi-hide properties on html tag to set if the tag will be rendered, Examples:

<div>
	<!-- ony if -->
	<div hi-if="a>0">a is great than 0</div>

	<!-- if and else -->
	<div hi-if="a>0">a is great than 0</div>
	<div hi-else="a==0">a is equals to 0</div>  <!-- hi-else="xxxx" means else if -->
	<div hi-else>a is little than 0</div>        <!-- hi-else means else -->

	<!-- show and hide -->
	<div hi-show="a==40">a is equals to 40</div>
	<div hi-hide="a==40">a is not equals to 40</div>
<div>

Usage - Loop

Using hi-for property to print a array, a object, a string, a range.

if a number is given, that means a range of [0~n).

Examples:

<!-- print array without index -->
<table>
	<tr hi-for="user in users">
		<td>{{user.id}}</td>
		<td>{{user.name}}</td>
	</tr>
</table>

<!-- print array with index -->
<table>
	<tr hi-for="(user, index) in users">
		<td>{{index+1}}</td>
		<td>{{user.id}}</td>
		<td>{{user.name}}</td>
	</tr>
</table>

<!-- print object without keys -->
<div hi-for="item in userInfo">
	{{item}}
</div>

<!-- print object with keys -->
<div hi-for="(item, key) in userInfo">
	{{key}}:{{item}}
</div>

<!-- and more -->
<table>
	<tr hi-for="(item, key) in users.filter(u=>u.gender=='男')">
		<td>{{index+1}}</td>
		<td>{{user.id}}</td>
		<td>{{user.name}}</td>
	</tr>
</table>

<!-- using range -->
<div hi-for="num1 in 4">  <!-- 0, 1, 2, 3 -->
	<div hi-for="num2 in -4" style="display:inline-block; width:100px"> 	<!-- 0, -1, -2, -3 -->
		<span>{{ num1 }}</span>
		<span>{{ (num2>=0) ? '+' : '-' }}</span>
		<span>{{ Math.abs(num2) }}</span>
		<span>=</span>
		<span>{{ num1+num2 }}</span>
	</div>
</div>

<!-- characters of string -->
<span hi-for="ch in 'ABCDE'" style="padding:0 5px;">{{ch}}</span>

Usage - Range

Using mkrange(from:number, to?:number):Array function to create a range, like:

mkrange(1, 3)               // 1, 2
mkrange(3)                  // 0, 1, 2
mkrange(3, 0)               // 3, 2, 1

Example:

<div hi-for="number in mkrange(10)">{{number}}</div>

Usage - Value

Using val(v:any):any function, you can create any value, but it is not a good idea, so, stop! stop! stop!:

<!-- loop A-G -->
<div hi-for="(ch, N) in val('ABCDEFG')">
	{{N+1}}:{{ch}}
</div>

Usage - import other templates

If you have other templates, you can use require tag to import them, such as:

<require path="./../lib/header.html"/>

Attentions

  • A html tag only has a condition property ( one of hi-if、hi-else、hi-show、hi-hide)
  • If you use hi-for and hi-if (or other condition property), hi-for will be done before hi-if
  • require tag must be closed (<require path="..." /> or <require path="..."></require>”)