I am a complete beginner with telosys. I have been through the documentation and the youtube video for an introduction, however, I can't seem to understand where the input to the templates comes from.
I have made the following entity
Feature {
name : string;
introduced: string;
present: boolean;
}
and I have the following template
Current entity is first ${feature.name}
When I attempt to generate the output on the command line using 'gen' I understandably get an error.
How do I provide input to these models? Can I plumb it into my existing python script?
def main():
# Create a feature manually or compute the values based on some input
f1 = Feature()
f1.name = "My feature"
f1.present = False
f2.introduced = "This was my first feature"
# How do I call telosys gen from this point onwards?
gen.gen()???
I maybe have completely missed the point.
Your "Feature" entity is correct.
The point you missed is the template working principle (in .vm file)
A template is designed to work with 1 to N entities, so it can only work with a generic entity as defined in the model, for example it can get the current entity name, but it cannot access an entity by its functional name (eg ${feature.name} : "feature" is not a model object).
A template works only with the model objects, all the objects you can use in a template are defined here: https://doc.telosys.org/templates/telosys-objects ). You can use the current entity with "$entity" object, use an attribute with "$attribute" object, etc
In your case if you want to create a Python file for each entity (among which "Feature") you will have to use ${entity.name} (returns "Feature") and to iterate over all attributes ( #foreach( $attribute in $entity.attributes ) to get your attributes ( "name", "introduced", "present" )
If you need examples, templates for Python code generation are available on GitHub : https://github.com/telosys-templates/
Here is a basic Python class template : https://github.com/telosys-templates/python-persistence-sqlalchemy/blob/master/entities/Xxx_class_py.vm
To launch generation just use Telosys-CLI "gen" command