| career | drupal | java | mac | mysql | perl | scala | uml | unix  

Scala example source code file (HtmlFactory.scala)

This example Scala source code file (HtmlFactory.scala) is included in my "Source Code Warehouse" project. The intent of this project is to help you more easily find Scala source code examples by using tags.

All credit for the original source code belongs to; I'm just trying to make examples easier to find. (For my Scala work, see my Scala examples and tutorials.)

Scala tags/keywords

collection, compiler, diagramgenerator, directory, doctemplateentity, htmlfactory, htmlpage, jfile, list, nsc, string, unit, utf-8

The HtmlFactory.scala Scala example source code

/* NSC -- new Scala compiler
 * Copyright 2007-2013 LAMP/EPFL
 * @author  David Bernard, Manohar Jonnalagedda

package doc
package html

import model._
import{ File => JFile }
import io.{ Streamable, Directory }
import scala.collection._
import page.diagram._


/** A class that can generate Scaladoc sites to some fixed root folder.
  * @author David Bernard
  * @author Gilles Dubochet */
class HtmlFactory(val universe: doc.Universe, index: doc.Index) {

  /** The character encoding to be used for generated Scaladoc sites.
    * This value is currently always UTF-8. */
  def encoding: String = "UTF-8"

  def siteRoot: JFile = new JFile(universe.settings.outdir.value)

  def libResources = List(








  /** Generates the Scaladoc site for a model into the site root.
    * A scaladoc site is a set of HTML and related files
    * that document a model extracted from a compiler run.
  def generate() {

    def copyResource(subPath: String) {
      val bytes = new Streamable.Bytes {
        val p = "/scala/tools/nsc/doc/html/resource/" + subPath
        val inputStream = getClass.getResourceAsStream(p)
        assert(inputStream != null, p)
      val dest = Directory(siteRoot) / subPath
      val out = dest.toFile.bufferedOutput()
      try out.write(bytes, 0, bytes.length)
      finally out.close()


    libResources foreach (s => copyResource("lib/" + s))

    new page.Index(universe, index) writeFor this
    new page.IndexScript(universe, index) writeFor this

    writeTemplates(_ writeFor this)

    for (letter <- index.firstLetterIndex) {
      new, index, universe) writeFor this


  def writeTemplates(writeForThis: HtmlPage => Unit) {
    val written = mutable.HashSet.empty[DocTemplateEntity]
    val diagramGenerator: DiagramGenerator = new DotDiagramGenerator(universe.settings)

    def writeTemplate(tpl: DocTemplateEntity) {
      if (!(written contains tpl)) {
        writeForThis(new page.Template(universe, diagramGenerator, tpl))
        written += tpl
        tpl.templates collect { case d: DocTemplateEntity => d } map writeTemplate


Other Scala source code examples

Here is a short list of links related to this Scala HtmlFactory.scala source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller


new blog posts


Copyright 1998-2021 Alvin Alexander,
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.