logo

class

docCompiler::DocCompiler

sys::Obj
  docCompiler::DocCompiler
//
// Copyright (c) 2007, Brian Frank and Andy Frank
// Licensed under the Academic Free License version 3.0
//
// History:
//   5 May 06  Brian Frank  Creation
//

using compiler
using fandoc

**
** DocCompiler manages the pipeline of compiling API and
** stand-alone fandoc documents into HTML.
**
class DocCompiler
{

//////////////////////////////////////////////////////////////////////////
// Construction
//////////////////////////////////////////////////////////////////////////

  new make()
  {
    log = CompilerLog.make
    errors = CompilerErr[,]
    outDir = Sys.homeDir + `doc/`
    uriMapper = UriMapper.make(this)
  }

//////////////////////////////////////////////////////////////////////////
// Compile
//////////////////////////////////////////////////////////////////////////

  Void compilePodToHtml()
  {
    log.info("DocCompiler [$pod]")
    Init.make(this).run
    ApiToHtml.make(this).run
    SourceToHtml.make(this).run
    FandocToHtml.make(this).run
    PodIndexToHtml.make(this).run
    if (!errors.isEmpty) throw errors.last
  }

  Void compileTopIndexToHtml()
  {
    log.info("DocCompiler [top index]")
    TopIndexToHtml.make(this).run
    BuildSearchIndex.make(this).run
    CopyResources.make(this).run
    if (!errors.isEmpty) throw errors.last
  }

//////////////////////////////////////////////////////////////////////////
// Errors
//////////////////////////////////////////////////////////////////////////

  **
  ** Create, log, and return a CompilerErr.
  **
  CompilerErr err(Str msg, Location loc)
  {
    return errReport(CompilerErr.make(msg, loc))
  }

  **
  ** Log, store, and return the specified CompilerErr.
  **
  CompilerErr errReport(CompilerErr e)
  {
    log.compilerErr(e)
    errors.add(e)
    return e
  }

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

  CompilerLog log           // ctor
  CompilerErr[] errors      // accumulated errors
  File outDir               // output directory
  Pod pod                   // pod to compile
  UriMapper uriMapper       // normalizes fandoc URIs to HTML
  File podDir               // Init: outDir/podName
  Obj[] fandocIndex         // FandocToHtml if we have "index.fog"
  Type curType              // if running Api generation

}