Socket
Socket
Sign inDemoInstall

odesza

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

odesza

Write clean, expressive templates with just HTML and inline JavaScript


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Odesza

Odesza allows you to write clean, expressive templates with inline JavaScript. It offers the flexibility of multiple inheritance and inline programming logic with the simplicity of writing plain HTML and JS.

  • multiple inheritance
  • variables
  • fully expressive inline JavaScript
  • support for Express
  • no magic, 0 dependencies, and just 150 lines of code

#Install

npm install odesza --save

Variables

Variables are passed in when Odesza templates are rendered. Scope is maintained through includes and extends.

var vars = {
  name = 'world'
};

odesza.render('hello, ${name}', vars); // hello world

#Inline JS 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.

code

var vars = {
  names: ['wells', 'joe', 'dom']
};

odesza.compile('greetings.ode', vars);

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/>');

})()}

output

<h2>welcome wells, joe, dom!</h2>
<div>1: wells</div><br/>
<div>2: joe</div><br/>
<div>3: dom</div>

Partials

welcome.ode

welcome, ${name}!

question.ode

include welcome

would you like to play a game, ${name}?

code

var vars = {
  name: 'foo'
};

odesza.compile('question', vars);

output

welcome, foo!

would you like to play a game, foo?

Inheritance

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)

extend 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)

extend page

block content
<p>
  Overwritten content.
</p>
endblock

code

var vars = {
  title: 'hello world',
  base_path: 'public/js'
};

odesza.compile('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>

#Express Support index.js

app.set('view engine', 'ode');
app.engine('.ode', require('odesza').__express);

controller

res.render('template', {
  foo: 'bar'
});

#License MIT

FAQs

Package last updated on 29 Nov 2015

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc