fastify / point-of-view

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

add parse raw template in view #391

Closed sirenkovladd closed 1 year ago

sirenkovladd commented 1 year ago

Fixes: https://github.com/fastify/point-of-view/issues/390

fastify.get('/', async (req, reply) => {
    const rawTemplate = await someRequestOrQuery(req)
    const someData = await getSomeData(req)
    reply.view({ raw: rawTemplate }, someData)
})
fastify.get('/', async (req, reply) => {
    const rawTemplate = await prepareHbsTemplate(req)
    const template = hbs.template(rawTemplate) // typeof template === 'function'
    const someData = await getSomeData(req)
    reply.view(template, someData, { layout: someLayout })
})

Checklist

sirenkovladd commented 1 year ago

also 100% coverage

-------------------------------------|---------|----------|---------|---------|-------------------
File                                 | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
-------------------------------------|---------|----------|---------|---------|-------------------
All files                            |     100 |      100 |     100 |     100 |                   
 point-of-view                       |     100 |      100 |     100 |     100 |                   
  index.js                           |     100 |      100 |     100 |     100 |                   
 point-of-view/tap-snapshots/test    |     100 |      100 |     100 |     100 |                   
  test-ejs-with-snapshot.js.test.cjs |     100 |      100 |     100 |     100 |                   
-------------------------------------|---------|----------|---------|---------|-------------------