All Projects → eta-dev → Eta

eta-dev / Eta

Licence: mit
Embedded JS template engine for Node, Deno, and the browser. Lighweight, fast, and pluggable. Written in TypeScript

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to Eta

Windowstemplatestudio
Windows Template Studio quickly builds a UWP app, using a wizard-based UI to turn your needs into a foundation of Windows 10 patterns and best practices.
Stars: ✭ 2,089 (+796.57%)
Mutual labels:  template-engine
Gotemplatebenchmark
comparing the performance of different template engines
Stars: ✭ 180 (-22.75%)
Mutual labels:  template-engine
Fatfree
A powerful yet easy-to-use PHP micro-framework designed to help you build dynamic and robust Web applications - fast!
Stars: ✭ 2,504 (+974.68%)
Mutual labels:  template-engine
Dwoo
[UNMAINTAINED] php template engine
Stars: ✭ 164 (-29.61%)
Mutual labels:  template-engine
Express Es6 Template Engine
Rendering engine for Express that uses ES6 javascript string templates as syntax.
Stars: ✭ 175 (-24.89%)
Mutual labels:  template-engine
Elefant
Elefant, the refreshingly simple PHP CMS and web framework.
Stars: ✭ 188 (-19.31%)
Mutual labels:  template-engine
Foil
PHP template engine for native PHP templates
Stars: ✭ 162 (-30.47%)
Mutual labels:  template-engine
Pupa
Simple micro templating
Stars: ✭ 231 (-0.86%)
Mutual labels:  template-engine
Microconfig
Modern tool for microservice configuration management
Stars: ✭ 180 (-22.75%)
Mutual labels:  template-engine
Ructe
Rust Compiled Templates with static-file handling
Stars: ✭ 206 (-11.59%)
Mutual labels:  template-engine
Craftsman
Craftsman is the workhorse behind the Wrapt framework and provides a suite of CLI commands for quickly scaffolding out new files and projects for your .NET Web APIs with simple CLI commands and configuration files.
Stars: ✭ 165 (-29.18%)
Mutual labels:  template-engine
Quicktemplate
Fast, powerful, yet easy to use template engine for Go. Optimized for speed, zero memory allocations in hot paths. Up to 20x faster than html/template
Stars: ✭ 2,287 (+881.55%)
Mutual labels:  template-engine
Yarte
Yarte stands for Yet Another Rust Template Engine
Stars: ✭ 189 (-18.88%)
Mutual labels:  template-engine
Spring Boot Email Tools
A set of services and tools for sending emails in a Spring Boot 1.5.x application using a Template Engine
Stars: ✭ 164 (-29.61%)
Mutual labels:  template-engine
Flexml
🚀基于Litho的Android高性能动态业务容器。
Stars: ✭ 225 (-3.43%)
Mutual labels:  template-engine
Pongo2
Django-syntax like template-engine for Go
Stars: ✭ 2,111 (+806.01%)
Mutual labels:  template-engine
Thymeleaf
Thymeleaf is a modern server-side Java template engine for both web and standalone environments.
Stars: ✭ 2,251 (+866.09%)
Mutual labels:  template-engine
Himl
HTML-based Indented Markup Language for Ruby
Stars: ✭ 236 (+1.29%)
Mutual labels:  template-engine
Jte
jte is a secure and lightweight template engine for Java.
Stars: ✭ 228 (-2.15%)
Mutual labels:  template-engine
React Ssr
React SSR as a view template engine
Stars: ✭ 200 (-14.16%)
Mutual labels:  template-engine

eta (η)

Documentation - Chat - RunKit Demo - Playground

GitHub package.json version (master) deno module Travis All Contributors Coveralls Donate

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!
    • ExpressJS support out-of-the-box
  • 🔥 Reliable
    • Better quotes/comments support
      • ex. <%= someval + "string %>" %> compiles correctly, while it fails with doT or EJS
    • Great error reporting
  • ⚡️ Exports ES Modules as well as UMD
  • 📝 Easy template syntax

Eta vs other template engines

Eta vs EJS

Eta's syntax is very similar to EJS' (most templates should work with either engine), Eta has a similar API, and Eta and EJS share the same file-handling logic. Here are the differences between Eta and EJS:

  • Eta is more lightweight. Eta weighs less than 2.5KB gzipped, while EJS is 4.4KB gzipped
  • Eta compiles and renders templates much faster than EJS. Check out these benchmarks: https://ghcdn.rawgit.org/eta-dev/eta/master/browser-tests/benchmark.html
  • Eta allows left whitespace control (with -), something that doesn't work in EJS because EJS uses - on the left side to indicate that the value shouldn't be escaped. Instead, Eta uses ~ to output a raw value
  • Eta gives you more flexibility with delimeters -- you could set them to {{ and }}, for example, while with EJS this isn't possible
  • Eta adds plugin support
  • Comments in Eta use /* ... */ which allows commenting around template tags
  • Eta parses strings correctly. Example: <%= "%>" %> works in Eta, while it breaks in EJS
  • Eta exposes Typescript types and distributes a UMD build
  • Eta supports custom tag-type indicators. Example: you could change <%= to <%*
Eta vs doT.js

Eta and doT.js both allow embedded JavaScript, and both have best-in-class performance when compared to other template engines (though Eta is slightly faster with HTML-escaped templates). Here are some of the differences between Eta and doT.js:

  • Eta allows you to control how you strip preceding and trailing whitespace after tags.
  • It's much simpler to set custom delimiters with Eta than doT -- you don't have to rewrite every configuration Regular Expression
  • Eta supports plugins
  • Eta supports async
  • Eta parses strings and multi-line comments correctly. Example: <%= "%>" %> works in Eta, while the equivalent breaks in doT
  • Eta exposes Typescript types and distributes a UMD build
  • Eta supports runtime partials and file-handling.
Eta vs Handlebars

Eta and Handlebars are very different in some ways -- Eta is an embedded template engine, while Handlebars is a logic-less template engine. Here some additional differences between Eta and Handlebars:

  • Eta is more lightweight. Eta weighs less than 2.5KB gzipped, while Handlebars is ~22KB gzipped
  • Eta compiles and renders templates much faster than Handlebars -- around 7x faster. Check out these benchmarks: https://ghcdn.rawgit.org/eta-dev/eta/master/browser-tests/benchmark.html
  • Eta allows you to set custom delimiters
  • Eta supports plugins
  • Eta exposes Typescript types and distributes a UMD build
  • Custom tag-type indicators. Example: you could change <%= to <%*
  • With Eta, you don't need to register tons of helpers to do simple tasks like check if one value equals another value
  • Note that Eta templates run as trusted code -- just like any other JavaScript you write.

    If you are running user-defined/created templates on your machine, server, site, etc., you probably should go with a tool built for that purpose, like Handlebars.
Eta vs ES6 Template Literals

Template literals are a super useful tool, especially for shortening simple string concatenation. But writing complete templates using template literals can quickly get out of hand. Here's a comparison of Eta and template literals:

  • Eta compiles templates into JavaScript functions that use string concatenation and have comparable performance with template literals
  • Eta lets you control preceding and trailing whitespace around tags
  • Eta gives you more flexibility with delimeters -- you could set them to {{ and }}, for example, or set them to ${ and } to mimic template literals
  • Eta supports plugins
  • Eta supports comments with /* ... */ syntax, just like in regular JavaScript. Template literals require you to stick a blank string after the comment: /* ... */"", which is much less readable
  • To write conditionals inside template literals, you have to use the ternary operator. Add more conditions or nested conditionals, and it quickly becomes a nightmarish mess of ? ... : ... ? ... : .... Writing conditionals in Eta is much simpler and more readable
  • Eta supports partials

Why Eta?

Simply put, Eta is super: super lightweight, super fast, super powerful, and super simple. Like with EJS, you don't have to worry about learning an entire new templating syntax. Just write JavaScript inside your templates.

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.

CLI

An official Eta CLI exists called etajs-cli.

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:

📝 https://eta.js.org

📓 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

Projects using eta

Contributors

Made with ❤ by @nebrelbug and all these wonderful contributors (emoji key):


Ben Gubler

💻 💬 📖 ⚠️

Clite Tailor

🤔 💻

Ioan CHIRIAC

💻 🤔

Craig Morten

💻

Rajan Tiwari

💡

shadowtime2000

💻 🤔 ⚠️

Hamza Hamidi

📖

Calum Knott

🤔

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.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].