Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Eta is a fast, lightweight, and highly configurable embedded JavaScript template engine. It is designed to be simple and easy to use, while also being powerful enough to handle complex templating needs.
Basic Template Rendering
This feature allows you to render a basic template with embedded JavaScript expressions. The `render` function takes a template string and a data object, and returns the rendered string.
const eta = require('eta');
const template = 'Hello, <%= it.name %>!';
const data = { name: 'World' };
const result = eta.render(template, data);
console.log(result); // Output: Hello, World!
Template Caching
Eta supports template caching, which allows you to define and reuse templates by name. This can improve performance by avoiding the need to recompile templates on each render.
const eta = require('eta');
eta.templates.define('greeting', 'Hello, <%= it.name %>!');
const data = { name: 'World' };
const result = eta.render('greeting', data);
console.log(result); // Output: Hello, World!
Custom Filters
Eta allows you to define custom filters that can be used within templates to transform data. In this example, a custom filter `shout` is defined to convert a string to uppercase and add exclamation marks.
const eta = require('eta');
eta.configure({
filters: {
shout: (str) => str.toUpperCase() + '!!!'
}
});
const template = 'Hello, <%= it.name | shout %>!';
const data = { name: 'World' };
const result = eta.render(template, data);
console.log(result); // Output: Hello, WORLD!!!
EJS (Embedded JavaScript) is a simple templating language that lets you generate HTML markup with plain JavaScript. It is similar to Eta in terms of syntax and functionality, but Eta is generally faster and more lightweight.
Pug (formerly known as Jade) is a high-performance template engine heavily influenced by Haml. It is known for its clean and minimal syntax. Compared to Eta, Pug offers a more concise syntax but has a steeper learning curve.
Handlebars is a popular templating engine that provides a more logic-less approach to templates. It uses a Mustache-like syntax and is known for its simplicity and ease of use. Unlike Eta, Handlebars enforces a separation of logic and presentation.
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'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:
-
), 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{{
and }}
, for example, while with EJS this isn't possible/* ... */
which allows commenting around template tags<%= "%>" %>
works in Eta, while it breaks in EJS<%=
to <%*
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.
"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...
<%= someval + "string %>" %>
compiles correctly, while it fails with doT or EJSA documentation website is coming soon. In the meantime
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>
<% if(it.somevalue === 1) { %>
Display this
<% } else { %>
Display this instead
<% } %>
<ul>
<% it.users.forEach(function(user){ %>
<li><%= user.name %></li>
<% }) %>
</ul>
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.
To be added
eta
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!
FAQs
Lightweight, fast, and powerful embedded JS template engine
The npm package eta receives a total of 408,010 weekly downloads. As such, eta popularity was classified as popular.
We found that eta demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.