Replies: 1 comment
-
for completeness sake if someone stumbles over the same problem: With the above i was able to write some python code that will load the json-data from #!/bin/env python
import subprocess
import _jsonnet
import json
from jinja2 import Template
# 3. Formulate the command to evaluate the given Jsonnet file (tk is used for executing it)
command = "tk eval environments/xyz/docs.jsonnet"
# 4. Run the shell command and capture the output
result = subprocess.check_output(command, shell=True, text=True)
# 5. Convert the JSON output from the command into a Python dictionary
json_data = json.loads(result)
# 6. Load the Markdown template (Accounts.md.j2) using Jinja2 for further rendering
with open('docs/template.md.j2', 'r') as file:
markdown_template = file.read()
# 7. Use Jinja2 to render the template with the data from the JSON dictionary
template = Template(markdown_template)
rendered_markdown = template.render(json_data)
# 8. Save the rendered Markdown content to a new file in the specified environment path
output_path = f'{args.environment_path}/readme.md'
with open(output_path, 'w') as file:
file.write(rendered_markdown)
# 9. Inform the user that the file has been generated successfully
print(f"{output_path} has been generated with templated values.") where {
docs: {
a: 1
} would be referenced in the template as |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
i am currently trying to automatically produce some documentation from a tanka environment. I have all my variables under
$._config.{a,b,c}
, but (defaults) distributed over multiblelib/{a,b,c}/secrets.jsonnet
files.First try i came up with:
docs.jsonnet
:And then parse that with some python script, but i am wondering if there is a better way? E.g. if tanka can show only the _config part or similar?
Beta Was this translation helpful? Give feedback.
All reactions