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

atpl

v0.9.3

Published

A complete and fast template engine fully compatible with twig and similar to jinja with zero dependencies.

Downloads

5,052

Readme

Build status on Travis:

Version Build Status

Install with NPM:

npm install atpl

Using with express3:

app.engine('html', require('atpl').__express);
app.set('devel', false);
app.set('view engine', 'html');
app.set('view cache', true);
app.set('views', __dirname + '/templates');

app.get('/simple', function(req, res) {
	res.render('simple', { name : 'Test' });
});

Using as standalone:

var atpl = require('atpl');
console.log(atpl.renderFileSync(__dirname + '/views', 'simple.html', { name: 'MyName' }, false));
atpl.renderFile(__dirname + '/views', 'simple.html', { name: 'MyName' }, false), function(err, result) {
	console.log(result);
});

Typescript typings: https://github.com/soywiz/atpl.js/blob/master/lib/atpl.d.ts

This project is designed to be compatible with twig. So the documentation about tags, filters, functions and tests is on the twig page:

  • http://twig.sensiolabs.org/documentation

I have continued working on it because there are several projects implementing twig templates but they are not implemented very well and lacks stuff like multiple inheritance or nesting blocks, or are slow because doesn't perform dynamic recompilation.

This project will implement the full twig set and will be as fast as possible.

Supported syntax:

  • Inheritance
  • Conditional inheritance
  • Include
  • if+elseif+else
  • for+else+loop scope variable
  • Auto-escape
  • Escape (|e) (|e('js')) (|e('css'))...
  • Skip autoescape (|raw)
  • Filters (all twig filters but 'convert_encoding' that is not required because javascript strings are unicode)
  • Functions (all twig functions but 'constant')
  • Tests (all twig tests but 'constant')
  • Tags (all twig tags)
  • value in array
  • value in string
  • set a, b = 'a', 'b'
  • macro support (macro+import+from)
  • sandbox
  • use (horizontal reuse)
{% autoescape %}
{% autoescape 'type' %}
{% extends "file.atpl" %}
{% extends cond ? "base1" : "base2" %}
{% include "template" %}
{% include "template" with { 'foo' : 'bar' } only %}
{% block name %}...{% endblock %}
{% for var in list %}...{% endfor %}
{% for var in list %}...{% else %}...{% endfor %}
{% for key, value in list %}...{% else %}...{% endfor %}
{% for key, value in list if condition %}...{% else %}...{% endfor %}
{% for key in ['a', 'b', 'c'] %}{{ loop.index0 }}{% endfor %}
{% if condition %}...{% else %}...{% endif %}
{% if cond1 %}...{% elseif cond2 %}...{% else %}...{% endif %}
{% set a, b = 'a', 'b' %}
{{ expression }}
{{ expression|filter }}
{{ expression|filter(params) }}
{{ function(params) }}
{{ var is even }}
{{ var is not defined }}
{{ var is sameas(var) }}
{{ var.array['access'] }}
{{ 3 in [1, 2, 3, 4] }}
{{ {'key':'value','key2':'value2'} }}