Skip to content

Commit

Permalink
Enhancement: Add Environment Variable Option for Custom Template Loca…
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffkala authored and cppmonkey committed Oct 25, 2023
1 parent d6b8466 commit ca23481
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,25 @@ $
>>>
```

### Define Custom Templates Directory

To use a custom templates directory set the environmental variable `NTC_TEMPLATES_DIR`.

**Requirements**
1. `index` file needs to be defined with standard structure. [See](#Index-File)
2. Each custom template should be defined.

To manaully set variable:
```shell
export NTC_TEMPLATES_DIR=/path/to/new/location/templates
```

To set within your program:
```python
import os
os.environ["NTC_TEMPLATES_DIR"] = "/path/to/new/templates/location/templates"
```

Contributing
------------

Expand Down
12 changes: 7 additions & 5 deletions lib/ntc_templates/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@


def _get_template_dir():
package_dir = os.path.dirname(__file__)
template_dir = os.path.join(package_dir, "templates")
if not os.path.isdir(template_dir):
project_dir = os.path.dirname(os.path.dirname(os.path.dirname(template_dir)))
template_dir = os.path.join(project_dir, "templates")
template_dir = os.environ.get("NTC_TEMPLATES_DIR")
if template_dir is None:
package_dir = os.path.dirname(__file__)
template_dir = os.path.join(package_dir, "templates")
if not os.path.isdir(template_dir):
project_dir = os.path.dirname(os.path.dirname(os.path.dirname(template_dir)))
template_dir = os.path.join(project_dir, "templates")

return template_dir

Expand Down

0 comments on commit ca23481

Please sign in to comment.