sectplating

1.0.4 • Public • Published

SectPlating

An easy to use, fast and lightweight template engine.

npm i sectplating

Example:

const { sectplating } = require("sectplating");

const rendered = sectplating("Hello {globe}, This Is The Power Of: {cool_name}!", { globe: "World", cool_name: "SectPlating" });

console.log(rendered); // Output: Hello World, This Is The Power Of: SectPlating!

With File Example:

const { renderFile, render } = require("sectplating");

const path = "./index.html" // File Content: <h1>{example}</h1>
const options = { example: "Hello, World!" }

// Built-In:
renderFile(path, options, (err, output) => {
  if (err) return console.log(err);
  
  console.log(output); // Output: <h1>Hello, World!</h1>
})

// Custom:
let filecontent = "ERROR: File Reading Error!"

try {
   filecontent = fs.readFileSync(path, 'utf8');
 } catch (err) {
   logcon.error(`ERROR: File Reading Error: ${err}`);
   filecontent = "ERROR: File Reading Error: " + err;
}

console.log(render(filecontent, options)); // Output: <h1>Hello, World!</h1>

Supports Express.js

const express = require("express")
const app = express()

const options = { example: "Hello, World!" }

app.engine("html", require("sectplating").__express) // Or: app.engine('html', require("sectplating").renderFile)

app.get('/', function (req, res) {
  res.render("index.html", options)
})

Options:

{ ignoreMissing = false, transform = ({ value }) => value }

Package Sidebar

Install

npm i sectplating

Weekly Downloads

2

Version

1.0.4

License

MPL-2.0

Unpacked Size

5.58 kB

Total Files

5

Last publish

Collaborators

  • sectly