D2 & Web-Framework

Nick Sabalausky a at a.a
Fri Jul 15 22:27:02 PDT 2011


"Adam D. Ruppe" <destructionator at gmail.com> wrote in message 
news:ivr07p$8cq$1 at digitalmars.com...
> Just a general comment... my D web stuff is spoiling me.
>
> Guy just asked me for a form based file uploader. With web.d:
>
> ===
> import arsd.web;
> import std.file;
> class SiteAdmin : ApiProvider {
>    override void _initialize() { cgi.requireBasicAuth("user", "pass"); }
>
>    string uploadNewVideo(Cgi.UploadedFile file) {
>         std.file.write("desiredfile", file.content);
>         return desiredfile;
>    }
>
>    override Document _defaultPage() {
>         return _getGenericContainer().
>            appendChild(_sitemap()).parentDocument;
>    }
> }
> mixin FancyMain!SiteAdmin;
> ===
>
> Boom. The library will auto-generate the form and some basic
> html output and a list of links to the pages.
>

Cool :)

> Compiling that little snipped will give me something
> I could show to him *right now*. And I can expand it later with
> ease. This one has a simple HTTP hard coded username and password
> which works for now and can again be trivially changed later.
>
> But alas, this job needed to be PHP. PHP is supposed to make
> file uploads easy, but I have to look up the stuff every time.
>

And whatever you end up with is most likely to have a bunch of subtle 
problems, and could easily break if moved to another server, even if you're 
lucky enough to have the same exact build of PHP on the new server.

> (just like how I have to look up the args to PHP str_replace
> every time... and I often forget Javascript substr or substring?
> In D, "string".replace("this", "that")[0..5]; is trivial to
> remember.)

Slicing is such a killer feature if, like me, you've come from langauges 
like C/C++/Java (or PHP).




More information about the Digitalmars-d mailing list