add title variable and apply it to script too

This commit is contained in:
Bill Burke 2016-05-03 12:02:26 -04:00
parent 16e4b237f6
commit 52a365835f
3 changed files with 13 additions and 9 deletions

View file

@ -1,4 +1,4 @@
= Summary = {{book.title}}
. link:topics/overview.adoc[Overview] . link:topics/overview.adoc[Overview]
.. link:topics/overview/recommended-reading.adoc[Recommended Reading] .. link:topics/overview/recommended-reading.adoc[Recommended Reading]

View file

@ -9,6 +9,7 @@
"splitter" "splitter"
], ],
"variables": { "variables": {
"title": "Keycloak Installation and Configuration Guide",
"community": true, "community": true,
"product": false, "product": false,
"images": "keycloak-images", "images": "keycloak-images",

View file

@ -2,16 +2,20 @@ import sys, os, re, json, shutil, errno
def transform(root, f, targetdir): def transform(root, f, targetdir):
full = os.path.join(root, f) full = os.path.join(root, f)
print full
input = open(full, 'r').read() input = open(full, 'r').read()
dir = os.path.join(targetdir, root) dir = os.path.join(targetdir, root)
if not os.path.exists(dir): if not os.path.exists(dir):
os.makedirs(dir) os.makedirs(dir)
output = open(os.path.join(dir, f), 'w') output = open(os.path.join(dir, f), 'w')
input = applyTransformation(input)
output.write(input)
def applyTransformation(input):
for variable in re.findall(r"\{\{(.*?)\}\}", input): for variable in re.findall(r"\{\{(.*?)\}\}", input):
tmp = variable.replace('.', '_') tmp = variable.replace('.', '_')
input = input.replace(variable, tmp) input = input.replace(variable, tmp)
input = input.replace('{{', '{').replace('}}','}') input = input.replace('{{', '{').replace('}}', '}')
input = re.sub(r"<<fake.+#", "<<", input) input = re.sub(r"<<fake.+#", "<<", input)
for variable in re.findall(r"[ ]*{% if (.*?) %}", input): for variable in re.findall(r"[ ]*{% if (.*?) %}", input):
tmp = variable.replace('.', '_') tmp = variable.replace('.', '_')
@ -19,7 +23,8 @@ def transform(root, f, targetdir):
exp = re.compile("[ ]*{% if (.*?) %}(.*?)[ ]*{% endif %}", re.DOTALL) exp = re.compile("[ ]*{% if (.*?) %}(.*?)[ ]*{% endif %}", re.DOTALL)
input = re.sub(exp, "ifeval::[{\g<1>}==true]\g<2>endif::[]", input) input = re.sub(exp, "ifeval::[{\g<1>}==true]\g<2>endif::[]", input)
input = re.sub(r"image:(\.\./)*", "image:", input) input = re.sub(r"image:(\.\./)*", "image:", input)
output.write(input) return input
indir = 'topics' indir = 'topics'
targetdir = 'target' targetdir = 'target'
@ -55,11 +60,7 @@ include::document-attributes.adoc[]
""") """)
input = re.sub(r"[ ]*\.+\s*link:(.*)\[(.*)\]", "include::\g<1>[]", input) input = re.sub(r"[ ]*\.+\s*link:(.*)\[(.*)\]", "include::\g<1>[]", input)
for variable in re.findall(r"[ ]*{% if (.*?) %}", input): input = applyTransformation(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)
output.write(input) output.write(input)
# parse book.json file and create document attributes # parse book.json file and create document attributes
@ -93,6 +94,8 @@ for attribute in attributeList:
for k in attribute.keys(): for k in attribute.keys():
output.write(':book_' + k + ": " + attribute[k] + "\n") output.write(':book_' + k + ": " + attribute[k] + "\n")
print "Transformation complete!"