// // webdoc.cs // // Author: // Jonathan Pryor // // Copyright (c) 2009 Novell, Inc. (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the // "Software"), to deal in the Software without restriction, including // without limitation the rights to use, copy, modify, merge, publish, // distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to // the following conditions: // // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; using System.Web; using Monodoc; using Mono.Options; using Mono.Rocks; namespace Mono.Documentation { public class MDocExportWebdocHtml : MDocCommand { public override void Run (IEnumerable args) { string dir = null; var options = new OptionSet () { { "o|out=", "The {DIRECTORY} to place the generated files and directories.", v => dir = v }, }; List files = 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 update'."); if (files == null) return; if (files.Count == 0) Error ("No files specified."); HelpSource.use_css = true; HelpSource.FullHtml = false; SettingsHandler.Settings.EnableEditing = false; foreach (var basePath in files.Select (f => Path.GetFileNameWithoutExtension (f)).Distinct ()) { Console.WriteLine ("# Processing BasePath={0}", basePath); string treeFile = basePath + ".tree"; string zipFile = basePath + ".zip"; if (!Exists (treeFile) || !Exists (zipFile)) continue; Console.WriteLine ("# Tree file={0}", treeFile); Tree tree = new Tree (null, treeFile); RootTree docRoot = RootTree.LoadTree (); // monodoc url == docRoot.RenderUrl // tree link == HelpSource.GetText() Console.WriteLine ("# tree contents:"); Tree.PrintTree (tree); foreach (Node node in tree.TraverseDepthFirst (t => t, t => t.Nodes.Cast ())) { var url = node.URL; Console.WriteLine ("# NodeUrl={0}", url); if (string.IsNullOrEmpty (url)) continue; var file = Path.Combine (dir, HttpUtility.UrlEncode (url).Replace ('/', '+').Replace ("*", "%2a")); Console.WriteLine ("# file={0}", file); using (var o = File.AppendText (file)) { Node _; o.Write (docRoot.RenderUrl (url, out _)); // tree.HelpSource.GetText (url, out _)); } } } } bool Exists (string file) { if (!File.Exists (file)) { Message (TraceLevel.Error, "mdoc: Could not find file: {0}", file); return false; } return true; } } }