Permalink
Browse files

ported pdf doc generation from docs project for use in Grails app and…

… plugin projects
  • Loading branch information...
1 parent 014c4b2 commit 692591581def70fc62eb27f9f1036beed6033dab @burtbeckwith burtbeckwith committed Apr 8, 2010
View
@@ -74,6 +74,7 @@
<classpathentry kind="lib" path="lib/aspectjrt-1.6.6.jar"/>
<classpathentry kind="lib" path="lib/aspectjweaver-1.6.6.jar"/>
<classpathentry kind="lib" path="lib/ehcache-core-1.7.1.jar"/>
+ <classpathentry kind="lib" path="lib/core-renderer-R8.jar"/>
<classpathentry kind="var" path="ASPECTJRT_LIB"/>
<classpathentry kind="output" path="target/eclipse/bin-output"/>
</classpath>
View
Binary file not shown.
View
Binary file not shown.
View
@@ -12,5 +12,8 @@ Import-Template:
org.codehaus.groovy.reflection.*;version="${groovy.version:[=.=.=, =.+1.0)}",
org.codehaus.groovy.classgen.*;version="${groovy.version:[=.=.=, =.+1.0)}",
org.codehaus.groovy.ant.*;version="${groovy.version:[=.=.=, =.+1.0)}",
- org.codehaus.groovy.tools.*;version="${groovy.version:[=.=.=, =.+1.0)}"
-
+ org.codehaus.groovy.tools.*;version="${groovy.version:[=.=.=, =.+1.0)}",
+ org.xhtmlrenderer.pdf.*;version="[0, 1)",
+ com.lowagie.*;version="[2.0.0, 3.0.0)",
+ javax.xml.*;version="0",
+ org.w3c.dom.*;version="0"
View
@@ -69,5 +69,12 @@
<version>1.7.1</version>
</dependency>
+ <!-- for PDF doc generation -->
+ <dependency>
+ <groupId>org.xhtmlrenderer</groupId>
+ <artifactId>core-renderer</artifactId>
+ <version>R8pre2</version>
+ </dependency>
+
</dependencies>
</project>
View
@@ -1,10 +1,9 @@
-import grails.util.GrailsUtil
-import org.radeox.engine.context.BaseInitialRenderContext
-import grails.doc.DocEngine
import org.codehaus.groovy.grails.documentation.DocumentationContext
import org.codehaus.groovy.grails.documentation.DocumentedMethod
+
import grails.util.GrailsNameUtils
import grails.doc.DocPublisher
+import grails.doc.PdfBuilder
/*
* Copyright 2004-2005 the original author or authors.
@@ -40,12 +39,12 @@ links = [
]
docsDisabled = { argsMap.nodoc == true }
+pdfEnabled = { argsMap.pdf == true }
target(docs: "Produces documentation for a Grails project") {
- depends(parseArguments, compile, javadoc, groovydoc, refdocs)
+ depends(parseArguments, compile, javadoc, groovydoc, refdocs, pdf)
}
-
target(setupDoc:"Sets up the doc directories") {
ant.mkdir(dir:"${basedir}/docs")
ant.mkdir(dir:groovydocDir)
@@ -63,7 +62,8 @@ target(groovydoc:"Produces groovydoc documentation") {
ant.taskdef(name:"groovydoc", classname:"org.codehaus.groovy.ant.Groovydoc")
event("DocStart", ['groovydoc'])
try {
- ant.groovydoc(destdir:groovydocDir, sourcepath:".", use:"true", windowtitle:grailsAppName,'private':"true")
+ ant.groovydoc(destdir:groovydocDir, sourcepath:".", use:"true",
+ windowtitle:grailsAppName,'private':"true")
}
catch(Exception e) {
event("StatusError", ["Error generating groovydoc: ${e.message}"])
@@ -78,11 +78,11 @@ target(javadoc:"Produces javadoc documentation") {
event("DocSkip", ['javadoc'])
return
}
-
+
setupDoc()
event("DocStart", ['javadoc'])
File javaDir = new File("${grailsSettings.sourceDir}/java")
- if(javaDir.listFiles().find{ !it.name.startsWith(".")}) {
+ if (javaDir.listFiles().find{ !it.name.startsWith(".")}) {
try {
ant.javadoc( access:"protected",
destdir:javadocDir,
@@ -106,30 +106,27 @@ target(javadoc:"Produces javadoc documentation") {
}
catch(Exception e) {
event("StatusError", ["Error generating javadoc: ${e.message}"])
- // ignore, empty src/java directory
+ // ignore, empty src/java directory
}
}
event("DocEnd", ['javadoc'])
-
}
target(refdocs:"Generates Grails style reference documentation") {
depends(parseArguments, createConfig,loadPlugins)
-
- if (docsDisabled()) return
-
- def srcDocs = new File("${basedir}/src/docs")
+ if (docsDisabled()) return
+ def srcDocs = new File("${basedir}/src/docs")
def context = DocumentationContext.getInstance()
- if(context?.hasMetadata()) {
+ if (context?.hasMetadata()) {
for(DocumentedMethod m in context.methods) {
- if(m.artefact && m.artefact != 'Unknown') {
+ if (m.artefact && m.artefact != 'Unknown') {
String refDir = "${srcDocs}/ref/${GrailsNameUtils.getNaturalName(m.artefact)}"
ant.mkdir(dir:refDir)
def refFile = new File("${refDir}/${m.name}.gdoc")
- if(!refFile.exists()) {
+ if (!refFile.exists()) {
println "Generating documentation ${refFile}"
refFile.write """
h1. ${m.name}
@@ -156,7 +153,8 @@ ${m.arguments?.collect { '* @'+GrailsNameUtils.getPropertyName(it)+'@\n' }}
}
}
}
- if(srcDocs.exists()) {
+
+ if (srcDocs.exists()) {
File refDocsDir = new File("${basedir}/docs/manual")
def publisher = new DocPublisher(srcDocs, refDocsDir)
publisher.ant = ant
@@ -172,16 +170,30 @@ ${m.arguments?.collect { '* @'+GrailsNameUtils.getPropertyName(it)+'@\n' }}
readPluginMetadataForDocs(publisher)
readDocProperties(publisher)
-
publisher.publish()
-
- println "Built user manual at ${refDocsDir}/index.html"
+ println "Built user manual at ${refDocsDir}/index.html"
}
-
}
+target(pdf: "Produces PDF documentation") {
+ depends(parseArguments)
+
+ File refDocsDir = new File("${basedir}/docs/manual")
+ File singleHtml = new File(refDocsDir, 'guide/single.html')
+
+ if (docsDisabled() || !pdfEnabled() || !singleHtml.exists()) {
+ event("DocSkip", ['pdf'])
+ return
+ }
+
+ event("DocStart", ['pdf'])
+ PdfBuilder.build(basedir, grailsHome)
+ println "Built user manual PDF at ${refDocsDir}/guide/single.pdf"
+
+ event("DocEnd", ['pdf'])
+}
def readPluginMetadataForDocs(DocPublisher publisher) {
def basePlugin = loadBasePlugin()
@@ -204,14 +216,14 @@ def readDocProperties(DocPublisher publisher) {
readIfSet(publisher,"license")
readIfSet(publisher,"authors")
readIfSet(publisher,"footer")
-
}
+
private readIfSet(DocPublisher publisher,String prop) {
- if(config.grails.doc."$prop") {
+ if (config.grails.doc."$prop") {
publisher[prop] = config.grails.doc."$prop"
}
+}
+private loadBasePlugin() {
+ pluginManager?.allPlugins?.find { it.basePlugin }
}
-private def loadBasePlugin() {
- pluginManager?.allPlugins?.find { it.basePlugin }
-}
@@ -0,0 +1,87 @@
+/* page layout and page numbering */
+@page {
+ size: a4;
+}
+
+@page :left {
+ @bottom-left {
+ content: counter(page);
+ vertical-align: middle;
+ margin: 0.8em 0;
+ font-size: 12pt;
+ }
+}
+
+@page :right {
+ @bottom-right {
+ content: counter(page);
+ vertical-align: middle;
+ margin: 0.8em 0;
+ font-size: 12pt;
+ }
+}
+
+/* style overrides */
+
+h1 {
+ font-size: 20px;
+ string-set: header content();
+ page-break-before: always
+}
+
+h1>a {
+ font-size: 20px;
+ string-set: header content();
+ page-break-before: always
+}
+
+h2 {
+ font-size: 16px;
+}
+
+h3 {
+ font-size: 14px;
+}
+
+h1, h2, h3, h1>a, h2>a, h3>a {
+ color:#000000;
+}
+
+#toc div.tocItem {
+ list-style: none;
+ margin: 0;
+ padding: 0;
+}
+
+#toc div.tocItem a::after {
+ content: leader('.') target-counter(attr(href), page);
+ font-style: normal;
+}
+
+div.title {
+ font-size: 20px;
+}
+
+.body {
+ font-size: 14px;
+}
+
+pre .code {
+ padding-left:5px;
+ font-size: 12px;
+ line-height: 100%;
+ white-space: normal;
+ page-break-inside: avoid;
+}
+
+.code, .bq {
+ border: 1px solid black;
+ margin-bottom: 2em;
+ page-break-inside: avoid;
+}
+
+.warning, .note, table {
+ margin-top: 2em;
+ margin-bottom: 2em;
+ page-break-inside: avoid;
+}
@@ -1,10 +1,10 @@
<html>
- <head>
- <meta http-equiv="Content-type" content="text/html; charset=utf-8">
- <title>${title}</title>
- <link rel="stylesheet" href="../css/main.css" type="text/css" media="screen" title="Ref" charset="utf-8">
- </head>
- <body class="body">
- ${content}
- </body>
-</html>
+ <head>
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
+ <title>${title}</title>
+ <link rel="stylesheet" href="../css/main.css" type="text/css" media="screen" title="Ref" charset="utf-8"/>
+ </head>
+ <body class="body">
+ ${content}
+ </body>
+</html>
@@ -1,15 +1,15 @@
-<html>
-<head>
- <title>${title} ${version} Reference Documentation</title>
-</head>
-<frameset cols="20%,80%">
- <frame src="ref/menu.html" name="leftFrame" title="index for guide">
- <frame src="guide/index.html" name="mainFrame" title="main guide contents" scrolling="yes">
+<html>
+ <head>
+ <title>${title} ${version} Reference Documentation</title>
+ </head>
+ <frameset cols="20%,80%">
+ <frame src="ref/menu.html" name="leftFrame" title="index for guide"/>
+ <frame src="guide/index.html" name="mainFrame" title="main guide contents" scrolling="yes"/>
- <noframes>
- <h2>Frame Alert</H2>
- <p>
- This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client.
- </noframes>
-</frameset>
-</html>
+ <noframes>
+ <h2>Frame Alert</H2>
+ <p/>
+ This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client.
+ </noframes>
+ </frameset>
+</html>
@@ -1,33 +1,34 @@
<html>
- <head>
- <title>${title} ${version} - Reference Documentation</title>
- <link rel="stylesheet" href="../css/main.css" type="text/css" media="screen" title="Style" charset="utf-8">
- </head>
+ <head>
+ <title>${title} ${version} - Reference Documentation</title>
+ <link rel="stylesheet" href="../css/main.css" type="text/css" media="screen" title="Style" charset="utf-8"/>
+ <link rel="stylesheet" href="../css/pdf.css" type="text/css" media="print" title="PDF" charset="utf-8" />
+ </head>
<body class="body">
- <div id="header">
- <div class="images"><br><br>
- ${logo}
- <span style="right:30px; top:20px; position:absolute;">
- <a href="../index.html" target="_top">Frames</a> | <a href="index.html" target="_top">No Frames</a><br><br>
- ${sponsorLogo}
- </span>
- </div>
- <div class="message">${subtitle}</div>
- <h1>${title} - Reference Documentation</h1>
- <p><strong>Authors:</strong> ${authors}</p>
- <p><strong>Version:</strong> ${version}</p>
- <em>${copyright}</em>
- </div>
-
- <div id="toc">
- <h2>Table of Contents</h2>
- ${toc}
- </div>
- <div id="content">
- ${body}
- </div>
- <div id="footer">
- ${footer}
- </div>
- </body>
-</html>
+ <div id="header">
+ <div class="images"><br/><br/>
+ ${logo}
+ <span style="right:30px; top:20px; position:absolute;">
+ <a href="../index.html" target="_top">Frames</a> | <a href="index.html" target="_top">No Frames</a><br/><br/>
+ ${sponsorLogo}
+ </span>
+ </div>
+ <div class="message">${subtitle}</div>
+ <h1>${title} - Reference Documentation</h1>
+ <p><strong>Authors:</strong> ${authors}</p>
+ <p><strong>Version:</strong> ${version}</p>
+ <em>${copyright}</em>
+ </div>
+
+ <div id="toc">
+ <h2>Table of Contents</h2>
+ ${toc}
+ </div>
+ <div id="content">
+ ${body}
+ </div>
+ <div id="footer">
+ ${footer}
+ </div>
+ </body>
+</html>
Oops, something went wrong.

0 comments on commit 6925915

Please sign in to comment.