logo

class

docCompiler::SourceToHtmlGenerator

sys::Obj
  fandoc::HtmlDocWriter
    docCompiler::HtmlGenerator
      docCompiler::ApiToHtmlGenerator
        docCompiler::SourceToHtmlGenerator
//
// Copyright (c) 2007, Brian Frank and Andy Frank
// Licensed under the Academic Free License version 3.0
//
// History:
//   9 May 07  Andy Frank  Creation
//

using compiler
using fandoc

**
** SourceToHtmlGenerator generates an syntax color coded HTML
** file for a Type's source code.
**
class SourceToHtmlGenerator : ApiToHtmlGenerator
{

//////////////////////////////////////////////////////////////////////////
// Constructor
//////////////////////////////////////////////////////////////////////////

  new make(DocCompiler compiler, Location loc, OutStream out, Type t, File srcFile)
    : super(compiler, loc, out, t)
  {
    this.srcFile = srcFile
  }

//////////////////////////////////////////////////////////////////////////
// ApiToHtmlGenerator
//////////////////////////////////////////////////////////////////////////

  **
  ** Generate the main content.
  **
  override Void content()
  {
    // print type header
    out.print("<div class='type'>\n")
    typeOverview
    out.print("</div>\n")

    // get file
    srcFileFacet := t->sourceFile
    file := t.pod.files["/src/$srcFileFacet".toUri]

    // build slot:lineNum map
    slots := Str:Int[:]
    t.slots.each |Slot s| { if (s.parent == t) slots[s.name] = s->lineNumber }

    // generate
    FanToHtml.make(file.in, out, slots).parse
  }

  **
  ** Generate the sidebar.
  **
  override Void sidebar()
  {
    out.print("<h2>More Info</h2>\n")
    out.print("<ul>\n")
    out.print("  <li><a href='${t.name}.html'>View Fandoc</a></li>\n")
    out.print("</ul>\n")
    slotsOverview(false)
  }

//////////////////////////////////////////////////////////////////////////
// Fields
//////////////////////////////////////////////////////////////////////////

  File srcFile
}