// // The assembler: Help compiler. // // Author: // Miguel de Icaza (miguel@gnome.org) // // (C) 2003 Ximian, Inc. // using System; using System.Collections.Generic; using System.Linq; using System.Xml; using Monodoc; using Mono.Options; namespace Mono.Documentation { public class MDocAssembler : MDocCommand { static readonly string[] ValidFormats = { "ecma", "ecmaspec", "error", "hb", "man", "simple", "xhtml" }; public static Option[] CreateFormatOptions (MDocCommand self, Dictionary> formats) { string cur_format = "ecma"; var options = new OptionSet () { { "f|format=", "The documentation {FORMAT} used in DIRECTORIES. " + "Valid formats include:\n " + string.Join ("\n ", ValidFormats) + "\n" + "If not specified, the default format is `ecma'.", v => { if (Array.IndexOf (ValidFormats, v) < 0) self.Error ("Invalid documentation format: {0}.", v); cur_format = v; } }, { "<>", v => AddFormat (self, formats, cur_format, v) }, }; return new Option[]{options[0], options[1]}; } public override void Run (IEnumerable args) { var formats = new Dictionary> (); string prefix = "tree"; string cur_format = "ecma"; var formatOptions = CreateFormatOptions (this, formats); var options = new OptionSet () { formatOptions [0], { "o|out=", "Provides the output file prefix; the files {PREFIX}.zip and " + "{PREFIX}.tree will be created.\n" + "If not specified, `tree' is the default PREFIX.", v => prefix = v }, formatOptions [1], }; List extra = Parse (options, args, "assemble", "[OPTIONS]+ DIRECTORIES", "Assemble documentation within DIRECTORIES for use within the monodoc browser."); if (extra == null) return; List list = new List (); EcmaProvider ecma = null; bool sort = false; foreach (string format in formats.Keys) { switch (format) { case "ecma": if (ecma == null) { ecma = new EcmaProvider (); list.Add (ecma); sort = true; } foreach (string dir in formats [format]) ecma.AddDirectory (dir); break; case "xhtml": case "hb": list.AddRange (formats [format].Select (d => (Provider) new XhtmlProvider (d))); break; case "man": list.Add (new ManProvider (formats [format].ToArray ())); break; case "simple": list.AddRange (formats [format].Select (d => (Provider) new SimpleProvider (d))); break; case "error": list.AddRange (formats [format].Select (d => (Provider) new ErrorProvider (d))); break; case "ecmaspec": list.AddRange (formats [format].Select (d => (Provider) new EcmaSpecProvider (d))); break; case "addins": list.AddRange (formats [format].Select (d => (Provider) new AddinsProvider (d))); break; } } HelpSource hs = new HelpSource (prefix, true); hs.TraceLevel = TraceLevel; foreach (Provider p in list) { p.PopulateTree (hs.Tree); } if (sort && hs.Tree != null) hs.Tree.Sort (); // // Flushes the EcmaProvider // foreach (Provider p in list) p.CloseTree (hs, hs.Tree); hs.Save (); } private static void AddFormat (MDocCommand self, Dictionary> d, string format, string file) { if (format == null) self.Error ("No format specified."); List l; if (!d.TryGetValue (format, out l)) { l = new List (); d.Add (format, l); } l.Add (file); } } }