From c6f57d77009a7995234f17b7a94fb970128c29de Mon Sep 17 00:00:00 2001 From: Josh Suereth Date: Fri, 9 Dec 2011 21:45:52 -0500 Subject: Fixed Emit*Page to write to file. The EmitHtmlPage and EmitManPage utilities now write to a file if there is more than one argument on the command line. This allows the SBT build to fork them and still generate a file without having to capture the output stream. --- src/manual/scala/tools/docutil/EmitHtml.scala | 154 ++--------------------- src/manual/scala/tools/docutil/EmitManPage.scala | 16 +-- 2 files changed, 17 insertions(+), 153 deletions(-) (limited to 'src/manual') diff --git a/src/manual/scala/tools/docutil/EmitHtml.scala b/src/manual/scala/tools/docutil/EmitHtml.scala index ddfb8cb0f2..43d097a137 100644 --- a/src/manual/scala/tools/docutil/EmitHtml.scala +++ b/src/manual/scala/tools/docutil/EmitHtml.scala @@ -201,164 +201,26 @@ object EmitHtml { out println "" out println "" } -/* */ -/* - private def group(ns: Iterable[NodeSeq]): NodeSeq = { - val zs = new NodeBuffer - for (z <- ns) { zs &+ z } - zs - } - - def emitSection(section: Section, depth: int): NodeSeq = { - def emitText(text: AbstractText): NodeSeq = text match { - case seq:SeqText => - group(seq.components.toList.map(item => emitText(item))) - - case Text(text) => - scala.xml.Text(escape(text)) - - case MDash => - scala.xml.Text("—") - - case NDash => - scala.xml.Text("–") - - case Bold(text) => - {emitText(text)} - - case Italic(text) => - {emitText(text)} - - case Emph(text) => - {emitText(text)} - - case Mono(text) => - {emitText(text)} - - case Quote(text) => - emitText("\"" & text & "\"") - - case DefinitionList(definitions @ _*) => -
- {definitions.toList.map(d => -
{emitText(d.term)}
-
{emitText(d.description)}
- )} -
- - case Link(label, url) => - {emitText(label)} - - case _ => - error("unknown text node " + text) - } - - def emitParagraph(para: Paragraph): NodeSeq = para match { - case TextParagraph(text) => -

{emitText(text)}

- case BlockQuote(text) => -
{emitText(text)}
- - case CodeSample(text) => -
{escape(text)}
- - case lst:BulletList => - - - case lst:NumberedList => -
    - {lst.items.toList.map(item =>
  1. {emitText(item)}
  2. )} -
- - case TitledPara(title, text) => -

{escape(title)}

- {emitText(text)} - - case EmbeddedSection(sect) => - {emitSection(sect, depth + 1)} - - case _ => - error("unknown paragraph node " + para) - } - - val name = section.title.replaceAll("\\p{Space}", "_").toLowerCase() -

{section.title}

.concat( - group(section.paragraphs.toList.map(p => emitParagraph(p)))) - } - - private def emit3columns(col1: String, col2: String, col3: String): NodeSeq = -
{col1}
-
{col3}
-
{col2}
-
- - private def emitHeader(col1: String, col2: String, col3: String): NodeSeq = -
- {emit3columns(col1, col2, col3)} -
- - private def emitFooter(col1: String, col2: String, col3: String): NodeSeq = { - scala.xml.Comment("footer") -
- {emit3columns(col1, col2, col3)} -
+ def main(args: Array[String]) = args match{ + case Array(classname) => emitHtml(classname) + case Array(classname, file, _*) => emitHtml(classname, new java.io.FileOutputStream(file)) + case _ => sys.exit(1) } - def emitDocument(document: Document, addDocType: Boolean) = { - val name = document.title + "(" + document.category.id + ")" - val doc = - - - {document.title} - - - - - - {emitHeader(name, "" + document.category, name)} - {document.sections.map(s => emitSection(s, 2))} - {emitFooter("version " + document.version, document.date, name)} - - - out.println(doc) -/* - val w = new java.io.StringWriter - val id = scala.xml.dtd.PublicID("PUBLIC", null) - val dtd = null //scala.xml.dtd.DEFAULT(true, "") - val doctype = scala.xml.dtd.DocType("html", id, null) //List(dtd)) - XML.write(w, doc, document.encoding, true/ *xmlDecl* /, doctype) - out.println(w.toString()) -*/ - } -*/ - def main(args: Array[String]) { - if (args.length < 1) { - System.err println "usage: EmitHtml " - sys.exit(1) - } + def emitHtml(classname: String, outStream: java.io.OutputStream = out.out) { + if(outStream != out.out) out setOut outStream try { val cl = this.getClass.getClassLoader() - val clasz = cl loadClass args(0) + val clasz = cl loadClass classname val meth = clasz getDeclaredMethod "manpage" val doc = meth.invoke(null).asInstanceOf[Document] emitDocument(doc) } catch { case ex: Exception => ex.printStackTrace() - System.err println "Error in EmitHtml" + System.err println "Error in EmitManPage" sys.exit(1) } } - - def emitHtml(classname: String, outStream: java.io.OutputStream) { - out setOut outStream - main(Array(classname)) - } } diff --git a/src/manual/scala/tools/docutil/EmitManPage.scala b/src/manual/scala/tools/docutil/EmitManPage.scala index 4a66e2ed07..3e0b02a415 100644 --- a/src/manual/scala/tools/docutil/EmitManPage.scala +++ b/src/manual/scala/tools/docutil/EmitManPage.scala @@ -163,10 +163,17 @@ object EmitManPage { doc.sections foreach (s => emitSection(s, 1)) } - def main(args: Array[String]) { + def main(args: Array[String]) = args match{ + case Array(classname) => emitManPage(classname) + case Array(classname, file, _*) => emitManPage(classname, new java.io.FileOutputStream(file)) + case _ => sys.exit(1) + } + + def emitManPage(classname: String, outStream: java.io.OutputStream = out.out) { + if(outStream != out.out) out setOut outStream try { val cl = this.getClass.getClassLoader() - val clasz = cl loadClass args(0) + val clasz = cl loadClass classname val meth = clasz getDeclaredMethod "manpage" val doc = meth.invoke(null).asInstanceOf[Document] emitDocument(doc) @@ -177,9 +184,4 @@ object EmitManPage { sys.exit(1) } } - - def emitManPage(classname: String, outStream: java.io.OutputStream) { - out setOut outStream - main(Array(classname)) - } } -- cgit v1.2.3