Skip to content

Commit 2503ff8

Browse files
committed
Refactor code as to get the docs base URL as a system property (allows switching from "next" to "latest" in dev mode easily)
1 parent a596fcd commit 2503ff8

14 files changed

+44
-32
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package generator
2+
3+
class DocUtils {
4+
@Lazy public static final String DOCS_BASEURL = System.getProperty('docs_baseurl')
5+
}

generator/src/main/groovy/generator/DocumentationHTMLCleaner.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class DocumentationHTMLCleaner {
5959
def (String tag, String attr, String url) = [it[1], it[2], it[3]]
6060
url = url.replaceAll(/x(.+)\.(?:pagespeed.+)/, '$1')
6161
if (!url.startsWith('http') && !url.startsWith('#') && 'target.html'!=url) {
62-
"$tag $attr'http://docs.groovy-lang.org/latest/html/documentation/$url'"
62+
"$tag $attr'${DocUtils.DOCS_BASEURL}/html/documentation/$url'"
6363
} else {
6464
it[0]
6565
}

generator/src/main/groovy/generator/PageTemplate.groovy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,7 @@ abstract class PageTemplate extends BaseTemplate {
5454
asciidoctor.convert(body,options)
5555
}
5656

57+
String latestDocURL(String target) {
58+
"${DocUtils.DOCS_BASEURL}/html/$target"
59+
}
5760
}

generator/src/main/groovy/generator/SiteGenerator.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class SiteGenerator {
107107
render 'docpage', item.targetFilename, [
108108
category: 'Learn',
109109
title: item.name,
110-
page: parsePage("http://docs.groovy-lang.org/docs/latest/html/documentation/${item.sourceFilename}.html")]
110+
page: parsePage("${DocUtils.DOCS_BASEURL}/html/documentation/${item.sourceFilename}.html")]
111111
}
112112
}
113113
}

generator/src/main/groovy/model/SiteMap.groovy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import groovy.transform.ToString
44
import org.codehaus.groovy.control.CompilerConfiguration
55

66
import groovy.transform.CompileStatic
7+
import org.codehaus.groovy.control.customizers.ImportCustomizer
78

89
@CompileStatic
910
@ToString(includeNames=true)
@@ -23,6 +24,9 @@ class SiteMap {
2324

2425
public static SiteMap from(File source) {
2526
CompilerConfiguration config = new CompilerConfiguration()
27+
def customizer = new ImportCustomizer()
28+
config.addCompilationCustomizers(customizer)
29+
customizer.addStaticImport('generator.DocUtils','DOCS_BASEURL')
2630
config.scriptBaseClass = 'groovy.util.DelegatingScript'
2731
GroovyShell shell = new GroovyShell(config)
2832
def script = shell.parse(source)

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
systemProp.docs_baseurl=http://docs.groovy-lang.org/latest

site/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ task generateSite(type:JavaExec) {
3939
classpath = project(':generator').sourceSets.main.runtimeClasspath
4040
main = 'generator.SiteGenerator'
4141
args = [sources, outputDir, project.watchmode]
42-
42+
systemProperties.docs_baseurl = System.getProperty('docs_baseurl')
4343
}
4444

4545
task checkDeadLinks(dependsOn: generateSite) {

site/src/site/pages/404.groovy

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
layout 'layouts/main.groovy', true,
66
pageTitle: 'The Groovy programming language - 404',
77
mainContent: contents {
8-
def latestURL = { String target ->
9-
"http://docs.groovy-lang.org/latest/html/$target"
10-
}
118
div(id: 'content', class: 'page-1') {
129
div(class: 'row') {
1310
div(class: 'row-fluid') {
@@ -16,10 +13,10 @@ layout 'layouts/main.groovy', true,
1613
div(class: 'panel-body') {
1714
p 'We could not find the page you are looking for. Maybe you are looking for one of those?'
1815
ul {
19-
li("The ${$a(href: latestURL('documentation'), 'reference documentation')} of the Groovy language.")
20-
li("The latest ${$a(href: latestURL('api'), 'Javadocs')} of the language.")
21-
li("The latest ${$a(href: latestURL('gapi'), 'Groovdocs')} of the Latestlanguage.")
22-
li("Description of ${$a(href: latestURL('groovy-jdk'), 'the Groovy development kit APIs')}.")
16+
li("The ${$a(href: latestDocURL('documentation'), 'reference documentation')} of the Groovy language.")
17+
li("The latest ${$a(href: latestDocURL('api'), 'Javadocs')} of the language.")
18+
li("The latest ${$a(href: latestDocURL('gapi'), 'Groovdocs')} of the Latestlanguage.")
19+
li("Description of ${$a(href: latestDocURL('groovy-jdk'), 'the Groovy development kit APIs')}.")
2320
}
2421
}
2522
}

site/src/site/pages/release-notes.groovy

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import generator.DocUtils
2+
13
modelTypes = {
24
String groovyVersion
35
String notes
@@ -11,8 +13,8 @@ layout 'layouts/main.groovy', true,
1113
script { yieldUnescaped "document.addEventListener('DOMContentLoaded',prettyPrint)" }
1214
},
1315
mainContent: contents {
14-
15-
def notesAsHTML = asciidocText(notes)
16+
Map options = [attributes:[DOCS_BASEURL:DocUtils.DOCS_BASEURL]]
17+
def notesAsHTML = asciidocText(notes,options)
1618
def matcher = notesAsHTML =~ /<h2 id="(.+?)">(.+?)<\/h2>/
1719
def sections = [:]
1820
while (matcher.find()) {

site/src/site/releasenotes/groovy-1.6.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ html.body.'**'[email protected](~/.*\.pdf/).each{ println it }
864864

865865
For the pleasure of giving another example: let’s use
866866
the link:http://eclipse.org/jetty/[Jetty servlet container] to
867-
expose link:http://docs.groovy-lang.org/next/html/documentation/template-engines.html[Groovy templates] in
867+
expose link:{DOCS_BASEURL}/html/documentation/template-engines.html[Groovy templates] in
868868
a few lines of code:
869869

870870
[source,groovy]
@@ -983,7 +983,7 @@ bean location: bind { pos.x + ', ' + pos.y }
983983
--------------------------------------------
984984

985985
You may also be interested in having a look
986-
at link:http://docs.groovy-lang.org/latest/html/api/groovy/util/ObservableMap.html[ObservableMap] and link:http://docs.groovy-lang.org/latest/html/api/groovy/util/ObservableList.html[ObservableList],
986+
at link:{DOCS_BASEURL}/html/api/groovy/util/ObservableMap.html[ObservableMap] and link:{DOCS_BASEURL}/html/api/groovy/util/ObservableList.html[ObservableList],
987987
for a similar mechanism on maps and lists.
988988

989989
Along with `@Bindable`, there’s also a `@Vetoable` transformation for

site/src/site/releasenotes/groovy-2.1.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ delegate based methods, but we hinted at the fact we can go beyond, in
246246
terms of static type checking for your DSLs.
247247

248248
For more details take a look at
249-
the link:http://docs.groovy-lang.org/docs/latest/html/documentation/#__code_delegatesto_code[@DelegatesTo documentation].
249+
the link:{DOCS_BASEURL}/html/documentation/#__code_delegatesto_code[@DelegatesTo documentation].
250250

251251
[[Groovy21releasenotes-Typecheckerextensions]]
252252
== Type checker extensions

site/src/site/releasenotes/groovy-2.3.adoc

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ particular Groovy methods decorating JDK 8 APIs might be added.
5454

5555
A major highlight for Groovy 2.3 is the introduction of the *concept of traits*.
5656

57-
link:http://docs.groovy-lang.org/latest/html/documentation/core-traits.html[Traits]
57+
link:{DOCS_BASEURL}/html/documentation/core-traits.html[Traits]
5858
are reusable components of behavior that your classes can implement, and
5959
are an additional Object-Oriented concept alongside classes and
6060
interfaces.
@@ -192,7 +192,7 @@ assert na.quack() == 'Quack!'
192192
----
193193

194194
You can find more information on traits in the
195-
exhaustive link:http://docs.groovy-lang.org/latest/html/documentation/core-traits.html[traits documentation].
195+
exhaustive link:{DOCS_BASEURL}/html/documentation/core-traits.html[traits documentation].
196196

197197
[[Groovy2.3releasenotes-NewandupdatedASTtransformations]]
198198
== New and updated AST transformations
@@ -271,7 +271,7 @@ assert person.age == 21
271271
-----
272272

273273
You can have a look at
274-
the link:http://docs.groovy-lang.org/latest/html/documentation/core-metaprogramming.html#xform-Builder[@Builder documentation]
274+
the link:{DOCS_BASEURL}/html/documentation/core-metaprogramming.html#xform-Builder[@Builder documentation]
275275
for the other builder variants.
276276

277277
[[Groovy2.3releasenotes-Sortable]]
@@ -310,7 +310,7 @@ Additionally, you can define included / excluded fields, access
310310
individual field comparators with methods like `comparatorByFirst()`.
311311

312312
More details on
313-
the http://docs.groovy-lang.org/latest/html/documentation/core-metaprogramming.html#xform-Sortable[@Sortable documentation] page.
313+
the {DOCS_BASEURL}/html/documentation/core-metaprogramming.html#xform-Sortable[@Sortable documentation] page.
314314

315315
[[Groovy2.3releasenotes-SourceURI]]
316316
==== @SourceURI
@@ -363,7 +363,7 @@ the name and parameter types expressed in an interface type
363363
[[Groovy2.3releasenotes-BaseScriptclassimprovements]]
364364
==== @BaseScript class improvements
365365

366-
http://docs.groovy-lang.org/latest/html/gapi/groovy/transform/BaseScript.html[@BaseScript]
366+
{DOCS_BASEURL}/html/gapi/groovy/transform/BaseScript.html[@BaseScript]
367367
is a fairly recent addition in Groovy, and it allowed to annotate a
368368
variable in your script to instruct the compiler to use a particular
369369
base script class for this script. Now we have another notation which is
@@ -470,9 +470,9 @@ level as competing libraries.
470470
Beside the performance improvements of the JSON module, other updates
471471
have taken place.
472472

473-
With link:http://docs.groovy-lang.org/latest/html/gapi/groovy/json/JsonSlurper.html[JsonSlurper],
473+
With link:{DOCS_BASEURL}/html/gapi/groovy/json/JsonSlurper.html[JsonSlurper],
474474
you’ll be able to set
475-
different link:http://docs.groovy-lang.org/latest/html/gapi/groovy/json/JsonParserType.html[parser types]
475+
different link:{DOCS_BASEURL}/html/gapi/groovy/json/JsonParserType.html[parser types]
476476
depending on the kind of input you wish to parse, particularly if
477477
you know the size of the payload you expect to parse, or whether you
478478
want a more tolerant parser which accepts elements like comments which
@@ -516,7 +516,7 @@ give the type of the parameter, but it’s no longer required:
516516

517517
In the signature of your methods taking closures as arguments, you’ll
518518
also be able to annotate the closure parameter
519-
with link:http://docs.groovy-lang.org/latest/html/gapi/groovy/transform/stc/ClosureParams.html[@ClosureParams]
519+
with link:{DOCS_BASEURL}/html/gapi/groovy/transform/stc/ClosureParams.html[@ClosureParams]
520520
to give additional hints to the type checker to infer the type of the
521521
parameters passed to your closure.
522522

@@ -534,7 +534,7 @@ internationalization, includes, as well as proposing type checked
534534
templates and models.
535535

536536
More details about the
537-
new link:http://docs.groovy-lang.org/latest/html/documentation/markup-template-engine.html[Markup template engine]
537+
new link:{DOCS_BASEURL}/html/documentation/markup-template-engine.html[Markup template engine]
538538
in the documentation, as well as in Cédric’s link:http://melix.github.io/blog/[blog], if you want to learn more
539539
about the "behind the scenes" stories!
540540

@@ -624,7 +624,7 @@ compiled.
624624
== JUnit 4 GroovyAssert class
625625

626626
The
627-
venerable link:http://docs.groovy-lang.org/latest/html/gapi/groovy/util/GroovyTestCase.html[GroovyTestCase]
627+
venerable link:{DOCS_BASEURL}/html/gapi/groovy/util/GroovyTestCase.html[GroovyTestCase]
628628
(JUnit 3 based approach) has often been used as a base class for your
629629
test classes — unless you’ve been using
630630
the link:http://www.spockframework.org/[Spock testing framework], of course.
@@ -633,7 +633,7 @@ your own classes, but must derive from `GroovyTestCase` to benefit from
633633
the additional assertion methods.
634634

635635
In earlier versions of Groovy we introduced the JUnit
636-
4-friendly link:http://docs.groovy-lang.org/latest/html/gapi/groovy/util/GroovyAssert.html[GroovyAssert],
636+
4-friendly link:{DOCS_BASEURL}/html/gapi/groovy/util/GroovyAssert.html[GroovyAssert],
637637
which is a convenient class offering the usual assertion methods of
638638
`GroovyTestCase`, but in the form of static methods that you can static
639639
import in your test class. In Groovy 2.3 we’ve enriched `GroovyAssert`
@@ -736,7 +736,7 @@ with link:http://jira.codehaus.org/browse/GROOVY-6459[GROOVY-6459].
736736
=== New documentation
737737

738738
We are still working on the
739-
brand link:http://docs.groovy-lang.org/docs/latest/html/documentation/[new documentation] for Groovy
739+
brand link:{DOCS_BASEURL}/html/documentation/[new documentation] for Groovy
740740
(in Asciidoc(tor) format), so you can already
741741
have a glimpse at what’s already covered or not.
742742

@@ -767,7 +767,7 @@ documentation, showing the methods the Groovy library adds on top of the
767767
JDK classes.
768768

769769
Please also have a look at the
770-
new link:http://docs.groovy-lang.org/latest/html/groovy-jdk/[restyled GDK documentation].
770+
new link:{DOCS_BASEURL}/html/groovy-jdk/[restyled GDK documentation].
771771

772772
[[Groovy2.3releasenotes-Dependencyupgrades]]
773773
== Dependency upgrades

site/src/site/releasenotes/groovy-2.4.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
== Android Support
33
With Groovy 2.4, you can write Android applications in Groovy!
44

5-
A quick link:http://docs.groovy-lang.org/docs/latest/html/documentation/tools-groovyc.html#section-android[getting
5+
A quick link:{DOCS_BASEURL}/html/documentation/tools-groovyc.html#section-android[getting
66
started guide] is available on the Groovy website.
77

88
To build your Android applications with the Groovy support, you’ll be

site/src/site/sitemap.groovy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ pages {
4949
page 'buildstatus', 'buildstatus', [category: 'Community']
5050
page 'faq', 'faq', [category: 'Documentation', docSections: documentationSections]
5151
page 'events', 'events', [category: 'Community', allEvents: allEvents]
52-
page 'api', 'api', [category: 'Learn', iframeTarget: 'http://docs.groovy-lang.org/docs/latest/html/gapi']
53-
page 'gdk', 'gdk', [category: 'Learn', iframeTarget: 'http://docs.groovy-lang.org/docs/latest/html/groovy-jdk']
54-
page 'singlepagedocumentation', 'single-page-documentation', [category: 'Learn', iframeTarget: 'http://docs.groovy-lang.org/docs/next/html/documentation/']
52+
page 'api', 'api', [category: 'Learn', iframeTarget: "${DOCS_BASEURL}/html/gapi"]
53+
page 'gdk', 'gdk', [category: 'Learn', iframeTarget: "${DOCS_BASEURL}/html/groovy-jdk"]
54+
page 'singlepagedocumentation', 'single-page-documentation', [category: 'Learn', iframeTarget: "${DOCS_BASEURL}/html/documentation/"]
5555
page 'changelogs', 'changelogs', [:]
5656
page '404','404', [:]
5757
}

0 commit comments

Comments
 (0)