Add support for embedding image files in ecma doc
authorJeremie Laval <jeremie.laval@gmail.com>
Sun, 30 Oct 2011 15:11:15 +0000 (16:11 +0100)
committerJeremie Laval <jeremie.laval@gmail.com>
Sun, 30 Oct 2011 15:11:43 +0000 (16:11 +0100)
mcs/tools/mdoc/Resources/monodoc-ecma.xsd
mcs/tools/monodoc/Monodoc/ecma-provider.cs
mcs/tools/monodoc/Monodoc/provider.cs
mcs/tools/monodoc/Resources/mdoc-html-utils.xsl

index ed63ed9c675b0b75f455266aeb41f1e596e39de9..b848f4b453ff4994c445a7320c8aceb3fd5454a4 100644 (file)
@@ -509,10 +509,18 @@ add masterdoc support?
         <xs:element ref="theta" />
         <xs:element ref="typeparamref" />
         <xs:element ref="whitespace" />
+        <xs:element ref="img" />
       </xs:choice>
     </xs:complexType>
   </xs:element>
 
+  <xs:element name="img">
+       <xs:complexType>
+         <xs:attribute name="href" type="xs:string" use="required" />
+         <xs:attribute name="class" type="xs:string" use="optional" />
+       </xs:complexType>
+  </xs:element>
+
   <xs:element name="param">
     <xs:complexType mixed="true">
       <xs:choice minOccurs="0" maxOccurs="unbounded">
index d654a9a7f6bf3130101df907bde2f11f5a7aa7cb..46988fcd08f46fab5f0e47dedb9ef2fab5f67004 100644 (file)
@@ -141,6 +141,12 @@ public static class EcmaDoc {
                return nsxml;
        }
 
+       internal static string GetImageFile (string dir, string img)
+       {
+               string path = Path.Combine (dir, "_images", img);
+               return File.Exists (path) ? path : null;
+       }
+
        public static string GetCref (XmlElement member)
        {
                string typeName = XmlDocUtils.ToEscapedTypeName (member.SelectSingleNode("/Type/@FullName").InnerText);
@@ -366,6 +372,7 @@ public class EcmaProvider : Provider {
                }
                tree.HelpSource.PackXml ("mastersummary.xml", nsSummary, null);
                AddExtensionMethods (tree);
+               AddImageFiles (hs, tree);
        }
 
        void AddExtensionMethods (Tree tree)
@@ -397,7 +404,22 @@ public class EcmaProvider : Provider {
                        tree.HelpSource.PackXml ("ExtensionMethods.xml", extensions, "ExtensionMethods.xml");
                }
        }
-              
+
+       void AddImageFiles (HelpSource hs, Tree tree)
+       {
+               foreach (string asm in asm_dirs) {
+                       string path = Path.Combine (asm, "_images");
+                       Console.WriteLine ("Loulou {0}", path);
+                       if (!Directory.Exists (path))
+                               return;
+
+                       foreach (var img in Directory.EnumerateFiles (path)) {
+                               Console.WriteLine ("adding {0}", img);
+                               hs.PackFile (img, Path.GetFileName (img));
+                       }
+               }
+       }
+      
        Hashtable/*<string, List<TypeInfo>>*/ class_summaries = new Hashtable ();
        Hashtable/*<string, XmlNode>*/ namespace_summaries = new Hashtable ();
        Hashtable/*<string, XmlNode>*/ namespace_remarks = new Hashtable ();
@@ -1277,6 +1299,8 @@ public class EcmaHelpSource : HelpSource {
                XsltArgumentList args = new XsltArgumentList();
 
                args.AddExtensionObject("monodoc:///extensions", ExtObject);
+
+               args.AddParam ("source-id", "", SourceID.ToString ());
                
                if (rest == "") {
                        args.AddParam("show", "", "typeoverview");
@@ -1784,6 +1808,13 @@ public class EcmaHelpSource : HelpSource {
                        return node.URL[idx+1] + ":" + full + "." + node.Caption;
                }
        }
+
+       public override Stream GetImage (string url)
+       {
+               if (url.Contains ("/"))
+                       url = url.Substring (url.LastIndexOf ('/') + 1);
+               return GetHelpStream (url);
+       }
                                
        //
        // Populates the index.
@@ -2327,6 +2358,14 @@ public class EcmaUncompiledHelpSource : EcmaHelpSource {
                doc.Load (id);
                return doc;
        }
+
+       public virtual Stream GetImage (string url)
+       {
+               string path = EcmaDoc.GetImageFile (basedir.FullName, url);
+               if (path == null)
+                       return null;
+               return File.OpenRead (path);
+       }
        
        class UncompiledResolver : XmlResolver {
                public override Uri ResolveUri (Uri baseUri, string relativeUri)
index e412d2da17769e53bc2cbb19b3cea974b0f2a0fd..56f10d34c0257ba9ea9c3fc7f1d563f2ef037576 100644 (file)
@@ -501,6 +501,12 @@ public class HelpSource {
                get { return trace_level; }
                set { trace_level = value; }
        }
+
+       public string BaseDir {
+               get {
+                       return base_dir;
+               }
+       }
        
        ZipFile zip_file;
        
index 5db361ce9da63df7d9ba9bb8405b965acd17a379..7e767c8a25df53710fd8278e4b0ee8d190341739 100644 (file)
@@ -31,6 +31,7 @@
        <!-- TEMPLATE PARAMETERS -->
        <xsl:param name="language" select="'C#'"/>
        <xsl:param name="index" />
+       <xsl:param name="source-id"/>
        
        <xsl:variable name="ThisType" select="/Type"/>
 
                        <xsl:with-param name="content" select="string(descendant-or-self::text())" />
                </xsl:call-template>
        </xsl:template>
+       <xsl:template match="img">
+         <p>
+               <img src="source-id:{$source-id}:{@href}">
+                 <xsl:attribute name="class">
+                       <xsl:choose>
+                         <xsl:when test="count(@class)&gt;0">
+                               <xsl:value-of select="@class" />
+                         </xsl:when>
+                         <xsl:otherwise>picture</xsl:otherwise>
+                       </xsl:choose>
+                 </xsl:attribute>
+               </img>
+         </p>
+       </xsl:template>
 
        <xsl:template match="onequarter">¼</xsl:template>
        <xsl:template match="pi">π</xsl:template>