On Tuesday, 2 October 2018 at 18:27:04 UTC, Aurélien Plazzotta wrote:
Thank you both for all the links! I guess DiamondMVC is very powerful but I would rather avoid using such heavy artillery. I'm expecting the learning curve to be very long.

I currently use two libraries I wrote to keep things easy.

https://code.dlang.org/packages/arrogant
https://code.dlang.org/packages/reserved

The first one is a html5 parser. So you don't need any template, you can directly read html and then edit them just like you are used to do in js, for example.

For example:
auto src = `<html><head></head><body><div>Hello World</div></body></html>`;
   auto arrogant = Arrogant();
   auto tree = arrogant.parse(src);

   // Change div content from "Hello World!" to "Hello D!"
   tree.byTagName("div").front.innerText = "Hello D!";

   // Print the edited html
   writeln(tree.document);

The second library is a scgi library that allow you to send data to any webserver that support scgi (f.e. nginx). It works like php:

import reserved;

@ReservedResponse
private void response(Request req, Output output)
{
   output ~= "Hello ";

   if ("name" in req.get)
      output ~= req.get["name"];
   else
      output ~= "World";

// Using the library above you can do something like this instead:
   // output ~= tree.document;
}

mixin Reserved!"awesome_d_webservice";

So if you combine those two libraries you can output a validated/well-formed html5 document in a easy way.

Andrea

Reply via email to