You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2017/11/23 14:25:05 UTC
[sling-site] branch master updated: Split utilities in specific
classes
This is an automated email from the ASF dual-hosted git repository.
bdelacretaz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-site.git
The following commit(s) were added to refs/heads/master by this push:
new 32b1d23 Split utilities in specific classes
32b1d23 is described below
commit 32b1d239fda048de4623d4b70f1090d9997f8b49
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Thu Nov 23 15:24:51 2017 +0100
Split utilities in specific classes
---
src/main/jbake/templates/includes/Git.groovy | 18 ++++++++++++++++++
src/main/jbake/templates/includes/OS.groovy | 17 +++++++++++++++++
src/main/jbake/templates/includes/U.groovy | 17 ++---------------
src/main/jbake/templates/page.tpl | 2 +-
4 files changed, 38 insertions(+), 16 deletions(-)
diff --git a/src/main/jbake/templates/includes/Git.groovy b/src/main/jbake/templates/includes/Git.groovy
new file mode 100644
index 0000000..5a055f5
--- /dev/null
+++ b/src/main/jbake/templates/includes/Git.groovy
@@ -0,0 +1,18 @@
+// Shared Git utilities
+package includes
+
+class Git {
+
+ /** Get Git revision info for the specified file */
+ def static getRevisionInfo(filename) {
+ def gitCmd = 'git log -1 --format=%h####%ad####%an####%s ' + filename
+ def defaultText = "0####0000####<MISSING>####<MISSING>"
+ def gitInfo = includes.U.exec(gitCmd, defaultText).split("####")
+ return [
+ lastCommit : gitInfo[0],
+ date : gitInfo[1],
+ author : gitInfo[2],
+ comment : gitInfo[3]
+ ]
+ }
+}
\ No newline at end of file
diff --git a/src/main/jbake/templates/includes/OS.groovy b/src/main/jbake/templates/includes/OS.groovy
new file mode 100644
index 0000000..4ba91c3
--- /dev/null
+++ b/src/main/jbake/templates/includes/OS.groovy
@@ -0,0 +1,17 @@
+// Shared OS-related utilities
+package includes
+
+class OS {
+ /* Execute an OS command and return its output,
+ * or the defaultText if an error occurs
+ */
+ def static exec(cmd, defaultText) {
+ try {
+ def p = cmd.execute()
+ p.waitFor()
+ return p.text
+ } catch(Exception e) {
+ return defaultText
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/jbake/templates/includes/U.groovy b/src/main/jbake/templates/includes/U.groovy
index a05d920..cb1595b 100644
--- a/src/main/jbake/templates/includes/U.groovy
+++ b/src/main/jbake/templates/includes/U.groovy
@@ -1,4 +1,4 @@
-// Shared utilities
+// Shared general utilities
package includes
class U {
@@ -57,7 +57,7 @@ class U {
return result
}
- def exec(cmd, defaultText) {
+ def static exec(cmd, defaultText) {
try {
def p = cmd.execute()
p.waitFor()
@@ -66,17 +66,4 @@ class U {
return defaultText
}
}
-
- def getRevisionInfo(filename) {
- def lastCommit = "444eb637ff1ddcf11a0f37f02dd4b3fe89eb149f"
- def gitCmd = 'git log -1 --format=%h####%ad####%an####%s ' + filename
- def defaultText = "0####0000####<MISSING>####<MISSING>"
- def gitInfo = exec(gitCmd, defaultText).split("####")
- return [
- lastCommit : gitInfo[0],
- date : gitInfo[1],
- author : gitInfo[2],
- comment : gitInfo[3]
- ]
- }
}
\ No newline at end of file
diff --git a/src/main/jbake/templates/page.tpl b/src/main/jbake/templates/page.tpl
index eb41386..e4a1557 100644
--- a/src/main/jbake/templates/page.tpl
+++ b/src/main/jbake/templates/page.tpl
@@ -45,7 +45,7 @@ layout 'layout/main.tpl', true,
},
lastModified: contents {
div(class:"revisionInfo") {
- def info = U.getRevisionInfo(content.file);
+ def info = includes.Git.getRevisionInfo(content.file);
yield "Last modified by "
span(class:"author") { yield info.author }
yield " on "
--
To stop receiving notification emails like this one, please contact
['"commits@sling.apache.org" <co...@sling.apache.org>'].