Closed mbucc closed 5 years ago
It seems pretty straightforward to me. I'd either wrap around kcgijson or use their json-c and replace the bits that use putc and printf and friends and replace them with khttp_write and friends. Keep me posted with what you do!
Joining here because I'm actually interested. I could not find a sane documentation for mustach
except reading the code which is basically hit and miss.
I have been planning to write a web application soon™, and while I make quite some progress with Ningle, the one thing that stops me from moving over to C/kcgi
is that I could not find a viable HTML template engine for it just yet. As far as I could see, khttp_template()
does not have blocks/loops like Jinja2 does (or does it?) and the only native C alternative I could find, SST, seems to be stalled for the time being.
So with this comment I'm basically setting myself on the watchlist for this issue. :)
Does it not make more sense to generate the output in the frontend? So that the JS frontend puts the pieces together and just concentrate on the more important part , putting more effort on a json–ld strategy? From my perspective templating belongs to the tasks of the frontend and that‘s in fact what processing the template is all about. To be more clear the JS should get the json–ld and the mustache template for the given site and put them together. You do not waste computational power to generate the output and if the request is not authorized to see the data which you have to check anyway it will neither see the template or the data. But if only the data or the template is requested you do not need to care about the rest. It is also a more generic approach. @dertuxmalwieder so I do not understand why you think that this is a blocker for using kcgi? @mbucc I am sure there are ways using mustache with JS if you like it that much but i would suggest vanilla JS and HTML if it is about websites @kristapsdz what do you think about this approach?
so I do not understand why you think that this is a blocker for using kcgi?
Because I honestly lack the experience to come up with a solution on my own.
I have been a qdecoder user for a while and is interested in kcgi, it seems kcgi is way more complex, hopefully way more powerful after the learning curve. yes I agree at least template engine should be totally independent from the rest and be optional, as in many cases you may use template on the client side instead these days. @opunix that's a debate between server-render vs client-render for html pages, in some cases you may want to render at the server side, for quick loading time, better SEO, or just protecting your source code and its logic when there is a need.
I'm closing this issue because it's not really an issue with kcgi. Thanks!
Hi,
I'm a fan of mustache templates and have found a C library (https://gitlab.com/jobol/mustach) that implements mustache. That lib comes bundled with a wrapper for json-c.
As best I can figure, writing a wrapper for kcgi's generated JSON code is a good way to use this library. A mustache wrapper implements the interface (https://gitlab.com/jobol/mustach/blob/master/mustach.h#L53-59):
where
Do you agree this is a sensible approach? And if so, how much work is involved?