eta (Ξ·)
Documentation - Chat - RunKit Demo - Playground
Summary
Eta is a lightweight and blazing fast embedded JS templating engine that works inside Node, Deno, and the browser. Created by the developers of Squirrelly, it's written in TypeScript and emphasizes phenomenal performance, configurability, and low bundle size.
π Features
π¦ 0 dependenciesπ‘ 2.3KB minzipped; size restricted to <3KB forever with size-limitβ‘οΈ Written in TypeScriptβ¨ Deno support (+ Node and browser)π Super Fastπ§ Configurable- Plugins, custom delimiters, caching
π¨ Powerful- Precompilation, partials, async
- Layout support!
π₯ Reliable- Better quotes/comments support
- ex.
<%= someval + "string %>" %>
compiles correctly, while it fails with doT or EJS
- ex.
- Great error reporting
- Better quotes/comments support
β‘οΈ Exports ES Modules as well as UMDπ Easy template syntax
Where did Eta's name come from?
"Eta" means tiny in Esperanto. Plus, it can be used as an acronym for all sorts of cool phrases: "ECMAScript Template Awesomeness", "Embedded Templating Alternative", etc....
Additionally, Eta is a letter of the Greek alphabet (it stands for all sorts of cool things in various mathematical fields, including efficiency) and is three letters long (perfect for a file extension).
Integrations
Visual Studio Code
@shadowtime2000 created eta-vscode.
ESLint
eslint-plugin-eta was created to provide an ESLint processor so you can lint your Eta templates.
Webpack
Currently there is no official Webpack integration but @clshortfuse shared the loader he uses:
{
loader: 'html-loader',
options: {
preprocessor(content, loaderContext) {
return eta.render(content, {}, { filename: loaderContext.resourcePath });
},
},
}
π Docs
We know nobody reads through the long and boring documentation in the ReadMe anyway, so head over to the documentation website:
π Examples
Simple Template
import * as Eta from "eta";
var myTemplate = "<p>My favorite kind of cake is: <%= it.favoriteCake %></p>";
Eta.render(myTemplate, { favoriteCake: "Chocolate!" });
// Returns: '<p>My favorite kind of cake is: Chocolate!</p>'
Conditionals
<% if(it.somevalue === 1) { %>
Display this
<% } else { %>
Display this instead
<% } %>
Loops
<ul>
<% it.users.forEach(function(user){ %>
<li><%= user.name %></li>
<% }) %>
</ul>
Partials
<%~ include('mypartial') %>
<%~ includeFile('./footer') %>
<%~ include('users', {users: it.users}) %>
βοΈ Tests
Tests can be run with npm test
. Multiple tests check that parsing, rendering, and compiling return expected results, formatting follows guidelines, and code coverage is at the expected level.
Resources
To be added
eta
Projects using - Docusaurus v2: open-source documentation framework that uses Eta to generate a SSR build
- swagger-typescript-api: Open source typescript api codegenerator from Swagger. Uses Eta as codegenerator by templates
- html-bundler-webpack-plugin: Webpack plugin make easily to bundle HTML pages from templates, source styles and scripts
- SmartDeno: SmartDeno is an easy to setup web template using Deno & Oak
- Add yours!
Contributors
Made with
Ben Gubler |
Clite Tailor |
Ioan CHIRIAC |
Craig Morten |
Rajan Tiwari |
shadowtime2000 |
Hamza Hamidi |
Calum Knott |
nhaef |
GΓΌn |
This project follows the all-contributors specification. Contributions of any kind are welcome!
Credits
- Async support and file handling were added based on code from EJS, which is licensed under the Apache-2.0 license. Code was modified and refactored to some extent.
- Syntax and some parts of compilation are heavily based off EJS, Nunjucks, and doT.