From 52a365835f92e15ca1b024c977f1c66c4996588e Mon Sep 17 00:00:00 2001 From: Bill Burke Date: Tue, 3 May 2016 12:02:26 -0400 Subject: [PATCH] add title variable and apply it to script too --- SUMMARY.adoc | 2 +- book.json | 1 + gitlab-conversion.py | 19 +++++++++++-------- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/SUMMARY.adoc b/SUMMARY.adoc index 88d775e501..4cf66acf7c 100755 --- a/SUMMARY.adoc +++ b/SUMMARY.adoc @@ -1,4 +1,4 @@ -= Summary += {{book.title}} . link:topics/overview.adoc[Overview] .. link:topics/overview/recommended-reading.adoc[Recommended Reading] diff --git a/book.json b/book.json index fe5534d5bf..009ed7b343 100755 --- a/book.json +++ b/book.json @@ -9,6 +9,7 @@ "splitter" ], "variables": { + "title": "Keycloak Installation and Configuration Guide", "community": true, "product": false, "images": "keycloak-images", diff --git a/gitlab-conversion.py b/gitlab-conversion.py index d500ce3bc9..21a1d67bbe 100755 --- a/gitlab-conversion.py +++ b/gitlab-conversion.py @@ -2,16 +2,20 @@ import sys, os, re, json, shutil, errno def transform(root, f, targetdir): full = os.path.join(root, f) - print full input = open(full, 'r').read() dir = os.path.join(targetdir, root) if not os.path.exists(dir): os.makedirs(dir) output = open(os.path.join(dir, f), 'w') + input = applyTransformation(input) + output.write(input) + + +def applyTransformation(input): for variable in re.findall(r"\{\{(.*?)\}\}", input): tmp = variable.replace('.', '_') input = input.replace(variable, tmp) - input = input.replace('{{', '{').replace('}}','}') + input = input.replace('{{', '{').replace('}}', '}') input = re.sub(r"<}==true]\g<2>endif::[]", input) input = re.sub(r"image:(\.\./)*", "image:", input) - output.write(input) + return input + indir = 'topics' targetdir = 'target' @@ -55,11 +60,7 @@ include::document-attributes.adoc[] """) input = re.sub(r"[ ]*\.+\s*link:(.*)\[(.*)\]", "include::\g<1>[]", input) -for variable in re.findall(r"[ ]*{% if (.*?) %}", input): - tmp = variable.replace('.', '_') - input = input.replace(variable, tmp) -exp = re.compile("[ ]*{% if (.*?) %}(.*?)[ ]*{% endif %}", re.DOTALL) -input = re.sub(exp, "ifeval::[{\g<1>}==true]\g<2>endif::[]", input) +input = applyTransformation(input) output.write(input) # parse book.json file and create document attributes @@ -93,6 +94,8 @@ for attribute in attributeList: for k in attribute.keys(): output.write(':book_' + k + ": " + attribute[k] + "\n") +print "Transformation complete!" +