NDoc is an extensible application: you can easily provide your own "documentation renderer", usually called documenter. I have used this feature to integrate NLiterate within NDoc and take advantage the built-in functions of the GUI. Here is the detailled procedure to create the NLiterate documenter.
1) Create the project:
Create an assembly project named NDoc.Documenter.*** where you replace *** with the name of your documenter. It is important to have your assembly named like this otherwise it will not be loaded by NDoc. Add the reference to NDoc.Core.dll.
2) Create the documenter config object:
The config class will be attached to the property grid control in the NDoc gui. This way we can easily define the different parameters of the documenter. The config class must implement IDocumenterConfig interface, however it is easier to inherit from BaseDocumenterConfig:
IDocumenterConfig
BaseDocumenterConfig
public class LiterateDocumenterConfig : BaseDocumenterConfig { private string outputFile; public LiterateDocumenterConfig() :base("Literate") { this.OutputFile =String.Format(".{0}doc{0}compile-log.txt",Path.DirectorySeparatorChar); } public string OutputFile { get { return this.outputFile; } set { this.outputFile = value; this.SetDirty(); } } }
Note that when OutputFile is modified, we notify NDoc using the protected method SetDirty.
3) Create the documenter class
The documenter class is the main class, it renders the documentation. This class must implement IDocumenter but again, it is easier to use the abstract base class BaseDocumenter:
public class LiterateDocumenter : BaseDocumenter { public LiterateDocumenter() :base("Literate") // this is the name that will appear in the NDoc list box { this.Clear(); } #region IDocumenter public override void Build(Project project) { // step one, load snippets loadSnippets(project); // step two, compile the snippets compileSnippets(project); // step three, create the report compileReport(project); } public override void Clear() { this.Config=new LiterateDocumenterConfig(); } public override DocumenterDevelopmentStatus DevelopmentStatus { get { return DocumenterDevelopmentStatus.Alpha; } } public override string MainOutputFile { get { return ((LiterateDocumenterConfig)this.Config).OutputFile; } } #endregion }
4) Adding progress notification
In the code above, we have not notified NDoc about the progress of the documentation rendering. This can be done through two functions: OnDocBuildingStep and OnDocBuildingProgress. For example:
public override void Build(Project project) { // step one, load snippets OnDocBuildingStep(0, "Start loading snippets"); loadSnippets(project); // step two, compile the snippets OnDocBuildingStep(40, "Start loading snippets"); compileSnippets(project); // step three, create the report OnDocBuildingProgress(40); // increasing progress percentage of 40% compileReport(project); }
5) Copy the assembly
The last step is to copy your assembly into the NDoc bin folder. When launched, NDoc looks for assemblies named "NDoc.Documenter...." and loads by reflection that documenter they are containing. That's it.
Page rendered at Sunday, September 07, 2008 8:21:06 PM UTC
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.