update MEF to preview 9
[mcs.git] / tools / mdoc / Mono.Documentation / assembler.cs
blob1f6e1a1fd0cab7282f13ed57e93a1c3cc79bffe9
1 //
2 // The assembler: Help compiler.
3 //
4 // Author:
5 // Miguel de Icaza (miguel@gnome.org)
6 //
7 // (C) 2003 Ximian, Inc.
8 //
9 using System;
10 using System.Collections.Generic;
11 using System.Linq;
12 using System.Xml;
13 using Monodoc;
14 using Mono.Options;
16 namespace Mono.Documentation {
18 public class MDocAssembler : MDocCommand {
19 static readonly string[] ValidFormats = {
20 "ecma",
21 "ecmaspec",
22 "error",
23 "hb",
24 "man",
25 "simple",
26 "xhtml"
29 public static Option[] CreateFormatOptions (MDocCommand self, Dictionary<string, List<string>> formats)
31 string cur_format = "ecma";
32 var options = new OptionSet () {
33 { "f|format=",
34 "The documentation {FORMAT} used in DIRECTORIES. " +
35 "Valid formats include:\n " +
36 string.Join ("\n ", ValidFormats) + "\n" +
37 "If not specified, the default format is `ecma'.",
38 v => {
39 if (Array.IndexOf (ValidFormats, v) < 0)
40 self.Error ("Invalid documentation format: {0}.", v);
41 cur_format = v;
42 } },
43 { "<>", v => AddFormat (self, formats, cur_format, v) },
45 return new Option[]{options[0], options[1]};
48 public override void Run (IEnumerable<string> args)
50 var formats = new Dictionary<string, List<string>> ();
51 string prefix = "tree";
52 string cur_format = "ecma";
53 var formatOptions = CreateFormatOptions (this, formats);
54 var options = new OptionSet () {
55 formatOptions [0],
56 { "o|out=",
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.",
60 v => prefix = v },
61 formatOptions [1],
63 List<string> extra = Parse (options, args, "assemble",
64 "[OPTIONS]+ DIRECTORIES",
65 "Assemble documentation within DIRECTORIES for use within the monodoc browser.");
66 if (extra == null)
67 return;
69 List<Provider> list = new List<Provider> ();
70 EcmaProvider ecma = null;
71 bool sort = false;
73 foreach (string format in formats.Keys) {
74 switch (format) {
75 case "ecma":
76 if (ecma == null) {
77 ecma = new EcmaProvider ();
78 list.Add (ecma);
79 sort = true;
81 foreach (string dir in formats [format])
82 ecma.AddDirectory (dir);
83 break;
85 case "xhtml":
86 case "hb":
87 list.AddRange (formats [format].Select (d => (Provider) new XhtmlProvider (d)));
88 break;
90 case "man":
91 list.Add (new ManProvider (formats [format].ToArray ()));
92 break;
94 case "simple":
95 list.AddRange (formats [format].Select (d => (Provider) new SimpleProvider (d)));
96 break;
98 case "error":
99 list.AddRange (formats [format].Select (d => (Provider) new ErrorProvider (d)));
100 break;
102 case "ecmaspec":
103 list.AddRange (formats [format].Select (d => (Provider) new EcmaSpecProvider (d)));
104 break;
106 case "addins":
107 list.AddRange (formats [format].Select (d => (Provider) new AddinsProvider (d)));
108 break;
112 HelpSource hs = new HelpSource (prefix, true);
113 hs.TraceLevel = TraceLevel;
115 foreach (Provider p in list) {
116 p.PopulateTree (hs.Tree);
119 if (sort && hs.Tree != null)
120 hs.Tree.Sort ();
123 // Flushes the EcmaProvider
125 foreach (Provider p in list)
126 p.CloseTree (hs, hs.Tree);
128 hs.Save ();
131 private static void AddFormat (MDocCommand self, Dictionary<string, List<string>> d, string format, string file)
133 if (format == null)
134 self.Error ("No format specified.");
135 List<string> l;
136 if (!d.TryGetValue (format, out l)) {
137 l = new List<string> ();
138 d.Add (format, l);
140 l.Add (file);