Difference between revisions of "Contributing to dlang.org"

From D Wiki
Jump to: navigation, search
(Created page with "This document is aimed at people who want to contribute to the [http://dlang.org dlang.org] website. It includes a brief tutorial in the technologies used and step-by-step ins...")
 
Line 31: Line 31:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
At this point if all went well a nicely-formatted HTML file pops up featuring the dlang.org homepage. Congratulations!
+
At this point if all went well a nicely-formatted HTML file pops up featuring a local replica of the dlang.org homepage. Congratulations!
 +
 
 +
== Editing Content ==
 +
 
 +
Browsing through <tt>~/d/dlang.org/</tt> reveals that most files have the <tt>.dd</tt> extension. Those files are in Ddoc format; in order to work on dlang.org a basic understanding of the Ddoc format is needed.
 +
 
 +
At its core, Ddoc is a pure macro expansion system. In this context "pure" means the macro language has no relationship to other file format; all the expansion engine does is take in macro definitions and then munch through text and expand macros as they come along. A few macros are predefined to values that make HTML generation easy, so in that sense a slight affinity with HTML does exist; however, those macros can be trivially redefined to any other purpose. Also, Ddoc recognizes sections marked in a particular way as D source code. There are a few subtleties inherent to macro processors (e.g. how recursion works or in what order nested macros are expanded), but aside from those Ddoc is deceptively simple and very flexible. Exploiting the favorable relationship between Ddoc's simplicity and power is key to using it effectively.
 +
 
 +
Ddoc source files have the following structure:
 +
 
 +
<syntaxhighlight lang=text>
 +
Ddoc
 +
Text with embedded macros such as $(MACRO1) and $(MACRO2) goes here.
 +
Macros:
 +
  MACRO1=definition1
 +
  MACRO2=definition2
 +
</syntaxhighlight>
 +
 
 +
That is, a Ddoc file consists of the actual word "Ddoc" followed by a newline, then followed by the actual text of the document, followed by a line containing "Macros:", followed by macro definitions of the form <tt>NAME=value</tt>. The "Macros:" section is optional (as is the indentation of the macro definitions; it's present here for aesthetic reasons only). You might have guessed already that the syntax <tt>$(MACRONAME)</tt> expands the macro called <tt>MACRONAME</tt> into whatever text was ascribed to it in the "Macros:" section. Let's actually test that by saving the following text into a file called e.g. <tt>test.dd</tt>:
 +
 
 +
<syntaxhighlight lang=text>
 +
Ddoc
 +
Text with embedded macros such as $(MACRO1) and $(MACRO2) goes here.
 +
Macros:
 +
  MACRO1=definition1
 +
  MACRO2=definition2
 +
  DDOC_COMMENT=
 +
  DDOC=$(BODY)
 +
</syntaxhighlight>
 +
 
 +
The last two macro definitions seem to come out of nowhere and deserve some explanation, which this document will provide soon. For now let's  "build" this file like this:
 +
 
 +
<syntaxhighlight lang=bash>
 +
~/d/dmd/src/dmd test.dd
 +
cat test.html
 +
</syntaxhighlight>
 +
 
 +
(You may of course just type <tt>dmd</tt> if it's in your <tt>$PATH</tt>) The produced file, by default carrying the <tt>.html</tt> extension, contains:
 +
 
 +
<syntaxhighlight lang=text>
 +
Text with embedded macros such as definition1 and definition2 goes here.
 +
</syntaxhighlight>
 +
 
 +
So the macro names got expanded to

Revision as of 15:34, 18 December 2015

This document is aimed at people who want to contribute to the dlang.org website. It includes a brief tutorial in the technologies used and step-by-step instructions for typical tasks.

Installing

We assume you already have a dmd rig up and running. If not, follow the steps at Starting as a Contributor to get it running. The directory structure we'll assume in the following is:

~/
  d/
    dmd/
    druntime/
    phobos/

With this setup, let's proceed to downloading the source of dlang.org as follows:

cd ~/d
git clone https://github.com/D-Programming-Language/dlang.org

After this, the dlang.org directory will end up parallel to dmd, druntime, and phobos. Let's build the site (for now without the standard library documentation) by using the following command:

cd ~/d/dlang.org
make -j32 -f posix.mak html

The html target instructs make to only build the site. By default (if you specify no target), make also builds the core runtime and standard library documentation, both for the latest release and for the current code residing on your machine. That may get pretty involved, so let's leave it for later. For now, let's inspect the result of the build, all of which goes in the dlang.org/web directory. On Linux, for example, the command sensible-browser opens your default browser with a given file or address so we can use it as such:

sensible-browser ~/d/dlang.org/web/index.html

At this point if all went well a nicely-formatted HTML file pops up featuring a local replica of the dlang.org homepage. Congratulations!

Editing Content

Browsing through ~/d/dlang.org/ reveals that most files have the .dd extension. Those files are in Ddoc format; in order to work on dlang.org a basic understanding of the Ddoc format is needed.

At its core, Ddoc is a pure macro expansion system. In this context "pure" means the macro language has no relationship to other file format; all the expansion engine does is take in macro definitions and then munch through text and expand macros as they come along. A few macros are predefined to values that make HTML generation easy, so in that sense a slight affinity with HTML does exist; however, those macros can be trivially redefined to any other purpose. Also, Ddoc recognizes sections marked in a particular way as D source code. There are a few subtleties inherent to macro processors (e.g. how recursion works or in what order nested macros are expanded), but aside from those Ddoc is deceptively simple and very flexible. Exploiting the favorable relationship between Ddoc's simplicity and power is key to using it effectively.

Ddoc source files have the following structure:

Ddoc
Text with embedded macros such as $(MACRO1) and $(MACRO2) goes here.
Macros:
  MACRO1=definition1
  MACRO2=definition2

That is, a Ddoc file consists of the actual word "Ddoc" followed by a newline, then followed by the actual text of the document, followed by a line containing "Macros:", followed by macro definitions of the form NAME=value. The "Macros:" section is optional (as is the indentation of the macro definitions; it's present here for aesthetic reasons only). You might have guessed already that the syntax $(MACRONAME) expands the macro called MACRONAME into whatever text was ascribed to it in the "Macros:" section. Let's actually test that by saving the following text into a file called e.g. test.dd:

Ddoc
Text with embedded macros such as $(MACRO1) and $(MACRO2) goes here.
Macros:
  MACRO1=definition1
  MACRO2=definition2
  DDOC_COMMENT=
  DDOC=$(BODY)

The last two macro definitions seem to come out of nowhere and deserve some explanation, which this document will provide soon. For now let's "build" this file like this:

~/d/dmd/src/dmd test.dd
cat test.html

(You may of course just type dmd if it's in your $PATH) The produced file, by default carrying the .html extension, contains:

Text with embedded macros such as definition1 and definition2 goes here.

So the macro names got expanded to