2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-13 10:35:40 +00:00

Include "config template" in docs (#7355)

- Extract data from file
- Add in "collapse" section
- Cleanup template file
This commit is contained in:
Oliver
2024-05-27 22:25:23 +10:00
committed by GitHub
parent 89cea3045a
commit b7b666b7f0
3 changed files with 47 additions and 117 deletions

View File

@ -22,7 +22,11 @@ The InvenTree server tries to locate the `config.yaml` configuration file on sta
!!! tip "Config File Location"
When the InvenTree server boots, it will report the location where it expects to find the configuration file
The configuration file *template* can be found on [GitHub]({{ sourcefile("src/backend/InvenTree/config_template.yaml") }})
#### Configuration File Template
The configuration file *template* can be found on [GitHub]({{ sourcefile("src/backend/InvenTree/config_template.yaml") }}), and is shown below:
{{ includefile("src/backend/InvenTree/config_template.yaml", "Configuration File Template", format="yaml") }}
!!! info "Template File"
The default configuration file (as defined by the template linked above) will be copied to the specified configuration file location on first run, if a configuration file is not found in that location.

View File

@ -167,27 +167,37 @@ def define_env(env):
return assets
@env.macro
def templatefile(filename):
"""Include code for a provided template file."""
def includefile(filename: str, title: str, format: str = ''):
"""Include a file in the documentation, in a 'collapse' block.
Arguments:
- filename: The name of the file to include (relative to the top-level directory)
- title:
"""
here = os.path.dirname(__file__)
template_dir = os.path.join(
here, '..', 'src', 'backend', 'InvenTree', 'report', 'templates'
)
template_file = os.path.join(template_dir, filename)
template_file = os.path.abspath(template_file)
path = os.path.join(here, '..', filename)
path = os.path.abspath(path)
basename = os.path.basename(filename)
if not os.path.exists(path):
raise FileNotFoundError(f'Required file {path} does not exist.')
if not os.path.exists(template_file):
raise FileNotFoundError(f'Report template file {filename} does not exist.')
with open(template_file, 'r') as f:
with open(path, 'r') as f:
content = f.read()
data = f'??? abstract "Template: {basename}"\n\n'
data += ' ```html\n'
data = f'??? abstract "{title}"\n\n'
data += f' ```{format}\n'
data += textwrap.indent(content, ' ')
data += '\n\n'
data += ' ```\n\n'
return data
@env.macro
def templatefile(filename):
"""Include code for a provided template file."""
base = os.path.basename(filename)
fn = os.path.join(
'src', 'backend', 'InvenTree', 'report', 'templates', filename
)
return includefile(fn, f'Template: {base}', format='html')