How To Dynamic Web Rendering?
Adam Ruppe
destructionator at gmail.com
Thu May 12 07:45:12 PDT 2011
> Could you share how or show an URL that provide sample code to do
> that in D?
Check out my D api demo:
http://arsdnet.net/cgi-bin/apidemo/
Here's the source code (about 50 lines of D)
http://arsdnet.net/apidemo.d
And the HTML templates it uses:
http://arsdnet.net/apidemo-document.html
http://arsdnet.net/apidemo-javascript.html
The libraries it imports are available here
http://arsdnet.net/dcode/
That demo shows something relatively new I made to provide same
source access to HTML and Javascript that uses D's reflection to
auto-generate almost everything.
You can also do more traditional style web apps. Here's a gradient
generator written in D:
http://arsdnet.net/cgi-bin/gradient?w=100&h=100&c1=ff0000&c2=00ff00&c4=ffff00&t=50
Source:
http://arsdnet.net/gradient.d
It uses my cgi.d from the dcode folder above. This code has a few
features so it isn't the simplest demo, about 150 lines. It makes
the png and sends it right out over the web.
Hello world with cgi.d looks like this:
import arsd.cgi;
void main() {
auto cgi = new Cgi();
cgi.write("Hello, world!");
cgi.close();
}
In all my examples though, I used mixins for main functions instead
of writing them directly because the mixin adds try/catch for
exceptions and handles the create and close too. This would look like:
import arsd.cgi;
void run() { cgi.write("Hello, world!"); }
mixin GenericMain!run;
I also often use my D DOM library in web code too, which you see
in the first example. That library is available in my folder too.
> So we use external tool to do that and not a build in one??
Yes, something like signtool.exe from Microsoft works for Windows
programs.
Generally, if you can do it to a C++ program, you can do it to a
D program too.
More information about the Digitalmars-d-learn
mailing list