diff options
author | Jonathan Pryor <jpryor@novell.com> | 2010-02-27 01:33:16 +0300 |
---|---|---|
committer | Jonathan Pryor <jpryor@novell.com> | 2010-02-27 01:33:16 +0300 |
commit | e24a4c48bf2f3161b21cde6a508e9ed66888ceef (patch) | |
tree | f801069dee6007aa4b2cd7514ce7d38183a43b9a /mcs/tools | |
parent | 170e3d25119fbe93b34a52d20c59150b6c0b7bb7 (diff) |
* Mono.Documentation/assembler.cs: Allow other apps to get the same
'--format' logic, specifically 'mdoc export-html-webdoc'.
* Mono.Documentation/webdoc.cs: Allow it to be more "stand-alone".
Previously, it would depend upon the system-wide .source files.
This is bad, because you might want to generate the 'cache'
directory for a different installation, with a different set of
.tree/.zip/.source files, and you might not want to replace your own
and/or you often forget, as is the case with me. Instead, allow a
format to be specified for .tree files, and allow additional .source
files to be referenced so that extension methods will be found within
the specified sources. This allows for a "stand-alone" method of
operation w/o depending upon the system-wide .source files.
svn path=/branches/mono-2-6/mcs/; revision=152591
Diffstat (limited to 'mcs/tools')
-rw-r--r-- | mcs/tools/mdoc/ChangeLog | 15 | ||||
-rw-r--r-- | mcs/tools/mdoc/Mono.Documentation/assembler.cs | 48 | ||||
-rw-r--r-- | mcs/tools/mdoc/Mono.Documentation/webdoc.cs | 47 |
3 files changed, 72 insertions, 38 deletions
diff --git a/mcs/tools/mdoc/ChangeLog b/mcs/tools/mdoc/ChangeLog index 17a8faf7875..cd544d8207d 100644 --- a/mcs/tools/mdoc/ChangeLog +++ b/mcs/tools/mdoc/ChangeLog @@ -1,3 +1,18 @@ +2010-02-26 Jonathan Pryor <jpryor@novell.com> + + * Mono.Documentation/assembler.cs: Allow other apps to get the same + '--format' logic, specifically 'mdoc export-html-webdoc'. + * Mono.Documentation/webdoc.cs: Allow it to be more "stand-alone". + Previously, it would depend upon the system-wide .source files. + This is bad, because you might want to generate the 'cache' + directory for a different installation, with a different set of + .tree/.zip/.source files, and you might not want to replace your own + and/or you often forget, as is the case with me. Instead, allow a + format to be specified for .tree files, and allow additional .source + files to be referenced so that extension methods will be found within + the specified sources. This allows for a "stand-alone" method of + operation w/o depending upon the system-wide .source files. + 2010-01-11 Jonathan Pryor <jpryor@novell.com> * Mono.Documentation/monodocs2slashdoc.cs: Fix NamespaceSummaries.xml diff --git a/mcs/tools/mdoc/Mono.Documentation/assembler.cs b/mcs/tools/mdoc/Mono.Documentation/assembler.cs index b8a48066b1c..1f6e1a1fd0c 100644 --- a/mcs/tools/mdoc/Mono.Documentation/assembler.cs +++ b/mcs/tools/mdoc/Mono.Documentation/assembler.cs @@ -16,37 +16,49 @@ using Mono.Options; namespace Mono.Documentation { public class MDocAssembler : MDocCommand { - public override void Run (IEnumerable<string> args) + static readonly string[] ValidFormats = { + "ecma", + "ecmaspec", + "error", + "hb", + "man", + "simple", + "xhtml" + }; + + public static Option[] CreateFormatOptions (MDocCommand self, Dictionary<string, List<string>> formats) { - string[] validFormats = { - "ecma", - "ecmaspec", - "error", - "hb", - "man", - "simple", - "xhtml" - }; - var formats = new Dictionary<string, List<string>> (); - string prefix = "tree"; 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" + + string.Join ("\n ", ValidFormats) + "\n" + "If not specified, the default format is `ecma'.", v => { - if (Array.IndexOf (validFormats, v) < 0) - Error ("Invalid documentation format: {0}.", 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<string> args) + { + var formats = new Dictionary<string, List<string>> (); + 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 }, - { "<>", v => AddFormat (formats, cur_format, v) }, + formatOptions [1], }; List<string> extra = Parse (options, args, "assemble", "[OPTIONS]+ DIRECTORIES", @@ -116,10 +128,10 @@ public class MDocAssembler : MDocCommand { hs.Save (); } - private void AddFormat (Dictionary<string, List<string>> d, string format, string file) + private static void AddFormat (MDocCommand self, Dictionary<string, List<string>> d, string format, string file) { if (format == null) - Error ("No format specified."); + self.Error ("No format specified."); List<string> l; if (!d.TryGetValue (format, out l)) { l = new List<string> (); diff --git a/mcs/tools/mdoc/Mono.Documentation/webdoc.cs b/mcs/tools/mdoc/Mono.Documentation/webdoc.cs index 57179978208..76a34285720 100644 --- a/mcs/tools/mdoc/Mono.Documentation/webdoc.cs +++ b/mcs/tools/mdoc/Mono.Documentation/webdoc.cs @@ -50,30 +50,44 @@ namespace Mono.Documentation { string dir = null; bool forceUpdate = false; + var formats = new Dictionary<string, List<string>> (); + var formatOptions = MDocAssembler.CreateFormatOptions (this, formats); + var sources = new List<string>(); var options = new OptionSet () { { "force-update", "Always generate new files. If not specified, will only generate " + "files if the write time of the output directory is older than the " + "write time of the source .tree/.zip files.", v => forceUpdate = v != null }, + formatOptions [0], { "o|out=", "The {PREFIX} to place the generated files and directories. " + "Default: \"`dirname FILE`/cache/\".\n" + "Underneath {PREFIX}, `basename FILE .tree` directories will be " + "created which will contain the pre-generated HTML content.", v => dir = v }, + { "r=", + "A {SOURCE} file to use for reference purposes.\n" + + "Extension methods are searched for among all {SOURCE}s which are referenced.\n" + + "This option may be specified multiple times.", + v => sources.Add (v) }, + formatOptions [1], }; - List<string> files = Parse (options, args, "export-html-webdoc", + Parse (options, args, "export-html-webdoc", "[OPTIONS]+ FILES", "Export mdoc documentation within FILES to HTML for use by ASP.NET webdoc.\n\n" + "FILES are .tree or .zip files as produced by 'mdoc assemble'."); - if (files == null) - return; - if (files.Count == 0) + if (formats.Values.All (files => files.Count == 0)) Error ("No files specified."); HelpSource.use_css = true; HelpSource.FullHtml = false; SettingsHandler.Settings.EnableEditing = false; + foreach (var p in formats) + ProcessFiles (dir, forceUpdate, sources, p.Key, p.Value); + } + + void ProcessFiles (string dir, bool forceUpdate, List<string> sources, string format, List<string> files) + { foreach (var basePath in files.Select (f => Path.Combine (Path.GetDirectoryName (f), Path.GetFileNameWithoutExtension (f))) @@ -91,7 +105,7 @@ namespace Mono.Documentation Message (TraceLevel.Warning, "Processing files: {0}, {1}", treeFile, zipFile); Directory.CreateDirectory (outDir); ExtractZipFile (zipFile, outDir); - GenerateCache (basePath, treeFile, outDir); + GenerateCache (basePath, format, outDir, sources); } } @@ -123,16 +137,16 @@ namespace Mono.Documentation } } - void GenerateCache (string basePath, string treeFile, string outDir) + void GenerateCache (string basePath, string format, string outDir, IEnumerable<string> sources) { - Tree tree = new Tree (null, treeFile); - RootTree docRoot = RootTree.LoadTree (); - string helpSourceName = Path.GetFileName (basePath); - HelpSource hs = docRoot.HelpSources.Cast<HelpSource> () - .FirstOrDefault (h => h.Name == helpSourceName); + var hs = RootTree.GetHelpSource (format, basePath); if (hs == null) { - throw new Exception ("Only installed .tree and .zip files are supported."); + Error ("Unable to find a HelpSource for provider '{0}' and file '{1}.tree'.", format, basePath); } + var tree = hs.Tree; + RootTree docRoot = RootTree.LoadTree (null, null, sources); + hs.RootTree = docRoot; + string helpSourceName = Path.GetFileName (basePath); foreach (Node node in tree.TraverseDepthFirst<Node, Node> (t => t, t => t.Nodes.Cast<Node> ())) { var url = node.URL; Message (TraceLevel.Info, "\tProcessing URL: {0}", url); @@ -141,14 +155,7 @@ namespace Mono.Documentation var file = XmlDocUtils.GetCachedFileName (outDir, url); using (var o = File.AppendText (file)) { Node _; - // Sometimes the HelpSource won't directly support a url. - // Case in point: the Tree will contain N:Enter.Namespace.Here nodes - // which aren't supported by HelpSource.GetText. - // If this happens, docRoot.RenderUrl() works. - // (And no, we can't always use docRoot.RenderUrl() for URLs like - // "ecma:0#Foo/", as that'll just grab the 0th stream contents from - // the first EcmaHelpSource found... - string contents = hs.GetText (url, out _) ?? docRoot.RenderUrl (url, out _); + string contents = hs.GetText (url, out _) ?? hs.RenderNamespaceLookup (url, out _); o.Write (contents); } } |