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


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)
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]");
<?xml version="1.0" ?> 

<!--
        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 ([EMAIL PROTECTED])
-->

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

        <xsl:param name="processorurl"/>

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

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

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

</xsl:stylesheet>
#!/usr/bin/perl
#
#  monodoc.cgi: Perl usage example of the --www option of the monodoc browser.
# 
#  Author: Philippe Desaulniers ([EMAIL PROTECTED])
# 
#  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";

Reply via email to