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

etpl-wrap

v0.2.1

Published

wrap the template engine [etpl] for node environment

Downloads

16

Readme

etpl-wrap etpl模板引擎的Node包装器

etpl-wrap用于包装etpl模板引擎,以便于在Node.js环境下使用。

etpl-wrap包装后,是独立的模板引擎,不依赖任何web框架,但又适用于任何框架。

详细使用文档

test目录下是一些测试代码及测试模板

为什么要包装etpl?

etpl是我用过的很出色的模板引擎,我想要的功能都有。

etpl本身是可以用在Node下的,但由于服务器环境和浏览器端天生不同,etpl更适合于浏览器端。

有些什么不同?

  1. 从后端语言的模板来讲,每个模板,一般就是一个文件,而不像浏览器端,需要显式的声明一个“模块”。如果接触后后端知识,比如JSP,就知道他们可以将几个模板文件互相include,组成想要的网页。

而etpl受JS的天生限制,没有直接compile/render一个文件的能力

  1. 后端语言的模板文件,在不同目录下当然允许重名。如根目录root下有list.html,root/content下也能有list.html,这是非常正常的需求,而且两个文件明显应该是不同的。

而在浏览器端,重名target是不允许的,要你自己规避target名称冲突的问题。

  1. 后端的模块是一个个文件,所以也就涉及到路径的问题。浏览器端没这个问题(虽然etpl支持把target name设为路径形式如:main/content/list,但这需要你自己命名)

  2. 由于文件之间天生独立的特性,所以在浏览器端,必要的target声明,在后端就不再需要的————每个模板文件就对应相应的target

使用方法

先安装etpl,再安装etpl-wrap,然后:

const ETPL = require('etpl-wrap');
let etpl = new ETPL('./views','.html')

new ETPL的参数依次是:模板文件根目录模板文件默认后缀名

此时就可以像在浏览器一样,使用etpl.render渲染对应模板了:

etpl.render('index', {
    title:'欢迎!',
    welcome:'非常欢迎你'
})

此代码即渲染了模板根目录下的index文件。

如果你要独立渲染子目录下的某模板,则:

etpl.render('content/list', data);

详细使用文档