[Mono-docs-list] Web based Monodoc

Philippe Desaulniers filou@histrion.org
07 Jul 2003 22:36:19 -0400


--=-EZ6Iec1u3JfykKKK6a+s
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hello,

I've gotten a web based monodoc to work, if anyone is interested
you can try it out.

It requires a patch to browser.cs and Makefile.am, I'm including 
diffs against the current sources. It also requires a new xsl file
(mono-hrefreplace.xsl), that you'll find attached.

I've also included an example cgi script that makes use of the 
modification. You can take see what it looks like here:
http://filou.homelinux.org/monodoc/monodoc.cgi?N:System
(I can't guaranty that URL will live excessively long...)

If project owners feel this is a relevant contribution, I'm willing 
to commit it to the tree, just let me know if I'm breaking any project
code formatting rules, I'll make fixes beforehand.

I'll start trying to figure out a way to get indexes working. Any ideas
welcome. 

Thanks,

phil



--=-EZ6Iec1u3JfykKKK6a+s
Content-Disposition: attachment; filename=Makefile.am.diff.txt
Content-Type: text/x-patch; name=Makefile.am.diff.txt; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

Index: Makefile.am
===================================================================
RCS file: /mono/monodoc/browser/Makefile.am,v
retrieving revision 1.17
diff -r1.17 Makefile.am
11c11
< EXTRA_DIST = $(assembler_sources) $(dump_sources) $(browser_sources) browser.glade monodoc.xml mono-ecma.xsl 
---
> EXTRA_DIST = $(assembler_sources) $(dump_sources) $(browser_sources) browser.glade monodoc.xml mono-ecma.xsl mono-hrefreplace.xsl 
18,19c18,19
< 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)
---
> browser.exe: $(browser_sources) browser.glade mono-ecma.xsl mono-hrefreplace.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 /resource:$(srcdir)/mono-hrefreplace.xsl,mono-hrefreplace.xsl $(browser_assemblies)

--=-EZ6Iec1u3JfykKKK6a+s
Content-Disposition: attachment; filename=browser.cs.diff.txt
Content-Type: text/x-patch; name=browser.cs.diff.txt; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

Index: browser.cs
===================================================================
RCS file: /mono/monodoc/browser/browser.cs,v
retrieving revision 1.33
diff -r1.33 browser.cs
19a20,21
> using System.Xml;
> using System.Xml.Xsl;
43,45c45,56
< 				if (i+1 == args.Length){
< 					Console.WriteLine ("--html needed argument");
< 					return 1; 
---
> 			case "--www":
> 				string processor_url = null;
> 
> 				if (args [i] == "--html") {
> 					if (i+1 == args.Length){
> 						Console.WriteLine ("--html needed argument");
> 						return 1; 
> 					}
> 
> 					else {
> 						topic = args [i+1];
> 					}
47c58,70
< 				
---
> 
> 				else if (args [i] == "--www") {
> 					if (i+2 == args.Length){
> 						Console.WriteLine ("--www needs two arguments");
> 						return 1; 
> 					}
> 
> 					else {
> 						processor_url = args [i+1];
> 						topic = args [i+2];
> 					}
> 				}
> 
50c73,74
< 				string res = help_tree.RenderUrl (args [i+1], out n);
---
> 
> 				string res = help_tree.RenderUrl (topic, out n);
51a76,102
> 					if (args [i] == "--www") {
> 						// Provider output is not valid XML, need to add XML header and a root node
> 						res = "<?xml version=\"1.0\" ?>\n<monodoc-provider-output>\n" 
> 							+ res 
> 							+ "\n</monodoc-provider-output>";
> 
> 						XsltArgumentList xsl_args = new XsltArgumentList();
> 						xsl_args.AddParam("processorurl", "", processor_url);
> 
> 						XslTransform hrefreplace_transform = new XslTransform ();
> 
> 						Assembly assembly = System.Reflection.Assembly.GetCallingAssembly ();
> 						Stream stream = assembly.GetManifestResourceStream ("mono-hrefreplace.xsl");
> 
> 						XmlReader xml_reader = new XmlTextReader (stream);
> 						hrefreplace_transform.Load (xml_reader);
> 		
> 						XmlDocument source = new XmlDocument();
> 						source.LoadXml(res);
> 
> 						StringWriter output = new StringWriter ();
> 
> 						hrefreplace_transform.Transform (source, xsl_args, output);
> 		
> 						res = output.ToString();
> 					}
> 
63c114
< 						   "browser [--html TOPIC] [--make-index] [TOPIC]");
---
> 						   "browser [--html TOPIC] [--www PROCESSOR_URL TOPIC] [--make-index] [TOPIC]");

--=-EZ6Iec1u3JfykKKK6a+s
Content-Disposition: attachment; filename=mono-hrefreplace.xsl
Content-Type: text/plain; name=mono-hrefreplace.xsl; charset=us-ascii
Content-Transfer-Encoding: quoted-printable

<?xml version=3D"1.0" ?>=20

<!--
	mono-hrefreplace.xsl: Prepends all MonoDoc native href's with a processor =
URL (so MonoDoc output can be used
	                      by a regular browser)

	Author: Philippe Desaulniers (filou@histrion.org)
-->

<xsl:stylesheet xmlns:xsl=3D"http://www.w3.org/1999/XSL/Transform" version=
=3D"1.0">

	<xsl:param name=3D"processorurl"/>

	<xsl:template match=3D"monodoc-provider-output">
		<xsl:apply-templates select=3D"node()"/>
	</xsl:template>
       =20
	<xsl:template match=3D"@*|node()">
		<xsl:choose>
			<!-- Ignore the root element, which is a placeholder to get valid XML ou=
tput from the Provider -->
			<xsl:when test=3D"local-name(.) =3D 'monodoc-provider-output'" />

			<!-- Replace monodoc specific URLs -->
			<xsl:when test=3D"local-name(.) =3D 'href' and=20
			                ( substring-before(., ':') =3D 'N' or
			                  substring-before(., ':') =3D 'T' or=20
			                  substring-before(., ':') =3D 'C' or=20
			                  substring-before(., ':') =3D 'M' or=20
			                  substring-before(., ':') =3D 'P' or=20
			                  substring-before(., ':') =3D 'F' or=20
			                  substring-before(., ':') =3D 'E' or=20
			                  substring-before(., ':') =3D 'source-id')">

				<xsl:attribute name=3D"href"><xsl:value-of select=3D"$processorurl"/><x=
sl:value-of select=3D"."/></xsl:attribute>
			</xsl:when>
         =20
			<xsl:otherwise>
				<xsl:copy>
					<xsl:apply-templates select=3D"@*|node()"/>
				</xsl:copy>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

</xsl:stylesheet>

--=-EZ6Iec1u3JfykKKK6a+s
Content-Disposition: attachment; filename=monodoc.cgi
Content-Type: text/x-perl; name=monodoc.cgi; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

#!/usr/bin/perl
#
#  monodoc.cgi: Perl usage example of the --www option of the monodoc browser.
# 
#  Author: Philippe Desaulniers (filou@histrion.org)
# 
#  Remarks: This is just a quick hack until a more elaborate ASP.NET integration 
#           of monodoc is developed, and is not intended for production use...
#

print "Content-type: text/html\n\n";
print "<html>\n";
print "<head>\n";
print "<title>Monodoc Documentation Browser</title>\n";
print "</head>\n";
print "<body>\n";

system("monodoc --www 'monodoc.cgi?' '$ENV{QUERY_STRING}'");

print "</body>\n";
print "</html>\n";

--=-EZ6Iec1u3JfykKKK6a+s--