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

assam.js

v1.0.0

Published

assam.js is an implementation of the mustache(that's right, not assam) template system in JavaScript.

Downloads

1

Readme

如何使用

1.要在项目中引入assam, 可以使用bower:

$ bower install --save assam.js

assam默认依赖jQuery. 你也可以选用其它的库

2.你也可以使用npm进行安装

$ npm install assam.js --save

运行测试

要运行项目中的测试用例, 你可以:

$ npm test

或者:

$ make test

语法

因为这个前端渲染引擎直接使用了Mustache的语法,而没有自己再设计一套,所以语法完全可以直接参照这里

实现方法

  1. 首先在一开始将所有partials替换到应有的位置,然后将所有comment取出,这两部类似于预处理,仅仅是对原模板进行一些文本上的替换和删减
  2. 然后到了核心的renderSection部分。之所以说它核心是因为我们可以将对模板的处理过程近似看作是对renderSection的递归调用。伴随着renderSection递归调用过程的,是上下文的切换。上下文是随着一层层section的深入而同时一层层地解引用的。递归总会有个终止条件,而这里的终止条件就是当再也发现不了section的时候,引擎就会去调用renderVariable,根据上下文对变量做替换,非常容易理解。
  3. 需要说明的是,这里对inverted section的处理使用了lazy evaluation的方式,也就是说,先不碰inverted section的标签,直到所有内容(包括inverted section里面的内容)都已经渲染完之后,再根据inverted section的tag的值判断显不显示其中的内容。如果不是lazy evaluation,则需要在每次调用renderSection之前,先检查是否有inverted section的存在,这样就多了不少处理。使用lazy evaluation虽然会潜在地多做一些无用的工作,但在处理上来说会容易很多。
  4. 对于variable的处理基本就是在当前上下文中找变量