atlatl
v5.6.1
Published
Atlatl is a templating language for Node. It is inspired by Jinja and Laravel's Blade.
Downloads
67
Readme
Atlatl
Atlatl is a templating language for Node. It is inspired by Jinja and Laravel's Blade.
It could be thought of as a superset of ES6 template strings that adds object oriented features, logic, and default escaping of html.
It looks like this.
@partial title (title)
<title>${ title }</title>
@
<!doctype html>
<html>
<head>
@yield head
</head>
<body>
@section main
${ safe(content.content) }
@
</body>
</html>
@extends layout.html
@section head
@call title ('Posts')
@
@section main
<ul>
@each content.posts (post)
<li><a href="${ post.permalink }">${ safe(post.title) } — ${ post.date }</a></li>
@
</ul>
@
Lines that begin with an @ are called directives. Some directives are one line. Others are blocks and must be closed with a line with just an @.
HTML output by ES6 templates' ${ ... }
is escaped by default but the safe
function can be used to mark code to not escape.
The Directives
Logic and Loops
@each var (val, [key])
Loops through an array. Block level.
@if (condition)
Just like any other if statement. Block level.
Methods
@partial name ([arg1, [ ...argN]])
Defines a method that can be called with @call
. Block level.
@call name ([arg1, [ ...argN]])
Calls a method. If it is not defined an error will occur.
@section name
Defines and calls a method that can be overridden when the template is extended. Block level.
@yield name
Defines and calls a method. A placeholder. Great for templates that are meant to be extended.
Inheritance
@extends template
Used to extend another template. The methods (sections and partials) in the extending template override methods in the extended template and any output outside of methods is ignored.
@import name template [method]
Can import partials or sections (any method) from another file. Use method
to rename the method being imported. If method
is not set then the name as defined is used.
@parent [name] ([arg1, [ ...argN]])
In a template that extends another template it calls an overridden method. If name
is not defined it calls the same method in which it appears.
The Result
Each template is transformed into a CommonJS module that exports a class.