franciscop / server

:desktop_computer: Simple and powerful server for Node.js
https://serverjs.io/
MIT License
3.56k stars 171 forks source link

Server and Nunkunks #40

Closed dannluciano closed 6 years ago

dannluciano commented 6 years ago

Hi Guys, someone can tell me how use server.js with nunjucks as template render? I can use server.js with nunjucks using this:

const server = require('server')
const { get } = server.router

const njk = require('nunjucks')
njk.configure('views')

server(
  get('/', ctx => njk.render('template.njk')),
)

or:

const server = require('server')
const njk = require('nunjucks')

const { get, post } = server.router
const { render } = server.reply

server(
  get('/', ctx => render('template.njk')),
).then((v) => njk.configure('views', {express: v.app}))

What is the best flow?

Thanks for your time and for this great lib.

franciscop commented 6 years ago

Please see this issue: https://github.com/franciscop/server/issues/34

Though I really like your second example, I will leave this open until I get a chance to unify them.

dannluciano commented 6 years ago

Thanks for your answer .

ghost commented 6 years ago

Hi Francisco, you helped me with Nunjucks in #34, thanks!! See, there is interest, and there is even a fork in Express being added now for the Generator there to have Nunjucks support built in.

I am just a beginner with Node, but maybe better documentation for the different templating engines? I may create a fork to try and give the documentation on your README.md file a section for different templating engines.

Thanks again!

franciscop commented 6 years ago

I want you to be able to do:

npm install @server/nunjucks

And be done with it. For this, the work on the 1.1 has to be finished which includes a solid plugin system. I am trying to think many possible edge cases and how to do this best. Will try to share my thought process so far.

ghost commented 6 years ago

@franciscop this would be really great because the Django community is special and people desire Node because of speed. My schizofrenic attempt at Nunjucks for Express is here: https://github.com/expressjs/generator/issues/156#issuecomment-348456686

your method of installation using @server/nunjucks is far greater than the express generator.

ghost commented 6 years ago

using [at]server/nunjucks

franciscop commented 6 years ago

I close this until plugins are done and ready to be used since the issue itself seems closed.