altai
v1.0.13
Published
A wrapper for the EJS library that allows more natural EJS elements.
Downloads
1
Readme
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<%-
whenout
is passed
Or, to make it shorter:
r
forrender
o
forout
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 <}>
.