logo

class

docCompiler::FandocIndexToHtmlGenerator

sys::Obj
  fandoc::HtmlDocWriter
    docCompiler::HtmlGenerator
      docCompiler::FandocIndexToHtmlGenerator
  1  //
  2  // Copyright (c) 2007, Brian Frank and Andy Frank
  3  // Licensed under the Academic Free License version 3.0
  4  //
  5  // History:
  6  //   5 May 07  Brian Frank  Creation
  7  //
  8  
  9  using compiler
 10  using fandoc
 11  
 12  **
 13  ** FandocIndexToHtmlGenerator generates an HTML file from an index.fog file.
 14  **
 15  class FandocIndexToHtmlGenerator : HtmlGenerator
 16  {
 17  
 18  //////////////////////////////////////////////////////////////////////////
 19  // Constructor
 20  //////////////////////////////////////////////////////////////////////////
 21  
 22    new make(DocCompiler compiler, Location loc, OutStream out)
 23      : super(compiler, loc, out)
 24    {
 25    }
 26  
 27  //////////////////////////////////////////////////////////////////////////
 28  // Generator
 29  //////////////////////////////////////////////////////////////////////////
 30  
 31    override Str title()
 32    {
 33      return "Index"
 34    }
 35  
 36    override Void header()
 37    {
 38      out.print("<ul>\n")
 39      out.print("  <li><a href='../index.html'>$docHome</a></li>\n")
 40      out.print("  <li><a href='index.html'>$compiler.pod.name</a></li>\n")
 41      out.print("  <li>$title</li>\n")
 42      out.print("</ul>\n")
 43    }
 44  
 45    override Void content()
 46    {
 47      row := -1  // used to track tables
 48  
 49      out.print("<h1 class='title'>$compiler.pod.name</h1>\n")
 50      compiler.fandocIndex.each |Obj obj|
 51      {
 52        if (obj is Str)
 53        {
 54          // close table if open
 55          if (row != -1)
 56          {
 57            out.print("</table>\n")
 58            row = -1
 59          }
 60  
 61          // heading
 62          out.print("<h1>$obj</h1>\n")
 63          return
 64        }
 65  
 66        // open table if needed
 67        if (row == -1) out.print("<table>\n")
 68        row++
 69  
 70        cls  := row % 2 == 0 ? "even" : "odd"
 71        Obj link := ""
 72        Obj text := ""
 73  
 74        if (obj is Obj[])
 75        {
 76          link = (obj as Obj[])[0]
 77          text = (obj as Obj[])[1]
 78        }
 79        else
 80        {
 81          link = obj
 82        }
 83  
 84        out.print("<tr class='$cls'>\n")
 85        out.print("  <td class='first'><a href='${link}.html'>$link</a></td>\n")
 86        out.print("  <td>$text</td>\n")
 87        out.print("</tr>\n")
 88      }
 89  
 90      // make sure we close table
 91      if (row != -1) out.print("</table>\n")
 92    }
 93  
 94  }
 95  

More Info