1.0.13 • Published 1 year ago

altai v1.0.13

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

altai

A wrapper for the EJS library that allows more natural EJS elements.

Example

<!DOCTYPE altai html>
<html>
  <script render>
    let username = `Jhon Doe`
  </script>
  
  <ejs>if(username){</ejs>
    <h1>
      <var>username</var>
    </h1>
  <ejs>}</ejs>
</html>

Installation

npm install altai

import * as altai from "altai"

If using Express, you can then easily set your view engine with

// Replace "html" with the extension of your view files, like "ejs" for index.ejs or "html" for index.html
app.engine('html', altai.renderFile);
app.set(`view engine`, `html`)

Or you can render altai HTML with

await altai.render(`<var>username</var>`,{
  username: `Jhon Doe`
})

Features

"Render" scripts

EJS

<% console.log("Hello, World!") %>

altai

<script render>
  console.log("Hello, World!")
</script>

Extra attributes can be passed along with render such as:

  • out like <%=
  • unsafe like <%- when out is passed

Or, to make it shorter:

  • r for render
  • o for out
  • ro for both

So, to render out some text:

<script ro>
  `Hello, ${username}!`
</script>

ejs instead of script is also valid, and automatically enables render.

<ejs out>
  `Hello, ${username}!`
</ejs>

Easy variable embedding

altai overrides the pretty much unused HTML element <var> for easy embedding of EJS variables.

<h1>
  <var>username</var>
</h1>

Easy template embedding

The <include> or <use> tag paired with a src can replace EJS's template embedding.

<include src="views/template.ejs" />

Keep in mind that included files will act like regular EJS templates and not have altai

Closing tag... tag

A peeve of mine is typing in <% } %> to end something like <% if(true){ %>.

Instead, with altai you can do a simple <}>.

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.1

1 year ago

2.0.0

7 years ago

1.0.0

7 years ago