2 // The assembler: Help compiler.
5 // Miguel de Icaza (miguel@gnome.org)
7 // (C) 2003 Ximian, Inc.
10 using System
.Collections
.Generic
;
16 namespace Mono
.Documentation
{
18 public class MDocAssembler
: MDocCommand
{
19 static readonly string[] ValidFormats
= {
29 public static Option
[] CreateFormatOptions (MDocCommand self
, Dictionary
<string, List
<string>> formats
)
31 string cur_format
= "ecma";
32 var options
= new OptionSet () {
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'.",
39 if (Array
.IndexOf (ValidFormats
, v
) < 0)
40 self
.Error ("Invalid documentation format: {0}.", v
);
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 () {
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 SimpleProvider (d
)));
99 list
.AddRange (formats
[format
].Select (d
=> (Provider
) new ErrorProvider (d
)));
103 list
.AddRange (formats
[format
].Select (d
=> (Provider
) new EcmaSpecProvider (d
)));
107 list
.AddRange (formats
[format
].Select (d
=> (Provider
) new AddinsProvider (d
)));
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)
123 // Flushes the EcmaProvider
125 foreach (Provider p
in list
)
126 p
.CloseTree (hs
, hs
.Tree
);
131 private static void AddFormat (MDocCommand self
, Dictionary
<string, List
<string>> d
, string format
, string file
)
134 self
.Error ("No format specified.");
136 if (!d
.TryGetValue (format
, out l
)) {
137 l
= new List
<string> ();