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

laytpl

v2.0.0

Published

Node.js view engine

Downloads

72

Readme

介绍 - Introduce

laytpl 是一款轻量的 JavaScript 模板视图引擎,能同时运行在浏览器端及 Node.js 端,且对 Express 框架无缝兼容,模版语法遵循原生 JavaScript。

安装 Installation

$ npm install laytpl

语句 - Grammar

  • 转义输出(即转义 HTML) : {{= d.field }}
  • 原文输出(即渲染 HTML) : {{- d.field }}

兼容性重要提示1.x 版本的 {{ d.field }} 等同于原文输出,因此若升级到 2.x,需按照新版分隔符进行语句适配。

  • 逻辑语句 : {{# JavaScript statement }}
  • 忽略解析 : {{! content !}} 如:
{{! 
  {{= d.key }} 则不会解析这中间的内容,原字符输出
!}} 

使用 - Usage

此处只演示 Express 下的使用方式

第一步

在项目入口指定 view engine,并且定义模版文件扩展名为 .html

var express = require('express');
var app = express();

var laytpl = require('laytpl');
app.engine('.html', laytpl.__express);
app.set('view engine', 'html');

第二步

在视图文件中书写模板,支持 include 导入子模板,文件扩展名可省略。

{{# if (d.user) { }}
  <h2>{{= d.user.name }}</h2>
{{# } >>
<p>{{= d.intro }}</p>

{{- include footer }}

第三步

渲染

app.get('/', function(req, res){
  res.render('index', {
    user: {name: 'sents'},
    intro: 'a developer from China'
  });
});

自定义分隔符 - Custom delimiters

Custom delimiters can also be applied globally:

laytpl.config({
  open: '{{',
  close: '}}'
});

缓存 - cache

laytpl 默认不开启缓存,这在你开发时非常有利。但是当你的模版足够稳定,你如果需要开启该项,只需要按以下设置即可:

laytpl.config({
  cache: true
});

开启缓存后的渲染速度将会得到极大的提升。

压缩 - min

laytpl.config({
  min: true
});

协议 - License

The MIT License