Skip to content
Snippets Groups Projects
Commit 29756f64 authored by Timo Koch's avatar Timo Koch Committed by Dennis Gläser
Browse files

[examples] Add uniform fold mechanism for source code to generator

parent f5af3746
No related branches found
No related tags found
1 merge request!1933[examples] Move properties to their own header
......@@ -50,12 +50,21 @@ def cppRules():
return [suppressHeader, suppressHeaderGuard, suppressEndHeaderGuard, docTransforms]
def transformCode(code, rules):
def transformCode(code, rules, codeFileName):
# exclude stuff between [[exclude]] and [[/exclude]]
exclude = parseTaggedContent("exclude", action=replaceWith(""))
code = exclude.transformString(code)
# Enable toggling content between [[content]] and [[/content]]
def wrapContentIntoDetails(token):
beginDetails = "//\n// <details open>\n"
summmary = "// <summary><b>Click to hide/show the file documentation</b> (or inspect the [source code]({}))</summary>\n//\n".format(codeFileName)
endDetails = "\n//\n// </details>\n"
return beginDetails + summmary + token[0] + endDetails
wrapContent = parseTaggedContent("content", action=wrapContentIntoDetails)
code = wrapContent.transformString(code)
for transform in rules:
code = transform.transformString(code)
return code
......@@ -27,7 +27,8 @@ def convertToMarkdownAndMerge(dir, config):
targetFile.write(markdown.read())
elif fileExtension == ".hh" or fileExtension == ".cc":
with open(os.path.join(dir, source), "r") as cppCode:
targetFile.write("\n\n" + transformCode(cppCode.read(), cppRules()) + "\n")
sourceRelPath = os.path.relpath(os.path.abspath(os.path.join(dir, source)), os.path.split(os.path.abspath(targetPath))[0])
targetFile.write("\n\n" + transformCode(cppCode.read(), cppRules(), sourceRelPath) + "\n")
else:
raise IOError("Unsupported or unknown file extension *{}".format(fileExtension))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment