📜 ⬆️ ⬇️

Generation of documents. Problems and Solutions

To generate documents from templates, an important task is to reduce the number of templates. The smaller the templates, the easier it is to maintain them, to make changes to them. This can be achieved if the patterns are polymorphic, i.e. will contain redundancy. Depending on the generation parameters, the extra parts during the generation of the document will be deleted and as a result only those parts that are required will remain. Mark, for example, the template text as follows:

<part: 1> Text of part 1. </ part: 1>
Permanently present text. <part: 2> Text of part 2. </ part: 2>

Let's transfer to the generator in parameters that it is necessary to delete <part: 1> (or leave <part: 2>). As a result, we get:
')
Permanently present text. The text of part 2.

For the logical AND operation (do not delete if <part: 1> and <part: 3> are selected), the markup may be as follows:

<part: 1> <part: 3> Text of part 1. </ part: 3> </ part: 1>
Permanently present text. <part: 2> Text of part 2. </ part: 2>

For a logical OR operation (delete if <part: 1> or <part: 3> is selected), the markup may be as follows:

<part: 1> || <part: 3> Text of Part 1. </ part: 3> </ part: 1>
Permanently present text. <part: 2> Text of part 2. </ part: 2>

We list the advantages and disadvantages of this method of marking patterns.

Advantages:

- in one template can contain many thematically related documents.
- The markup is simple enough and can be done by non-IT staff. If there is a good tool for developing templates, an employee competent in the subject area will be able to perform such markup, and he will not need to work with an incompetent intermediary from IT.
- It is possible to get from the entire list of fields to fill in the information contained in the template, a list of fields that will remain after removing unnecessary fragments from the template.

Disadvantages:

- markup without a special developer tool is not readable.
- the sizes of the templates become very large, which can lead to a decrease in the generation rate if no special measures are taken.

To combat the large size of the templates, you can apply the method of breaking the template into parts, where parts are stored separately from the template and inserted into it only with the parameters passed to the generator. This significantly reduces the size of the template, and hence the generation time. The template is divided into parts automatically by the template development environment if there is a special markup in the template, which indicates when the part should be inserted into the main template.

Source: https://habr.com/ru/post/334666/


All Articles