@gaman ejs - 7TogkID/gaman GitHub Wiki

EJS

GamanJS integration for EJS view rendering. Simplify template rendering using EJS.

Features

  • Integrates EJS template rendering into GamanJS applications.
  • Fully customizable options passed to the EJS renderer.
  • Supports custom view directories and other EJS configuration options.

Installation

Install the package using your favorite package manager:

npm install @gaman/ejs ejs

Usage

1. Initialize Integration

Configure the EJS integration in your main.ts file:

import ejs from "@gaman/ejs";
import gaman from "gaman";
import blocks from "./blocks";

gaman.serv({
  integrations: [
    ejs({
      viewPath: "custom/views", // Default is 'src/views'
      // Additional EJS options can be configured here
    }),
  ],
  blocks: [blocks],
});

2. Create EJS Templates

Add EJS templates in the src/views directory (or your custom directory if configured).

File: src/views/index.ejs

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title><%= title %></title>
</head>
<body>
  <h1><%= title %></h1>
  <p>Welcome to your GamanJS app with EJS integration!</p>
</body>
</html>

3. Define Routes with View Rendering

In your blocks file (e.g., main.block.ts or example.block.ts):

import { defineBlock, Response } from "gaman";

export default defineBlock({
  routes: {
    "/": async (ctx) => {
      return Response.render("index", { title: "Welcome to GamanJS" });
    },
  },
});

Options

EJS options can be customized through the integration. Refer to the full list of EJS options at the official EJS documentation.

Option Type Description Default
viewPath string Root directory for your EJS templates. src/views
priority Priority Priority for this integration in GamanJS. normal

Example Project Structure

src/
├── blocks/
│   └── main.block.ts
├── views/
│   └── index.ejs
└── main.ts

FAQ

Q: What is EJS?

EJS (Embedded JavaScript) is a simple templating language that lets you generate HTML markup with plain JavaScript.

Q: Why use this integration?

This integration simplifies using EJS in GamanJS applications, letting you render views directly in your routes.


Seamlessly integrate EJS templates into your GamanJS projects with @gaman/ejs!

⚠️ **GitHub.com Fallback** ⚠️