Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/deligenius/view-engine
🚀A Template View Engine for Deno frameworks
https://github.com/deligenius/view-engine
Last synced: about 12 hours ago
JSON representation
🚀A Template View Engine for Deno frameworks
- Host: GitHub
- URL: https://github.com/deligenius/view-engine
- Owner: deligenius
- License: mit
- Created: 2020-05-25T22:02:55.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-03-15T16:55:06.000Z (8 months ago)
- Last Synced: 2024-09-17T15:49:51.771Z (about 2 months ago)
- Language: TypeScript
- Homepage:
- Size: 1.98 MB
- Stars: 54
- Watchers: 3
- Forks: 16
- Open Issues: 7
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
## 🚀 View Engine
![View Engine Logo](./docs/icon.png)
> A Template View Engine for Deno frameworks
## View Engine is now matching the version of Oak[![tag](https://img.shields.io/github/tag/deligenius/view-engine.svg)](https://github.com/deligenius/view-engine)
### Features:
- Support **multiple templating engines**📰
- Current support [Denjucks](https://github.com/denjucks/denjucks), [Eta](https://github.com/eta-dev/eta), [Handlebars](https://handlebarsjs.com/), and [dejs](https://github.com/syumai/dejs),
- Engines can be used **standalone**🎙 - [Use standlone handlebar engine](#Use-standalone-handlebar-engine)
- **Framework neutral**🎨, it uses adapter to load engine
- Current support [Oak](https://github.com/oakserver/oak)
- **Local file**⛱ loading
- ~~Ashychorous⚡ remote file fetching (fetching template on the fly )~~
- **Dynamic module import**, uses `await` to load adapters and engines🌈### Table of Contents
- [Usage](#Usage)
- [🎛Adapter](#adapter)
- [🚀Engine](#engine)
- [⚙ViewConfig](#viewconfig)---
### Usage
```ts
viewEngine(
adapter: Adapter,
engine:Engine,
viewConfig?: ViewConfig
)
```#### 🎛Adapter
```ts
import { oakAdapter } from "https://deno.land/x/[email protected]/mod.ts"```
#### 🚀Engine
```ts
import { ejsEngine, denjuckEngine, handlebarsEngine } from "https://deno.land/x/[email protected]/mod.ts"
```#### ⚙ViewConfig
```ts
const viewConfig: ViewConfig = {
viewRoot: "./views", // default: "", specify the root path, it can be remote address
}
```## [🔝](#table-of-contents)
### Examples
#### Use [Oak](https://github.com/oakserver/oak) to render `eta` template at `./views/eta/index.eta`
Suppose you have a folder like this:
```
/views/index.ejs
/app.ts
``````html
Hobbies of <%=it.name%>
```
```ts
// app.ts
import { Application } from "https://deno.land/x/[email protected]/mod.ts";
import { viewEngine, ejsEngine, oakAdapter } from "https://deno.land/x/[email protected]/mod.ts"const app = new Application();
app.use(
viewEngine(oakAdapter, etaEngine, {
viewRoot: "./views/eta",
})
);app.use(async (ctx, next) => {
ctx.render("index.eta", { name: "John" } );
});await app.listen({ port: 8000 });
```
Then run
```ts
> deno run --allow-net --allow-read ./app.ts
```
Open any browser, url: ```http://localhost:8000``` you should see the result.## [🔝](#table-of-contents)
### Credit
Original work by [@gjuoun](https://github.com/gjuoun/)