Skip to content

Commit 81dc721

Browse files
committed
release 0.2.0
1 parent 642817c commit 81dc721

11 files changed

Lines changed: 144 additions & 43 deletions

File tree

build.gradle

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ plugins {
88
id "com.github.ben-manes.versions" version "0.11.3"
99
id "com.jfrog.bintray" version "1.6"
1010
id "org.asciidoctor.convert" version "1.5.3"
11-
id 'org.ajoberstar.github-pages' version '1.5.0'
11+
id 'org.ajoberstar.github-pages' version '1.5.1'
1212
id "com.github.hierynomus.license" version "0.12.1"
1313
id "net.saliman.properties" version "1.4.4"
1414
id 'com.gradle.build-receipt' version '1.0'
@@ -98,6 +98,7 @@ configurations {
9898
}
9999

100100
license {
101+
exclude '*.txt'
101102
header rootProject.file("license-header.txt")
102103
skipExistingHeaders true
103104
ignoreFailures false
@@ -107,6 +108,10 @@ signing {
107108
sign configurations.archives
108109
}
109110

111+
def isPublishTask(task) {
112+
task.name.startsWith('publish') && (task.name != 'publishGhPages')
113+
}
114+
110115
signArchives {
111116
onlyIf { gradle.taskGraph.allTasks.findAll {task -> isPublishTask(task)} }
112117
}
@@ -179,6 +184,45 @@ artifacts {
179184
(System.getenv("TRAVIS") == "true") ? archives(sourcesJar) : archives(sourcesJar, groovydocJar)
180185
}
181186

187+
asciidoctor {
188+
sourceDir = file("doc")
189+
sources {include 'index.adoc'}
190+
logDocuments = true
191+
attributes 'source-highlighter': 'coderay',
192+
'coderay-linenums-mode': 'table',
193+
icons: 'font',
194+
imagesdir: 'img',
195+
'data-uri': '',
196+
linkattrs: true,
197+
linkcss: true
198+
}
199+
githubPages {
200+
repoUri = 'https://github.com/beryx/handlebars-java-helpers.git'
201+
202+
credentials {
203+
username = System.getenv('GH_PAGES_ACCESS_TOKEN')
204+
password = ''
205+
}
206+
207+
pages {
208+
def pgType = project.hasProperty('ghPageType') ? ghPageType : 'latest'
209+
if(pgType == 'init') {
210+
from file("ghpages")
211+
} else {
212+
from file("${asciidoctor.outputDir.path}/html5")
213+
}
214+
def docDir = Boolean.valueOf(hbsHelpersReleaseBuild) ? 'releases' : 'snapshots'
215+
if(pgType == 'init') {
216+
into "."
217+
} else if(pgType == 'version') {
218+
publishGhPages.enabled = (docDir != 'snapshots')
219+
into "$docDir/$hbsHelpersVersion"
220+
} else {
221+
into "$docDir/latest"
222+
}
223+
}
224+
}
225+
182226
publishing {
183227
publications {
184228
hbsHelpers(MavenPublication) {
@@ -275,35 +319,6 @@ ideaWorkspace {
275319
outputFile = file('hbsHelpers.iws')
276320
}
277321

278-
asciidoctor {
279-
sourceDir = file("doc")
280-
sources {include 'index.adoc'}
281-
logDocuments = true
282-
attributes 'source-highlighter': 'coderay',
283-
'coderay-linenums-mode': 'table',
284-
icons: 'font',
285-
'data-uri': '',
286-
linkattrs: true,
287-
linkcss: true
288-
}
289-
290-
githubPages {
291-
repoUri = 'https://github.com/beryx/handlebars-java-helpers.git'
292-
293-
credentials {
294-
username = System.getenv('GH_PAGES_ACCESS_TOKEN')
295-
password = ''
296-
}
297-
298-
pages {
299-
from file("${asciidoctor.outputDir.path}/html5")
300-
from file('doc/CNAME')
301-
if(!Boolean.valueOf(hbsHelpersReleaseBuild)) {
302-
into "snapshots/$hbsHelpersVersion"
303-
}
304-
}
305-
}
306-
307322
def readFromConsole(prompt) {
308323
readFromConsole('', prompt)
309324
}
@@ -335,10 +350,6 @@ def readFromConsole(header, prompt, isPassword) {
335350
}
336351
}
337352

338-
def isPublishTask(task) {
339-
task.name.startsWith('publish') && (task.name != 'publishGhPages')
340-
}
341-
342353
gradle.taskGraph.whenReady { taskGraph ->
343354
if (gradle.taskGraph.allTasks.findAll {task -> isPublishTask(task)}) {
344355
def password = readPasswordFromConsole('Please enter your signing credentials', 'PGP Private Key Password')

doc/helpers.adoc

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,3 +315,32 @@ package: {{asJavaId service camelCase=false underscore=true}}
315315
serviceId: byteAsAnOctet
316316
package: byte_as_an_octet
317317
----
318+
319+
320+
== javaComment
321+
Inserts the content of a file as a Java comment.
322+
323+
*Syntax*: {{[purple]##javaComment## _commentFile_}}
324+
325+
*Example:*
326+
327+
.Template
328+
----
329+
{{javaComment 'license-header.txt'}}
330+
public class A {}
331+
----
332+
333+
.license-header.txt
334+
----
335+
This is public-domain software.
336+
Do whatever you want with it.
337+
----
338+
339+
.Result
340+
----
341+
/*
342+
* This is public-domain software.
343+
* Do whatever you want with it.
344+
*/
345+
public class A {}
346+
----

ghpages/CNAME

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
handlebars-java-helpers.beryx.org

ghpages/index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<link rel="canonical" href="releases/latest"/>
5+
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
6+
<meta http-equiv="refresh" content="0;url=releases/latest" />
7+
</head>
8+
</html>

ghpages/releases/latest/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<body>
4+
<h1>No release yet</h1>
5+
</body>
6+
</html>

gradle.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
hbsHelpersVersionMajor = 0
2-
hbsHelpersVersionMinor = 1
3-
hbsHelpersVersionPatch = 2
4-
# hbsHelpersVersionLabel = alpha-3
5-
hbsHelpersReleaseBuild = false
2+
hbsHelpersVersionMinor = 2
3+
hbsHelpersVersionPatch = 0
4+
# hbsHelpersVersionLabel = rc-1
5+
hbsHelpersReleaseBuild = true
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Mon Apr 25 12:16:33 CEST 2016
1+
#Wed Jul 20 17:05:51 CEST 2016
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-bin.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-all.zip

src/main/groovy/org/beryx/hbs/Helpers.groovy

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ enum Helpers implements Helper {
152152
chars.each {ch ->
153153
if(Character.isJavaIdentifierPart(ch)) {
154154
if((first && !Character.isJavaIdentifierStart(ch)) || (startNewPart && useUnderscore)) sb << '_'
155-
sb << (first ? ch.toLowerCase() : (startNewPart && useCamelCase) ? ch.toUpperCase() : ch)
155+
sb << (first ? ch.toLowerCase() : (startNewPart ? (useCamelCase ? ch.toUpperCase() : ch.toLowerCase()) : ch))
156156
startNewPart = false
157157
first= false
158158
} else {
@@ -162,6 +162,25 @@ enum Helpers implements Helper {
162162
buffer.append(sb.toString())
163163
}
164164
buffer
165+
}),
166+
167+
JAVA_COMMENT("javaComment", { String commentFile, Options options ->
168+
Options.Buffer buffer = options.buffer()
169+
170+
String comment = null
171+
try {
172+
comment = options.handlebars.loader.sourceAt(commentFile).content()
173+
} catch (Exception e) {
174+
log.debug "Comment file $commentFile not found (${options.handlebars.loader.resolve(commentFile)})"
175+
}
176+
if(comment) {
177+
buffer.append('/*\n')
178+
comment.eachLine { line ->
179+
buffer.append(' * ').append(line).append('\n')
180+
}
181+
buffer.append(' */\n')
182+
}
183+
buffer
165184
})
166185

167186

src/test/groovy/org/beryx/hbs/HelpersSpec.groovy

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,4 +362,24 @@ class HelpersSpec extends Specification implements TestUtil {
362362
"'!!! 6 x 9 = 42'" | '_6X942'
363363
"'!!! 6 x 9 = 42' camelCase=false underscore=true" | '_6_x_9_42'
364364
}
365+
366+
def "javaComment should insert the commentFile"() {
367+
given:
368+
def template = """
369+
{{javaComment 'This is public-domain software.'}}
370+
public class A {}
371+
""".stripIndent()
372+
373+
when:
374+
def merged = merge(template, context)
375+
376+
then:
377+
merged == '''
378+
/*
379+
* This is public-domain software.
380+
*/
381+
public class A {}
382+
'''.stripAll()
383+
384+
}
365385
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This is public domain software.
2+
Do whatever you want with it.

0 commit comments

Comments
 (0)