[runtime] Disable some tests in full-aot mode which cannot be AOTed because of type...
[mono.git] / mcs / class / monodoc / Monodoc / generators / HtmlGenerator.cs
index c91c49b31dd46c9e03f8ff536fcb73a8d636c977..7b157413c22594db13f236138015732f330de68b 100644 (file)
@@ -46,45 +46,52 @@ namespace Monodoc.Generators
                        this.defaultCache = defaultCache;
                }
 
-               public string Generate (HelpSource hs, string id)
+               public string Generate (HelpSource hs, string id, Dictionary<string, string> context)
                {
+                       string specialPage = null;
+                       if (context != null && context.TryGetValue ("specialpage", out specialPage) && specialPage == "master-root")
+                               return GenerateMasterRootPage (hs != null ? hs.RootTree : null);
+
+                       if (id == "root:" && hs == null)
+                               return MakeEmptySummary ();
+
                        if (hs == null || string.IsNullOrEmpty (id))
                                return MakeHtmlError (string.Format ("Your request has found no candidate provider [hs=\"{0}\", id=\"{1}\"]",
                                                                     hs == null ? "(null)" : hs.Name, id ?? "(null)"));
+
                        var cache = defaultCache ?? hs.Cache;
                        if (cache != null && cache.IsCached (MakeCacheKey (hs, id, null)))
                                return cache.GetCachedString (MakeCacheKey (hs, id, null));
 
                        IEnumerable<string> parts;
                        if (hs.IsMultiPart (id, out parts))
-                               return GenerateMultiPart (hs, parts, id);
+                               return GenerateMultiPart (hs, parts, id, context);
 
                        if (hs.IsRawContent (id))
                                return hs.GetText (id) ?? string.Empty;
 
-                       Dictionary<string, string> extraParams = null;
-                       DocumentType type = hs.GetDocumentTypeForId (id, out extraParams);
-                       if (cache != null && extraParams != null && cache.IsCached (MakeCacheKey (hs, id, extraParams)))
-                               return cache.GetCachedString (MakeCacheKey (hs, id, extraParams));
+                       DocumentType type = hs.GetDocumentTypeForId (id);
+                       if (cache != null && context != null && cache.IsCached (MakeCacheKey (hs, id, context)))
+                               return cache.GetCachedString (MakeCacheKey (hs, id, context));
 
                        IHtmlExporter exporter;
                        if (!converters.TryGetValue (type, out exporter))
                                return MakeHtmlError (string.Format ("Input type '{0}' not supported",
                                                                     type.ToString ()));
                        var result = hs.IsGeneratedContent (id) ? 
-                               exporter.Export (hs.GetCachedText (id), extraParams) :
-                               exporter.Export (hs.GetCachedHelpStream (id), extraParams);
+                               exporter.Export (hs.GetCachedText (id), context) :
+                               exporter.Export (hs.GetCachedHelpStream (id), context);
 
                        if (cache != null)
-                               cache.CacheText (MakeCacheKey (hs, id, extraParams), result);
+                               cache.CacheText (MakeCacheKey (hs, id, context), result);
                        return result;
                }
 
-               string GenerateMultiPart (HelpSource hs, IEnumerable<string> ids, string originalId)
+               string GenerateMultiPart (HelpSource hs, IEnumerable<string> ids, string originalId, Dictionary<string, string> context)
                {
                        var sb = new StringBuilder ();
                        foreach (var id in ids)
-                               sb.AppendLine (Generate (hs, id));
+                               sb.AppendLine (Generate (hs, id, context));
 
                        var cache = defaultCache ?? hs.Cache;
                        if (cache != null)
@@ -92,6 +99,18 @@ namespace Monodoc.Generators
                        return sb.ToString ();
                }
 
+               string GenerateMasterRootPage (RootTree rootTree)
+               {
+                       if (rootTree == null)
+                               return string.Empty;
+                       var assembly = System.Reflection.Assembly.GetAssembly (typeof (HtmlGenerator));
+                       var hpStream = assembly.GetManifestResourceStream ("home.html");
+                       var home = new StreamReader (hpStream).ReadToEnd ();
+                       var links = string.Join (Environment.NewLine,
+                                                rootTree.RootNode.ChildNodes.Select (n => string.Format ("<li><a href=\"{0}\">{1}</a></li>", n.Element, n.Caption)));
+                       return home.Replace ("@@API_DOCS@@", links);
+               }
+
                public static string InlineCss {
                        get {
                                if (css_code != null)
@@ -116,7 +135,12 @@ namespace Monodoc.Generators
 
                string MakeHtmlError (string error)
                {
-                       return string.Format ("<html><head></head><body><p>{0}</p></body></html>", error);
+                       return string.Format ("<html><head></head><body><p><em>Error:</em> {0}</p></body></html>", error);
+               }
+
+               string MakeEmptySummary ()
+               {
+                       return @"<html><head></head><body><p><em>This node doesn't have a summary available</p></body></html>";
                }
 
                string MakeCacheKey (HelpSource hs, string page, IDictionary<string,string> extraParams)