Generating Travel Impressions code from the model

The JSON representation of the last model spiral is generated in the Model Concepts tool and then copied to the model.json file that is placed in the empty travel_impressions folder of the new app. The project’s model code is generated by dartling_gen; this is step two in our schema. In the Run | Manage Launches of Dart Editor, create a dartling_gen.dart command-line launch pointing to the following script in the dartling_gen project:

bin/dartling_gen.dart 

In the Script arguments, enter the following argument:

--genall projectpath domain model

For the travel_impressions project, the arguments are as follows:

--genall c:/dart/travel_impressions travel impressions 

The arguments are similar for the project path in Linux: /home/dart/travel_impressions.

The --genall argument indicates that the complete project will be generated. The c:/dart/travel_impressions argument replaces the projectpath parameter—a path to the project’s folder that contains the model.json file. The travel argument is the domain name and the impressions argument is the model name. By running the main function in the bin/dartling_gen.dart file, a project, with its domain and model, will be generated in the project directory. This project contains the folders doc, lib, test and web, as well as a pubspec.yaml file, which specifies our project is dependent on Dartling and dartling_default_app.

In the generated project, the lib folder has the gen and travel (domain) folders. The gen folder also has the travel (domain) folder. The travel folder, both in lib and gen, has the impressions (model) folder. The gen folder keeps the generic code (not to be edited!) that is to be regenerated when the model changes. However, the travel subfolder in lib contains the specific code that is open for changes. The generic code extends the code in Dartling, and the specific code extends the generic code.

Generating Travel Impressions code from the model

Structure of generated project

But what if the model changes? Then, update the JSON representation of the model in the model.json file. Regenerate only the lib/gen directory, by giving these arguments:

--gengen projectpath domain model

Tip

The generated code in lib/gen must not be edited by a programmer. The specific code, which is outside of the lib/gen folder, will be changed in the evolution of the application.

If you regenerate the whole project, be sure to have its backup to be able to compare the two versions. If you regenerate only the generic code in the lib/gen folder, you may need to adjust some specific code. When the complete project is generated, the content of the model.json file is reproduced in the lib/travel/impressions/json/model.dart file as the content of its travelImpressionsModelJson variable. This variable, and not the model.json file, is used in the running of the application. In this way, you may experiment with some minor changes in the model (for example, changing essential attributes) without losing the content of the model.json file. However, if you want to keep those changes, you should update the JSON file before the next code generation. After the code is generated, the README.md and travel_impressions_web.html files are usually updated in a minor way to reflect the project in question. To run the application, the web page travel_impressions_web.html (in the folder web/travel/impressions) is selected. If you run the app, it already shows two buttons with text Show Travelers and Show Countries. When these buttons are pushed, they show a grid with dummy data. The two travel_impressions_web files (.dart and .html) are the only web files, in addition to CSS files, in the project. However, they rely on dartling_default_app. The objective of this application is to validate the model by using its data. The next step is to create that data.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.237.201