D2 & Web-Framework

Adam D. Ruppe destructionator at gmail.com
Fri Jul 15 20:23:37 PDT 2011


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.

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.

(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.)


More information about the Digitalmars-d mailing list