andbrs
andbrs

Reputation: 59

Generate a single file with Telosys

how are you? I am learning how to use Telosys to make a code generator for Arduino, I was wondering if there is a way to create a single file for all the entities in my DSL. For example, I have the .entity files "Cars" and "Drivers", which generates me two .txt files when I generate code. Is there any way to generate the code for both .entity files in a single text file?

Upvotes: 2

Views: 187

Answers (1)

lgu
lgu

Reputation: 2460

Yes, it's possible and it's quite easy. In your ".vm" file you just have to iterate on each entity defined in the model by using one these entities list : "$model.allEntites" or "$selectedEntities" ( see templates doc : https://www.telosys.org/templates-doc/objects/model.html )

Here's an example :

All entities :
#foreach( $entity in $model.allEntites )
 . $entity.name : $entity.attributesCount attributes
#end

The "database doc" is a bundle of templates using this kind of generation. See "database_tables_list.vm" in bundle https://github.com/telosys-templates-v3/database-doc-T300

Don't forget to set the "number of generations" to "1" for this ".vm" file in the "templates.cfg" file in order to generate it only once

Example from "database doc" bundle ( "1" at the end of line ) :

Database tables list (HTML) ; database.html ; dbdoc ; database_tables_list.vm  ; 1

In your case for a text file :

My global text file ; global.txt ; myfolder ; mytemplate.vm  ; 1

Upvotes: 2

Related Questions