From 2ed7849921f0413c175094ff15b1cf71d931ed1c Mon Sep 17 00:00:00 2001 From: Grzegorz Adam Hankiewicz Date: Mon, 6 Jan 2014 14:55:03 +0100 Subject: [PATCH] Transforms docgen sample to be generated from source. --- doc/docgen.txt | 4 +- doc/docgen_sample.nim | 12 ++ doc/docgen_samples/sample.html | 282 -------------------------------- doc/docgen_samples/sample2.html | 282 -------------------------------- tools/nimweb.nim | 14 ++ 5 files changed, 28 insertions(+), 566 deletions(-) create mode 100644 doc/docgen_sample.nim delete mode 100644 doc/docgen_samples/sample.html delete mode 100644 doc/docgen_samples/sample2.html diff --git a/doc/docgen.txt b/doc/docgen.txt index 2ef06e578..acd09f2eb 100644 --- a/doc/docgen.txt +++ b/doc/docgen.txt @@ -97,7 +97,7 @@ Partial Output:: proc helloWorld*(times: int) ... -Output can be viewed in full here `sample.html `_. +Output can be viewed in full here: `docgen_sample.html `_. The next command, called ``doc2``, is very similar to the ``doc`` command, but will be run after the compiler performs semantic checking on the input nimrod module(s), which allows it to process macros. @@ -110,7 +110,7 @@ Partial Output:: proc helloWorld(times: int) {.raises: [], tags: [].} ... -The full output can be seen here `sample2.html `_. +The full output can be seen here: `docgen_sample2.html `_. As you can see, the tool has extracted additional information provided to it by the compiler beyond what the ``doc`` command provides, such as pragmas attached implicitly by the compiler. This type of information is not available from diff --git a/doc/docgen_sample.nim b/doc/docgen_sample.nim new file mode 100644 index 000000000..875993187 --- /dev/null +++ b/doc/docgen_sample.nim @@ -0,0 +1,12 @@ +## This module is a sample. + +import strutils + +proc helloWorld*(times: int) = + ## Takes an integer and outputs + ## as many "hello world!"s + + for i in 0 .. times-1: + echo "hello world!" + +helloWorld(5) diff --git a/doc/docgen_samples/sample.html b/doc/docgen_samples/sample.html deleted file mode 100644 index 4efa40905..000000000 --- a/doc/docgen_samples/sample.html +++ /dev/null @@ -1,282 +0,0 @@ - - - - - - -Module sample - - - - -
-

Module sample

- -
-This module is a sample. - -
-

Procs

-
-
proc helloWorld*(times: int)
-
-Takes an integer and outputs as many "hello world!"s -
- -
- -
- -Generated: 2013-12-21 11:45:42 UTC -
- - diff --git a/doc/docgen_samples/sample2.html b/doc/docgen_samples/sample2.html deleted file mode 100644 index 3ff5e27e5..000000000 --- a/doc/docgen_samples/sample2.html +++ /dev/null @@ -1,282 +0,0 @@ - - - - - - -Module sample - - - - -
-

Module sample

- -
-This module is a sample. - -
-

Procs

-
-
proc helloWorld(times: int) {.raises: [], tags: [].}
-
-Takes an integer and outputs as many "hello world!"s -
- -
- -
- -Generated: 2013-12-21 11:45:52 UTC -
- - diff --git a/tools/nimweb.nim b/tools/nimweb.nim index c5d510eac..0e519b4b8 100644 --- a/tools/nimweb.nim +++ b/tools/nimweb.nim @@ -204,6 +204,18 @@ proc Exec(cmd: string) = echo(cmd) if os.execShellCmd(cmd) != 0: quit("external program failed") +proc buildDocSamples(c: var TConfigData, destPath: string) = + ## Special case documentation sample proc. + ## + ## The docgen sample needs to be generated twice with different commands, so + ## it didn't make much sense to integrate into the existing generic + ## documentation builders. + const src = "doc"/"docgen_sample.nim" + Exec("nimrod doc $# -o:$# $#" % + [c.nimrodArgs, destPath / "docgen_sample.html", src]) + Exec("nimrod doc2 $# -o:$# $#" % + [c.nimrodArgs, destPath / "docgen_sample2.html", src]) + proc buildDoc(c: var TConfigData, destPath: string) = # call nim for the documentation: for d in items(c.doc): @@ -352,7 +364,9 @@ proc main(c: var TConfigData) = copyDir("web/assets", "web/upload/assets") buildNewsRss(c, "web/upload") buildAddDoc(c, "web/upload") + buildDocSamples(c, "web/upload") buildDoc(c, "web/upload") + buildDocSamples(c, "doc") buildDoc(c, "doc") buildPdfDoc(c, "doc")