| /* |
| * Copyright 2003-2014 the original author or authors. |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| apply plugin: 'asciidoctor' |
| |
| asciidoctor { |
| def (full, major, minor, patch, flavor) = (groovyVersion =~ /(\d+)\.(\d++)\.(\d+)(?:-(.+))?/)[0] |
| logDocuments = true |
| sourceDir = project.file('src/spec/doc') |
| options = [ |
| attributes: [ |
| 'source-highlighter': 'prettify', |
| groovyversion: groovyVersion, |
| 'groovy-major-version': major, |
| 'groovy-minor-version': minor, |
| 'groovy-patch-version': patch, |
| 'groovy-full-version': groovyVersion, |
| 'groovy-short-version': "${major}.${minor}", |
| doctype: 'book', |
| revnumber: groovyVersion, |
| icons: 'font', |
| toc2: '', |
| subprojroot: 'subprojects/groovy-', |
| specfolder: 'src/spec/doc', |
| 'linkcss!': '', |
| encoding: 'utf-8' |
| ] |
| ] |
| } |
| |
| // skip the asciidoctor task if there's no directory with asciidoc files |
| asciidoctor.onlyIf { project.file('src/spec/doc').exists() } |
| |
| asciidoctor.doLast { |
| outputDir.eachFileMatch(~'.*html') { File file -> |
| def text = file.getText('UTF-8') |
| text = text.replaceAll(/gapi::([a-zA-Z0-9$.#]+)/) { m -> |
| def cName = m[1] |
| def cPath = m[1].replace('.', '/') |
| def anchor = '' |
| int anchorIdx = cPath.indexOf('#') |
| if (anchorIdx > 0) { |
| anchor = cPath.substring(anchorIdx) |
| cPath = cPath.substring(0, anchorIdx) |
| } |
| |
| "<a href='http://groovy.codehaus.org/gapi/index.html?${cPath}.html${anchor}' target='_blank'><code>$cName</code></a>" |
| } |
| file.write(text, 'UTF-8') |
| } |
| } |