fastify / point-of-view

Template rendering plugin for Fastify
MIT License
341 stars 86 forks source link

edge.js templates #417

Open johntom opened 7 months ago

johntom commented 7 months ago

Prerequisites

🚀 Feature Proposal

I just came across edge.js templates from "htmx discord link" and think this would be a strong addition to point-of-view.

Motivation

While I'm currently using nunjucks as my templating engine, many users on discord feel they will never add partials which is a feature I'd like to test with htmx. I also find https://edgejs.dev/docs/introduction very clear and concise.

Example

No response

mcollina commented 7 months ago

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

johntom commented 7 months ago

Sure, sorry to say that I've never done a pull request so I'm reading your guidelines now and will make an attempt.

multivoltage commented 7 months ago

never read about this engine. It's seem very big. I loved what they wrote:

If you swim in the <your-frontend-framework> ecosystem, you do not need Edge. Imagine, you never opened this website 😉

@johntom if you want help/collaborate I'm happy

johntom commented 7 months ago

Yes would love the help and I don't think I'll have any issues with a pull request(pr) but have not gotten edge to work with fastify so didnt have anything to contribute, Do you want me to do the pr?

johntom commented 7 months ago

Ok, I think I have successfully created a pull request.

mweberxyz commented 6 months ago

I am not sure edge is a great fit for this plugin. Looking at https://edgejs.dev/docs/getting_started, it is ESM-only (whereas this entire plugin is CommonJS).

johntom commented 6 months ago

I never got edge to work and was off converting a Fastify3/ commonJS to Fastify4/ESM. To that end, the following code will let you require files with esm

'use strict' import fp from 'fastify-plugin'; import os from 'os' const drive = process.env.drive;

// The following fixes common libs when you cant import import { createRequire } from "module"; const require = createRequire(import.meta.url); // End of fix

console.log(" chilkat================== ") if (os.platform() == 'win32') { if (os.arch() == 'ia32') { var chilkat = @./ck-node20-win-ia32'); } else { var chilkat = @./ck-node20-win64'); } } // esm does not support loading json and if fixed with this snippet const books = require("../json/books.json")

On Mon, Mar 25, 2024 at 10:29 PM Matt Weber @.***> wrote:

I am not sure edge is a great fit for this plugin. Looking at https://edgejs.dev/docs/getting_started, it is ESM-only (whereas this entire plugin is CommonJS), and it looks like it has HTTP routing and middleware built in, just looking at this getting started example, I am not sure how Fastify fits in:

import { Edge } from 'edge.js' import { createServer } from 'node:http'

const edge = Edge.create() edge.mount(new URL('./views', import.meta.url))

const server = createServer(async (req, res) => { const data = { username: 'virk' } const html = await edge.render('home', data)

res.setHeader('content-type', 'text/html') res.end(html) })

server.listen(3000)

— Reply to this email directly, view it on GitHub https://github.com/fastify/point-of-view/issues/417#issuecomment-2019272677, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOKLADSYXNJMOSXEA56EOTY2DMRJAVCNFSM6AAAAABD6LX7A2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMJZGI3TENRXG4 . You are receiving this because you were mentioned.Message ID: @.***>