2 // The assembler: Help compiler.
5 // Miguel de Icaza (miguel@gnome.org)
7 // (C) 2003 Ximian, Inc.
10 using System.Collections.Generic;
14 using Monodoc.Providers;
17 namespace Mono.Documentation {
19 public class MDocAssembler : MDocCommand {
20 static readonly string[] ValidFormats = {
30 public static Option[] CreateFormatOptions (MDocCommand self, Dictionary<string, List<string>> formats)
32 string cur_format = "ecma";
33 var options = new OptionSet () {
35 "The documentation {FORMAT} used in DIRECTORIES. " +
36 "Valid formats include:\n " +
37 string.Join ("\n ", ValidFormats) + "\n" +
38 "If not specified, the default format is `ecma'.",
40 if (Array.IndexOf (ValidFormats, v) < 0)
41 self.Error ("Invalid documentation format: {0}.", v);
44 { "<>", v => AddFormat (self, formats, cur_format, v) },
46 return new Option[]{options[0], options[1]};
49 public override void Run (IEnumerable<string> args)
51 var formats = new Dictionary<string, List<string>> ();
52 string prefix = "tree";
53 var formatOptions = CreateFormatOptions (this, formats);
54 var options = new OptionSet () {
57 "Provides the output file prefix; the files {PREFIX}.zip and " +
58 "{PREFIX}.tree will be created.\n" +
59 "If not specified, `tree' is the default PREFIX.",
63 List<string> extra = Parse (options, args, "assemble",
64 "[OPTIONS]+ DIRECTORIES",
65 "Assemble documentation within DIRECTORIES for use within the monodoc browser.");
69 List<Provider> list = new List<Provider> ();
70 EcmaProvider ecma = null;
73 foreach (string format in formats.Keys) {
77 ecma = new EcmaProvider ();
81 foreach (string dir in formats [format])
82 ecma.AddDirectory (dir);
87 list.AddRange (formats [format].Select (d => (Provider) new XhtmlProvider (d)));
91 list.Add (new ManProvider (formats [format].ToArray ()));
95 list.AddRange (formats [format].Select (d => (Provider) new ErrorProvider (d)));
99 list.AddRange (formats [format].Select (d => (Provider) new EcmaSpecProvider (d)));
103 list.AddRange (formats [format].Select (d => (Provider) new AddinsProvider (d)));
108 HelpSource hs = new HelpSource (prefix, true);
109 hs.TraceLevel = TraceLevel;
111 foreach (Provider p in list) {
112 p.PopulateTree (hs.Tree);
115 if (sort && hs.Tree != null)
116 hs.Tree.RootNode.Sort ();
119 // Flushes the EcmaProvider
121 foreach (Provider p in list)
122 p.CloseTree (hs, hs.Tree);
127 private static void AddFormat (MDocCommand self, Dictionary<string, List<string>> d, string format, string file)
130 self.Error ("No format specified.");
132 if (!d.TryGetValue (format, out l)) {
133 l = new List<string> ();