1515
1616package grails.doc
1717
18+ import grails.doc.asciidoc.AsciiDocEngine
1819import grails.doc.internal.*
1920import groovy.io.FileType
2021import groovy.text.Template
2122
2223import org.apache.commons.logging.LogFactory
24+ import org.radeox.api.engine.WikiRenderEngine
2325import org.radeox.engine.context.BaseInitialRenderContext
26+ import org.radeox.engine.context.BaseRenderContext
2427import org.yaml.snakeyaml.Yaml
2528
29+ import java.util.regex.Pattern
30+
2631/**
2732 * Coordinated the DocEngine the produce documentation based on the gdoc format.
2833 *
@@ -46,6 +51,8 @@ class DocPublisher {
4651 File images
4752 /* * The directory containing any CSS to use (will override defaults) **/
4853 File css
54+ /* * The directory containing any fonts to use (will override defaults) **/
55+ File fonts
4956 /* * The directory containing any Javascript to use (will override defaults) **/
5057 File js
5158 /* * The directory cotnaining any templates to use (will override defaults) **/
@@ -80,13 +87,19 @@ class DocPublisher {
8087 String logo
8188 /* * HTML markup that renders the right logo */
8289 String sponsorLogo
90+ /**
91+ * The source repository
92+ */
93+ String sourceRepo
8394
8495 /* * Properties used to configure the DocEngine */
8596 Properties engineProperties
8697
98+ boolean asciidoc = false
99+
87100 def output
88- private context
89- private engine
101+ private BaseRenderContext context
102+ private WikiRenderEngine engine
90103 private customMacros = []
91104
92105 DocPublisher () {
@@ -151,7 +164,9 @@ class DocPublisher {
151164 ant. mkdir(dir : " $refDocsDir /ref" )
152165
153166 String imgsDir = new File (refDocsDir, calculatePathToResources(" img" )). path
167+ File fontsDir = new File (refDocsDir, calculatePathToResources(" fonts" ))
154168 ant. mkdir(dir : imgsDir)
169+ ant. mkdir(dir : fontsDir )
155170 String cssDir = new File (refDocsDir, calculatePathToResources(" css" )). path
156171 ant. mkdir(dir : cssDir)
157172 String jsDir = new File (refDocsDir, calculatePathToResources(" js" )). path
@@ -167,6 +182,7 @@ class DocPublisher {
167182 fileset(dir : images)
168183 }
169184 }
185+
170186 ant. copy(todir : cssDir, overwrite : true ) {
171187 fileset(dir : " ${ docResources} /css" )
172188 }
@@ -175,6 +191,11 @@ class DocPublisher {
175191 fileset(dir : css)
176192 }
177193 }
194+ if (fonts && fonts. exists()) {
195+ ant. copy(todir : fontsDir, overwrite : true , failonerror :false ) {
196+ fileset(dir : fonts)
197+ }
198+ }
178199 ant. copy(todir : jsDir, overwrite : true ) {
179200 fileset(dir : " ${ docResources} /js" )
180201 }
@@ -201,12 +222,15 @@ class DocPublisher {
201222 def guideSrcDir = new File (src, " guide" )
202223 def yamlTocFile = new File (guideSrcDir, TOC_FILENAME )
203224 def guide
225+ def ext = asciidoc ? " .adoc" : " .gdoc"
204226 if (yamlTocFile. exists()) {
205- guide = new YamlTocStrategy (new FileResourceChecker (guideSrcDir)). generateToc(yamlTocFile)
227+ def tocStrategy = new YamlTocStrategy (new FileResourceChecker (guideSrcDir), ext)
228+ guide = tocStrategy. generateToc(yamlTocFile)
206229
207230 // A set of all gdoc files.
208231 def files = []
209- guideSrcDir. traverse(type : FileType . FILES , nameFilter : ~/ ^.+\. gdoc$/ ) {
232+ def pattern = asciidoc ? ~/ ^.+\. adoc$/ : ~/ ^.+\. gdoc$/
233+ guideSrcDir. traverse(type : FileType . FILES , nameFilter : pattern) {
210234 // We need relative file paths with '/' separators, since those
211235 // are what are stored in the UserGuideNodes.
212236 files << (it. absolutePath - guideSrcDir. absolutePath)[1 .. -1 ].
@@ -222,7 +246,8 @@ class DocPublisher {
222246 }
223247 }
224248 else {
225- def files = guideSrcDir. listFiles()?. findAll { it. name. endsWith(" .gdoc" ) } ?: []
249+
250+ def files = guideSrcDir. listFiles()?. findAll { it. name. endsWith(ext) } ?: []
226251 guide = new LegacyTocStrategy (). generateToc(files)
227252 }
228253
@@ -247,8 +272,8 @@ class DocPublisher {
247272 def refCategories = files. collect { f ->
248273 new Expando (
249274 name : f. name,
250- usage : new File (" ${ src} /ref/${ f.name} .gdoc " ),
251- sections : f. listFiles(). findAll { it. name. endsWith(" .gdoc " ) }. sort())
275+ usage : new File (" ${ src} /ref/${ f.name} $e xt " ),
276+ sections : f. listFiles(). findAll { it. name. endsWith(ext ) }. sort())
252277 }
253278
254279 def fullToc = new StringBuilder ()
@@ -257,6 +282,7 @@ class DocPublisher {
257282 def vars = [
258283 encoding : encoding,
259284 title : title,
285+ docTitle : title,
260286 subtitle : subtitle,
261287 footer : footer, // TODO - add a way to specify footer
262288 authors : authors,
@@ -272,7 +298,8 @@ class DocPublisher {
272298 resourcesPath : calculatePathToResources(pathToRoot),
273299 prev : null ,
274300 next : null ,
275- legacyLinks : legacyLinks
301+ legacyLinks : legacyLinks,
302+ sourceRepo : sourceRepo,
276303 ]
277304
278305 // Build the user guide sections first.
@@ -311,15 +338,16 @@ class DocPublisher {
311338 vars. section = section
312339
313340 new File (" ${ refDocsDir} /ref/${ section} " ). mkdirs()
314- def textiles = f. listFiles(). findAll { it. name. endsWith(" .gdoc " )}. sort()
315- def usageFile = new File (" ${ src} /ref/${ section} .gdoc " )
341+ def textiles = f. listFiles(). findAll { it. name. endsWith(ext )}. sort()
342+ def usageFile = new File (" ${ src} /ref/${ section}${ ext } " )
316343 if (usageFile. exists()) {
317344 def data = usageFile. getText(" UTF-8" )
318345 context. set(DocEngine . SOURCE_FILE , usageFile)
319346 context. set(DocEngine . CONTEXT_PATH , pathToRoot)
320347 context. set(DocEngine . API_CONTEXT_PATH , vars. resourcesPath)
348+ output. warn " Rendering document file $usageFile . name "
321349 vars. content = engine. render(data, context)
322-
350+ vars . sourcePath = " ref/ ${ section } / $u sageFile . name "
323351 new File (" ${ refDocsDir} /ref/${ section} /Usage.html" ). withWriter(encoding) {out ->
324352 template. make(vars). writeTo(out)
325353 }
@@ -330,8 +358,9 @@ class DocPublisher {
330358 context. set(DocEngine . SOURCE_FILE , txt. name)
331359 context. set(DocEngine . CONTEXT_PATH , pathToRoot)
332360 context. set(DocEngine . API_CONTEXT_PATH , vars. resourcesPath)
361+ output. warn " Rendering document file $txt . name "
333362 vars. content = engine. render(data, context)
334-
363+ vars . sourcePath = " ref/ ${ section } / $t xt . name "
335364 new File (" ${ refDocsDir} /ref/${ section} /${ name} .html" ). withWriter(encoding) {out ->
336365 template. make(vars). writeTo(out)
337366 }
@@ -404,6 +433,8 @@ class DocPublisher {
404433 varsCopy. path = path
405434 varsCopy. level = level
406435 varsCopy. sectionToc = section. children
436+ varsCopy. sourcePath = section. file
437+ output. warn " Rendering document file $sourceFile . name "
407438 varsCopy. content = engine. render(sourceFile. getText(" UTF-8" ), context)
408439
409440 // First create the section content, which usually consists of a header
@@ -506,7 +537,12 @@ class DocPublisher {
506537 context = new BaseInitialRenderContext ()
507538 initContext(context, " .." )
508539
509- engine = new DocEngine (context)
540+ if (asciidoc) {
541+ engine = new AsciiDocEngine (context)
542+ }
543+ else {
544+ engine = new DocEngine (context)
545+ }
510546
511547 engine. engineProperties = props
512548 context. renderEngine = engine
0 commit comments