Security News
Combatting Alert Fatigue by Prioritizing Malicious Intent
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Odesza is a templating engine that allows you to write clean, expressive templates with inline JavaScript.
I find learning templating languages to be more of a hassle than just writing the HTML. Hence, there is no magic or shorthand code in Odesza templates. Odesza simply provides a structure for you to write complex templating systems without having to learn a new language. Simply put, it offers the flexibility of multiple inheritance and inline programming logic with the familiarity of writing plain HTML and JS.
Variables are passed in when Odesza templates are rendered. Scope is maintained through includes and extends. You can also treat ${}
as a function statement.
hello.ode
<title>${title}</title>
<p>
Welcome, ${names.map(n => `<i>${n}</i>`).join(', ')}!
</p>
code
var vars = {
title: 'hello world',
names: ['foo', 'bar']
};
odesza.renderFile('hello.ode', vars);
output
<title>hello world</title>
<p>
Welcome, <i>foo</i>, <i>bar</i>
</p>
Odesza makes it easy to write inline JavaScript in your templates. Under the hood, templates are evaluated as ES6 template strings, which means you have access to ${}
expressions. If you need more flexibility with inline js, you can create a self-executing function expression with code inside it like this: ${(() => { ... })()}
.
greetings.ode
<h2>welcome ${names.join(', ')}!</h2>
${(() => {
// this is a self-executing function expression inside an ES6 template string.
// essentially that means you can write any inline js you want here. the
// following code is to demonstrate how you can programatically generate HTML.
var items = [];
names.forEach((name, index) => {
items.push(`<div>${index + 1}: ${name}</div>`);
});
return items.join('<br/>');
})()}
code
var vars = {
names: ['wells', 'joe', 'dom']
};
odesza.renderFile('greetings.ode', vars);
output
<h2>welcome wells, joe, dom!</h2>
<div>1: wells</div><br/>
<div>2: joe</div><br/>
<div>3: dom</div>
Odesza makes it easy to nest templates within each other. You can include templates as many levels deep as you like. Variables maintain scope in included files.
greeting.ode
hello!
welcome.ode
include greeting
welcome, ${name}!
question.ode
include welcome
would you like to play a game, ${name}?
code
var vars = {
name: 'foo'
};
odesza.renderFile('question,ode', vars);
output
hello!
welcome, foo!
would you like to play a game, foo?
Odesza gives you access to multiple inheritance through extending templates and block scopes.
layout.ode
<!doctype html>
<html>
<head>
<title>${title}</title>
block js
</head>
<body>
block content
</body>
</html>
page.ode (extends layout.ode)
extends layout
block js
<script src="${base_path}/page.js"></script>
endblock
block content
<p>
Some content.
</p>
endblock
extended_page.ode (extends page.ode, overwrites 'content' block)
extends page
block content
<p>
Overwritten content.
</p>
endblock
code
var vars = {
title: 'hello world',
base_path: 'public/js'
};
odesza.renderFile('extended_page.ode', vars);
output
<!doctype html>
<html>
<head>
<title>hello world</title>
<script src="public/js/page.js"></script>
</head>
<body>
<p>
Overwritten content.
</p>
</body>
</html>
index.js
app.set('view engine', 'ode');
app.engine('.ode', require('odesza').__express);
controller
res.render('template', {
foo: 'bar'
});
You can compile odesza templates from the command line to stdout
or an output file.
odesza <file> [-o <output>]
npm install odesza --save
MIT
FAQs
Write clean, expressive templates with just HTML and inline JavaScript
The npm package odesza receives a total of 0 weekly downloads. As such, odesza popularity was classified as not popular.
We found that odesza demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.