How To Dynamic Web Rendering?

Adam D. Ruppe destructionator at gmail.com
Sun May 15 12:19:20 PDT 2011


Alexander:
> That kind of a comment made me crazy many times - because then I
> had to dig inside the program to find the place where it was filled

Meh, is it any worse than digging into the program to figure
out what a function referenced in the template does?

> If at some point I want to change output from table view to
> something else - then I've to change the application as well

Not necessarily - you could add format strings to the html,
or have the output dependent on the tag name.

The Javascript access to my code I pointed to earlier includes this:

HTML, using a custom formatter provided by the Person object:

http://arsdnet.net/cgi-bin/apidemo/get-people?startingId=0&format=html

String, using a part custom, part automatic formatter:

http://arsdnet.net/cgi-bin/apidemo/get-people?startingId=0&format=string

Table, using an automatic formatter:

http://arsdnet.net/cgi-bin/apidemo/get-people?startingId=0&format=table

Json, using an automatic formatter:

http://arsdnet.net/cgi-bin/apidemo/get-people?startingId=0&format=json


The D function simply returned a Person[]. The formatting is
flexible, automatic in a lot of cases, hookable by the object if
needed.



But, in a lot of cases, you have to change the model to change
the data you're showing anyway... the view only has what's available
to it.

Even when mixed php code/data, you're going to either repeat
yourself a lot, or be limited by what's available in existing
functions or in the database.

The semantics of the data won't change without touching app code,
so the tags at this low level probably won't either. Changing
their appearance is done by CSS.


Take this table:

http://arsdnet.net/cgi-bin/apidemo/get-people?startingId=0&format=table

Want to show it as a list? Use CSS:

table { display: block; border: none; padding-left: 2em; }

thead { display: none; }

tr { display: list-item; }

th, td { display: inline; border: none; margin-left: 0.2em; }


Boom, the table now looks like an unordered list. Semantically
though, it's still tabular data, and the markup reflects that.

See it live here:

http://arsdnet.net/get-people.htm



> What blocks me is the absence of good, robust and
> high-performance socket/file I/O framework for D2.

When I wrote my http code, one of which is a kind of proxy/webapp
build in one, so it does server and client work, I just used
the appropriate C functions. Everything accessible from C is
also accessible from D, so even if phobos isn't quite up to it,
you can always do without.

I agree it will be nice when phobos' offering improves though.


More information about the Digitalmars-d-learn mailing list