JSPM

  • Created
  • Published
  • Downloads 1163161
  • Score
    100M100P100Q181507F
  • License MIT

Lightweight, fast, and powerful embedded JS template engine

Package Exports

  • eta

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (eta) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

eta (η)

GitHub package.json version (master) Travis All Contributors Coveralls Dev Dependencies

documentation website styled with prettier Join the chat at https://gitter.im/eta-dev/community Donate

Summary

Eta is a lightweight and blazing fast embedded JS templating engine. The team who created Squirrelly created it to serve as a better alternative to EJS.

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://cdn.statically.io/gh/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
  • Custom tag-type indicators. Example: you could change <%= to <%*

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, and is three letters long, which is great for file extensions.

🌟 Features

  • 🔧 Great error reporting
  • 📦 0 dependencies
  • 🔧 Better quotes/comments support
    • ex. <%= someval + "string %>" %> compiles correctly, while it fails with doT or EJS
  • ⚡️ Exports ES Modules as well as UMD
  • 🔧 ExpressJS support out-of-the-box
  • 🔨 Loops
  • 🔧 Custom delimeters
  • 📝 Easy template syntax
  • 🔧 Precompilation
  • 🔨 Partials
  • 🔨 Comments
  • 🔨 Server and browser support
  • 🔧 Caching
  • 🚀 Super Fast
  • ⚡️ Async support

📜 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

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

<% @includeFile('footer') %>

✔️ 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

Add yours!

Contributors

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


Ben Gubler

💻 💬 📖 ⚠️

Clite Tailor

🤔 💻

Ioan CHIRIAC

💻 🤔

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 to throw an Eta Error.
  • Syntax and some parts of compilation are heavily based off EJS, Nunjucks, and doT.