This Week in D is back

Adam D. Ruppe destructionator at gmail.com
Wed Dec 19 14:33:03 UTC 2018


Here's a fun fact about the setup: the files are actually written 
as D modules. The source code looks like

// just docs: title
/++

Article content

+/
module Blog.Posted_date;


Now, that might seem a little silly, but it provides some 
interesting advantages (I should have wrote about this in the 
first article!):

1) I can use adrdox's linking with the same pattern: I can link 
with the shortcuts to the titles. Similarly, adrdox's navigation 
can handle it automatically.

2) I can compile them!


It is #2 that is going to be fun. If I want to write some example 
code in there, I can compile and run it without any copy/paste 
action. But wait, how do you see the code in the article?

As a documented unittest, of course! And adrdox has two features 
that extend it: an `// exclude from docs` comment to take boring 
plumbing lines out of the publication

/++ I can compile and run this as a test, and display it in the 
article as a complete program the user can copy/paste and run 
themselves! +/
unittest {
         import arsd.terminal;

         void main() {
                 auto terminal = 
Terminal(ConsoleOutputType.linear);
                 string line = terminal.getline();
                 terminal.writeln("You wrote: ", line);
         }

         main; // exclude from docs
}


And I can embed the unittest somewhere in the text (via a magic 
`$(EMBED_UNITTEST id)`) instead of just listing them at the end 
under examples, so make it flow better with the narrative.


It'll be fun to play with this in the future :)


More information about the Digitalmars-d-announce mailing list