[Mono-docs-list] Monodoc aspx .1 -- Beter version

Ben Maurer bmaurer@users.sourceforge.net
12 Jul 2003 21:44:23 -0500


--=-gNqXP46pJHwtS+NNgI1b
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Ok, I have made a better version. New instructions:

     1. install the xml patch in the parent thread
     2. install the attached patch
     3. cd monodoc; ./autogen.sh; make install
     4. cd /xsp/path/bin/; ln -s
        /usr/lib/monodoc/Mono.Website.Handlers.dll .
     5. Use the following for web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.web>
	<httpHandlers>
		<add verb="*" path="*.mdoc"
type="Mono.Website.Handlers.MonodocHandler,Mono.Website.Handlers.MonodocHandler" />
	</httpHandlers> 
	</system.web>
</configuration>

You can see the docs at http://localhost:8080/a.mdoc.

-- Ben

--=-gNqXP46pJHwtS+NNgI1b
Content-Disposition: attachment; filename=monodocaspx.patch
Content-Type: text/x-patch; name=monodocaspx.patch; charset=UTF-8
Content-Transfer-Encoding: 7bit

Index: .cvsignore
===================================================================
RCS file: /cvs/public/monodoc/browser/.cvsignore,v
retrieving revision 1.2
diff -u -r1.2 .cvsignore
--- .cvsignore	6 Jun 2003 03:28:17 -0000	1.2
+++ .cvsignore	13 Jul 2003 02:46:20 -0000
@@ -1,3 +1,4 @@
+*.dll
 *dbg
 *tree
 Makefile
Index: ChangeLog
===================================================================
RCS file: /cvs/public/monodoc/browser/ChangeLog,v
retrieving revision 1.46
diff -u -r1.46 ChangeLog
--- ChangeLog	11 Jul 2003 02:00:07 -0000	1.46
+++ ChangeLog	13 Jul 2003 02:46:20 -0000
@@ -1,3 +1,9 @@
+2003-07-12  Ben Maurer <bmaurer@users.sourceforge.net>
+	* browser.cs: Added support for visiting nodes from the root tree.
+	* ecma-provider.cs: Render the root: url with a list of namespaces
+	* provider.cs: Send the root:/xxx to the help sources. Handle
+	root:
+
 2003-07-10  Ben Maurer <bmaurer@users.sourceforge.net>
 
 	* mono-ecma.xsl: Don't generate the excess monodoc namespaces.
Index: Makefile.am
===================================================================
RCS file: /cvs/public/monodoc/browser/Makefile.am,v
retrieving revision 1.17
diff -u -r1.17 Makefile.am
--- Makefile.am	26 Jun 2003 05:51:59 -0000	1.17
+++ Makefile.am	13 Jul 2003 02:46:20 -0000
@@ -1,5 +1,5 @@
 monodocdir = $(libdir)/monodoc
-monodoc_DATA = browser.exe assembler.exe monodoc.xml
+monodoc_DATA = browser.exe assembler.exe monodoc.xml Mono.Website.Handlers.MonodocHandler.dll
 CSC=mcs
 
 shared_sources = $(srcdir)/monohb-provider.cs $(srcdir)/xhtml-provider.cs $(srcdir)/ecma-provider.cs $(srcdir)/simple-provider.cs $(srcdir)/html-helper.cs $(srcdir)/provider.cs $(srcdir)/index.cs
@@ -17,6 +17,9 @@
 
 browser.exe: $(browser_sources) browser.glade mono-ecma.xsl $(srcdir)/../monodoc.png
 	$(CSC) /debug /out:browser.exe $(browser_sources) /resource:$(srcdir)/../monodoc.png,monodoc.png /resource:$(srcdir)/browser.glade,browser.glade /resource:$(srcdir)/mono-ecma.xsl,mono-ecma.xsl $(browser_assemblies)
+
+Mono.Website.Handlers.MonodocHandler.dll: $(shared_sources) mono-ecma.xsl $(srcdir)/../monodoc.png $(srcdir)/MonodocHandler.cs
+	$(CSC) /debug /out:Mono.Website.Handlers.MonodocHandler.dll /target:library $(srcdir)/MonodocHandler.cs -r:ICSharpCode.SharpZipLib.dll -r System.Web.dll $(shared_sources) /resource:$(srcdir)/../monodoc.png,monodoc.png /resource:$(srcdir)/mono-ecma.xsl,mono-ecma.xsl
 
 dump.exe: $(dump_sources) 
 	$(CSC) /debug /out:dump.exe $(dump_sources)  -r:ICSharpCode.SharpZipLib.dll
Index: MonodocHandler.cs
===================================================================
RCS file: MonodocHandler.cs
diff -N MonodocHandler.cs
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ MonodocHandler.cs	13 Jul 2003 02:46:20 -0000
@@ -0,0 +1,126 @@
+//
+// Mono.Web.Handlers.MonodocHandler
+//
+// Authors:
+//	Ben Maurer (bmaurer@users.sourceforge.net)
+//
+// (C) 2003 Ben Maurer
+//
+
+using System;
+using System.Collections;
+using System.IO;
+using System.Text;
+using System.Web;
+using System.Web.UI;
+using System.Xml;
+using System.Xml.Xsl;
+
+namespace Mono.Website.Handlers
+{
+	public class MonodocHandler : IHttpHandler
+	{
+		static RootTree help_tree;
+		static MonodocHandler ()
+		{
+			help_tree = RootTree.LoadTree ("/devel/install/lib/monodoc/");
+		}
+
+		void IHttpHandler.ProcessRequest (HttpContext context)
+		{
+			string link = (string) context.Request.Params["link"];
+			if (link == null)
+				link = "root:";
+			
+			if (link.StartsWith ("source-id:") && (link.EndsWith (".gif") || link.EndsWith (".jpeg") || link.EndsWith (".jpg")  || link.EndsWith(".png")))
+			{
+				switch (link.Substring (link.LastIndexOf ('.') + 1))
+				{
+					case "gif":
+						context.Response.ContentType = "image/gif";
+						break;
+					case "jpeg":
+					case "jpg":
+						context.Response.ContentType = "image/jpeg";
+						break;
+					case "png":
+						context.Response.ContentType = "image/png";
+						break;
+					default:
+						throw new Exception ("WTF!?!!?!");
+				}
+				
+				Stream s = help_tree.GetImage (link);
+				
+				if (s == null)
+					throw new HttpException (404, "File not found");
+				
+				Copy (s, context.Response.OutputStream);
+				return;
+			}
+			
+			PrintDocs (link, context);
+		}
+		
+		
+		
+		void Copy (Stream input, Stream output)
+		{
+			const int BUFFER_SIZE=1024; // 1k buf
+			byte [] buffer = new byte [BUFFER_SIZE];
+		
+			int len;
+			while ( (len = input.Read (buffer, 0, BUFFER_SIZE)) > 0)
+				output.Write (buffer, 0, len);
+			
+			output.Flush();
+		}
+		
+		void PrintDocs (string url, HttpContext ctx)
+		{
+			Node n;
+			
+			
+			ctx.Response.Write (@"
+<html>
+<head>
+<script>
+<!--
+function load ()
+{
+	objs = document.getElementsByTagName('a');
+	for (i = 0; i < objs.length; i++)
+	{
+		objs[i].href = '" + ctx.Request.Path + @"?link=' + objs[i].href;
+	}
+			
+	objs = document.getElementsByTagName('img');
+	for (i = 0; i < objs.length; i++)
+	{
+		objs[i].src = '" + ctx.Request.Path + @"?link=' + objs[i].src;
+	}
+}
+-->
+</script>
+<title>Mono Documentation</title>
+</head>
+<body onLoad='load()'>
+
+			");
+			
+			ctx.Response.Write (help_tree.RenderUrl (url, out n));
+		
+			ctx.Response.Write (@"
+			</body>
+</html>");
+		}
+
+		bool IHttpHandler.IsReusable
+		{
+			get {
+				return true;
+			}
+		}
+
+	}
+}
\ No newline at end of file
Index: browser.cs
===================================================================
RCS file: /cvs/public/monodoc/browser/browser.cs,v
retrieving revision 1.37
diff -u -r1.37 browser.cs
--- browser.cs	11 Jul 2003 00:13:10 -0000	1.37
+++ browser.cs	13 Jul 2003 02:46:20 -0000
@@ -529,10 +529,16 @@
 
 		public override void Go ()
 		{
+			string res;
 			Node x;
 			
-			string res = n.tree.HelpSource.GetText (url, out x);
-			((Browser)browser).Render (res, n, url);
+			// The root tree has no help source
+			if (n.tree.HelpSource != null)
+				res = n.tree.HelpSource.GetText (url, out x);
+			else
+				res = ((RootTree)n.tree).RenderUrl (url, out x);
+					
+			browser.Render (res, n, url);
 		}
 	}
 
@@ -554,23 +560,25 @@
 
 		if (tree_view.Selection.GetSelected (out model, ref iter)){
 			Node n = (Node) iter_to_node [iter];
-
-			if (n.tree.HelpSource == null)
-				return;
-
-			string url = n.URL;
 			
-			//
-			// Try the tree-based urls first.
-			//
+			string url = n.URL;
 			Node match;
-			string s = n.tree.HelpSource.GetText (url, out match);
-			if (s != null){
-				((Browser)browser).Render (s, null, url);
-				browser.history.AppendHistory (new NodePageVisit (browser, n, url));
-				return;
+			string s;
+			
+			if (n.tree.HelpSource != null)
+			{
+				//
+				// Try the tree-based urls first.
+				//
+				
+				s = n.tree.HelpSource.GetText (url, out match);
+				if (s != null){
+					((Browser)browser).Render (s, null, url);
+					browser.history.AppendHistory (new NodePageVisit (browser, n, url));
+					return;
+				}
 			}
-
+			
 			//
 			// Try the url resolver next
 			//
Index: ecma-provider.cs
===================================================================
RCS file: /cvs/public/monodoc/browser/ecma-provider.cs,v
retrieving revision 1.51
diff -u -r1.51 ecma-provider.cs
--- ecma-provider.cs	10 Jul 2003 16:34:32 -0000	1.51
+++ ecma-provider.cs	13 Jul 2003 02:46:20 -0000
@@ -384,6 +384,17 @@
 	public override string GetText (string url, out Node match_node)
 	{
 		match_node = null;
+		
+		if (url == "root:")
+		{
+			StringBuilder sb = new StringBuilder ();
+			
+			foreach (Node ns_node in Tree.Nodes)
+				sb.AppendFormat ("<a href='{0}'>{1}</a></br>", ns_node.Element, ns_node.Element.Substring (2));				
+				
+			return sb.ToString ();
+		}
+		
 		if (url.StartsWith ("ecma:"))
 			return GetTextFromUrl (url);
 
Index: monohb-provider.cs
===================================================================
RCS file: /cvs/public/monodoc/browser/monohb-provider.cs,v
retrieving revision 1.4
diff -u -r1.4 monohb-provider.cs
--- monohb-provider.cs	18 Jun 2003 13:24:57 -0000	1.4
+++ monohb-provider.cs	13 Jul 2003 02:46:20 -0000
@@ -20,7 +20,7 @@
 			string cssClass = ((XmlElement)node).GetAttribute("class");
 			if (cssClass != null && (cssClass == "topframe" || cssClass == "navbar" || cssClass == "copyright"))
 			{
-				node.RemoveAll();
+				node.ParentNode.RemoveChild (node);
 			}
                                                                                 
 		}
@@ -53,7 +53,7 @@
 		bodynode.RemoveChild(firstheading);
 
 	bodynode.InnerXml =	"<table width=\"100%\">" +
-			"<tr bgcolor=\"#b0c4dae\"><td><i></i>Mono Handbook<h3>" + headinginner + "</h3></td></tr></table><p />" +
+			"<tr bgcolor=\"#b0c4de\"><td><i></i>Mono Handbook<h3>" + headinginner + "</h3></td></tr></table><p />" +
 	bodynode.InnerXml;
 }
 catch {
@@ -117,6 +117,8 @@
 
 		}
 	}
-		return docToProcess;
+		XmlDocument ret = new XmlDocument ();
+		ret.LoadXml (docToProcess.GetElementsByTagName("body")[0].OuterXml);
+		return ret;
 	}
 }
Index: provider.cs
===================================================================
RCS file: /cvs/public/monodoc/browser/provider.cs,v
retrieving revision 1.34
diff -u -r1.34 provider.cs
--- provider.cs	11 Jul 2003 00:13:10 -0000	1.34
+++ provider.cs	13 Jul 2003 02:46:20 -0000
@@ -552,7 +552,8 @@
 		//
 		// Load the layout
 		//
-		doc.Load ("monodoc.xml");
+		string layout = Path.Combine (basedir, "monodoc.xml");
+		doc.Load (layout);
 		XmlNodeList nodes = doc.SelectNodes ("/node/node");
 
 		root.name_to_node ["root"] = root;
@@ -561,7 +562,7 @@
 		//
 		// Load the sources
 		//
-		string sources_dir = basedir + "/sources/";
+		string sources_dir = Path.Combine (basedir, "sources");
 		
 		string [] files = Directory.GetFiles (sources_dir);
 		foreach (string file in files){
@@ -601,10 +602,11 @@
 				string path = a.InnerText;
 
 				HelpSource hs = null;
+				string basefilepath = Path.Combine (sources_dir, basefile);
 				switch (provider){
 				case "ecma":
 					try {
-						hs = new EcmaHelpSource (sources_dir + basefile, false);
+						hs = new EcmaHelpSource (basefilepath, false);
 					} catch (FileNotFoundException) {
 						Console.Error.WriteLine ("Error: did not find one of the files in sources/"+basefile);
 						break;
@@ -612,7 +614,7 @@
 					break;
 				case "monohb":
 					try {
-						hs = new MonoHBHelpSource(sources_dir + basefile, false);
+						hs = new MonoHBHelpSource(basefilepath, false);
 					} catch (FileNotFoundException) {
 						Console.Error.WriteLine ("Error: did not find one of the files in sources/"+basefile);
 						break;
@@ -628,7 +630,7 @@
 					break;
 				case "simple":
 					try {
-						hs = new SimpleHelpSource (sources_dir + basefile, false);
+						hs = new SimpleHelpSource (basefilepath, false);
 					} catch (FileNotFoundException) {
 						Console.Error.WriteLine ("Error: did not find one of the files in sources/"+basefile);
 						break;
@@ -641,6 +643,7 @@
 				if (hs == null)
 					continue;
 				root.help_sources.Add (hs);
+				root.name_to_hs [path] = hs;
 
 				Node parent = (Node) root.name_to_node [path];
 				if (parent == null){
@@ -661,6 +664,7 @@
 	// Maintains the name to node mapping
 	//
 	Hashtable name_to_node = new Hashtable ();
+	Hashtable name_to_hs = new Hashtable ();
 	
 	void Populate (Node parent, XmlNodeList xml_node_list)
 	{
@@ -678,7 +682,7 @@
 			}
 			string name = e.InnerText;
 
-			Node n = parent.LookupNode (label, name);
+			Node n = parent.LookupNode (label, "root:/" + name);
 			n.EnsureNodes ();
 			name_to_node [name] = n;
 			XmlNodeList children = xml_node.SelectNodes ("./node");
@@ -812,7 +816,20 @@
 	///    URL.
 	/// </summary>
 	public string RenderUrl (string url, out Node match_node)
-	{
+	{	
+		if (url.StartsWith ("root:"))
+		{
+			match_node = null;
+			if (url == "root:") {
+				StringBuilder sb = new StringBuilder ("<h1>Welcome to Monodoc</h1>");
+				foreach (Node n in Nodes)
+					sb.AppendFormat ("<a href='{0}'>{1}</a></br>", n.Element, n.Caption);
+				return sb.ToString ();
+				
+			} else
+				return ((HelpSource)name_to_hs [url.Substring (6)]).GetText ("root:", out match_node);
+		}
+		
 		if (url.StartsWith ("source-id:")){
 			string rest = url.Substring (10);
 			int p = rest.IndexOf (":");
Index: xhtml-provider.cs
===================================================================
RCS file: /cvs/public/monodoc/browser/xhtml-provider.cs,v
retrieving revision 1.11
diff -u -r1.11 xhtml-provider.cs
--- xhtml-provider.cs	26 Jun 2003 19:12:02 -0000	1.11
+++ xhtml-provider.cs	13 Jul 2003 02:46:20 -0000
@@ -55,6 +55,27 @@
 	public override string GetText (string url, out Node match_node)
 	{
 		match_node = null;
+		
+		if (url == "root:") {
+			StringBuilder sb = new StringBuilder ();
+			foreach (Node n in Tree.Nodes) {
+				if (n.IsLeaf) { 
+					sb.AppendFormat ("<a href='{0}'>{1}</a></br>", 
+						n.Element.Replace ("source-id:NNN", "source-id:" + SourceID), 
+						n.Caption);
+				} else {
+					sb.AppendFormat ("<h2>{0}</h2>", n.Caption);
+					foreach (Node subNode in n.Nodes) {
+						sb.AppendFormat ("<a href='{0}'>{1}</a></br>", 
+							subNode.Element.Replace ("source-id:NNN", "source-id:" + SourceID), 
+							subNode.Caption);
+					}
+				}
+			}
+			
+			return sb.ToString ();
+		}
+		
 		if (url.IndexOf (XHTML_PREFIX) > -1)
 			return GetTextFromUrl (url);
 
@@ -227,7 +248,7 @@
 			
 			XmlDocument processedDoc = ProcessContent(newdoc);
 			XmlDocument docForMonodoc = RewriteLinks(processedDoc, url);
-			return docForMonodoc.InnerXml;
+			return docForMonodoc.DocumentElement.InnerXml; // get rid of <body>
 		}
 
 		else if (s != null && (fname.EndsWith (".gif") || fname.EndsWith (".jpeg") || fname.EndsWith (".jpg")  || fname.EndsWith(".png")))

--=-gNqXP46pJHwtS+NNgI1b--