ulka-parser
v0.4.1
Published
Templating engine for ulka static site generator
Downloads
287
Readme
🚀 Usage
ClI
npx ulka-parser --t /path/to/template/folder/or/file --o /path/to/output/folder
# OR
npm install -g ulka-parser
ulka-parser --t /path/to/template/folder/or/file --o /path/to/output/folder
Javascript Api
npm i ulka-parser
const { render } = require("ulka-parser")
const template = `Hello, I am {% name %}`
const data = render(template, { name: "Roshan Acharya" })
console.log(data)
// Hello, I am Roshan Acharya
Template Guide
You can write nodejs code inside {% %}
in ulka template.
index.ulka
{% const name = "Roshan Acharya".toUpperCase() %}
<h1>Hello, I am {% name %}</h1>
index.html
<h1>ROSHAN ACHARYA</h1>
Variables
index.ulka
{% const name = "I Love Javascript" %}
{% name %}
index.html
I Love Javascript
Loops
index.ulka
{% const languages = [ { name: "javascript", short: "js" }, { name: "typescript", short: "ts" }, ]; %}
<div>
{% languages.map(lang => `<h1>I Love ${lang.name} (${lang.short}).</h1>`) %}
</div>
index.html
<div>
<h1>I Love javascript (js).</h1>
<h1>I Love typescript (ts).</h1>
</div>
Conditionals
index.ulka
{% const iAmWinner = true %}
{% iAmWinner ? "I am Winner": "I am loser" %}
index.html
I am Winner
Import NPM modules
{% const dayjs = require('dayjs') %}
{% dayjs().format() %}
Ulka parser with express
const express = require("express")
const { engine } = require("ulka-parser")
const app = express()
app.engine("ulka", engine())
app.set("views", "./views")
app.set("view engine", "ulka")
app.get("/", (req, res) => {
res.render("index", { name: "Roshan Acharya" })
})
app.listen(3000, () => {
console.log("Server listening on port 3000")
})