Skip to content

Commit

Permalink
Move templates to (temporary) new structure
Browse files Browse the repository at this point in the history
Ideally each template should be under each technology dir but
the way the generic generator is written now, it assumes everything
under one directory.  For now, it can stay like this (but under
the output_filters directory).

Signed-off-by: Gunnar Andersson <[email protected]>
  • Loading branch information
gunnar-mb committed Jan 7, 2025
1 parent 30686f8 commit c901203
Show file tree
Hide file tree
Showing 34 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions docs/static-developer-generators.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ A simple generator (with only one template) can be done like this:

Unless you need to add more logic, generating one input file with one (or several)
templates is basically already available if ifex_generator.py is called as a
main program. You specify the directory name (relative to `<project-dir>/ifex/templates`)
main program. You specify the directory name (relative to `<project-dir>/output_filters/templates`)
where the template(s) is stored. Note that `setup.py` "installs" an executable entrypoint
`ifexgen` to call the program:

Expand All @@ -53,7 +53,7 @@ An advanced generator (with several templates) can be done like this:
* Import the ifex_generator.py and ifex_parser.py, and TemplateDir modules.
* Get the needed Service description file(s) (YAML), for example from command line argument
* For each file, get the Abstract Syntax Tree representation by calling `ifex_parser.get_ast_from_yaml_file(service_desc_file)`
* Write templates according to (some, not all) node types. You can call `gen(node)` or `gen(node, <Template>)` from within a template - see details below. Templates must be under a specific sub-directory of `<project-dir>/ifex/templates` and must be named with the naming convention such that the node type is mentioned first (see template chapter).
* Write templates according to (some, not all) node types. You can call `gen(node)` or `gen(node, <Template>)` from within a template - see details below. Templates must be under a specific sub-directory of `<project-dir>/output_filters/templates` and must be named with the naming convention such that the node type is mentioned first (see template chapter).
* Once the template directory is known, ee-initialize the TemplateDir object if needed. This will populate the default templates data structure such that gen() knows which template to use. It automatically uses the naming of the templates to know which template is for which node type.
* Implement the `gen()` function, normally by delegating directly into `ifex_generator.gen()`, but you can put your own logic here if needed.
* Set the jinja environment, passing in the gen() and any other symbols that must be callable from within Jinja templates.
Expand Down Expand Up @@ -143,7 +143,7 @@ gen(node, 'My-alternative-method-template.tpl')
### Naming convention
The only strict requirement is that all templates to be used by automatic type-to-template mapping in the gen() function, must be within the same subdirectory and must be named according to the naming conventioned mentioned before.

Templates can be stored in the sub-directories of the ifex/templates/ directory.
Templates can be stored in the sub-directories of the output_filters/templates/ directory.

The intended target format (output format) is normally clear from the naming of the subdirectory. E.g. "protobuf", or "D-Bus" or "ARXML" or other output format.

Expand Down
2 changes: 1 addition & 1 deletion models/ifex/ifex_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

# For other features from parser module
from typing import Any
from ifex.templates import JinjaTemplateEnv
from output_filters.templates import JinjaTemplateEnv

# Module global - probably soon to be modified to run-time instantiation of a
# JinjaTemplateEnv instance instead.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
import jinja2
from typing import Dict, Any
from ifex.templates import TemplateDir
from output_filters.templates import TemplateDir

class JinjaTemplateEnv:

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from setuptools import setup
from setuptools import find_packages

from ifex.templates import TemplateDir
from output_filters.templates import TemplateDir

def get_template_files():
paths = []
Expand Down

0 comments on commit c901203

Please sign in to comment.