RejectedSoftware Forums

Sign up

Can I use HTML instead of diet templates?

Hi,

Thing is Jade and Diet don't have support for data-bind="somestuff" style attributes or other popular JavaScript templating systems you might use with modern MV* libraries such as knockout, angular, etc. So is there a way to build with raw html instead of Diet?

Thanks,
Florin

Re: Can I use HTML instead of diet templates?

On Fri, 07 Feb 2014 02:40:14 GMT, Florin wrote:

Hi,

Thing is Jade and Diet don't have support for data-bind="somestuff" style attributes or other popular JavaScript templating systems you might use with modern MV* libraries such as knockout, angular, etc. So is there a way to build with raw html instead of Diet?

Thanks,
Florin

The binding will happen in the browser, thus you can definitely use the regular sematics: input(data-bind='username[value]') is compiled by the diet template compiler into: <input data-bind='username[value]' />

If you really want to write raw html, you can put it on the right side of a vertical bar in diet templates:
| <div><div><input type="text" data-bind="someField" /></div></div>

Or if you want to send raw html directly to the output stream, use a bodyWriter and use the hundreds of different ways to build some D strings:

res.writeBody(string) and res.bodyWriter.write(string)

Re: Can I use HTML instead of diet templates?

Am 07.02.2014 05:41, schrieb Etienne:

On Fri, 07 Feb 2014 02:40:14 GMT, Florin wrote:

Hi,

Thing is Jade and Diet don't have support for data-bind="somestuff" style attributes or other popular JavaScript templating systems you might use with modern MV* libraries such as knockout, angular, etc. So is there a way to build with raw html instead of Diet?

Thanks,
Florin

The binding will happen in the browser, thus you can definitely use the regular sematics: input(data-bind='username[value]') is compiled by the diet template compiler into: <input data-bind='username[value]' />

If you really want to write raw html, you can put it on the right side of a vertical bar in diet templates:
| <div><div><input type="text" data-bind="someField" /></div></div>

Or if you want to send raw html directly to the output stream, use a bodyWriter and use the hundreds of different ways to build some D strings:

res.writeBody(string) and res.bodyWriter.write(string)

Just one thing to add: If you like writing plain HTML better in general
anyway, there are also some raw text based template systems that you
could look into:

http://code.dlang.org/packages/temple
http://code.dlang.org/packages/mustache-d
http://code.dlang.org/packages/embd

I think temple has the best vibe.d compatibility.

Re: Can I use HTML instead of diet templates?

Etiene, Sönke,

Thank you for your solutions, much appreciated! I just couldn't find this in the documentation, although input(data-bind='username[value]') was obviously there in the Jade docs.

I'm more inclined in using vibe.d as a restful api server at this point and consume the data from another server holding the front-end application.

However I am very interested in checking if there is any performance gain in serving the html and assets with vibe.d. This forum for example seems crazy fast :)

Re: Can I use HTML instead of diet templates?

On Fri, 07 Feb 2014 13:13:53 GMT, Florin wrote:

Etiene, Sönke,

Thank you for your solutions, much appreciated! I just couldn't find this in the documentation, although input(data-bind='username[value]') was obviously there in the Jade docs.

I'm more inclined in using vibe.d as a restful api server at this point and consume the data from another server holding the front-end application.

However I am very interested in checking if there is any performance gain in serving the html and assets with vibe.d. This forum for example seems crazy fast :)

Static content is better served from memory than from a hard drive with aio, given that it's accessed frequently. You should find more improvements with nginx in front and possibly this little module configured with it: https://github.com/desbouis/nginx-redis-proxy