Skip to content

Commit dc0b0f5

Browse files
authored
x.templating.dtm: fix formatting and improve clarity in README.md (#25966)
1 parent 90fa8bc commit dc0b0f5

1 file changed

Lines changed: 43 additions & 45 deletions

File tree

‎vlib/x/templating/dtm/README.md‎

Lines changed: 43 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ templates with Vweb, without the need to recompile the application with every ch
55

66
## Quick Start
77

8-
Using the dynamic template manager ( named '**dtm**' in this readme) is relatively straightforward.
9-
You just need to initialize an instance. Then, call the '**expand**' function in the code that
8+
Using the dynamic template manager (named `dtm` in this readme) is relatively straightforward.
9+
You just need to initialize an instance. Then, call the `expand` function in the code that
1010
manages your template.
1111

12-
Before starting, You can specify a folder, but it is not mandatory to store the generated cache. If
12+
Before starting, you can specify a folder, but it is not mandatory to store the generated cache. If
1313
nothing is specified or if there is a problem with the targeted folder (for example, a permission
1414
issue), the DTM will attempt to create a cache folder in the temporary file area of your OS.
1515
Finally, if all this does not prove successful, then the DTM will disable the cache system and
1616
notify the user if the cache system was previously required.
1717

18-
However, at the root directory of your project, you need to create a '**templates**' folder. The
18+
However, at the root directory of your project, you need to create a `templates/` folder. The
1919
absence of these directories will prevent you from using the dtm. You must add your template files
2020
into the folder you previously created. ***Be aware that if the templates are not placed in the
2121
correct directory, the DTM will return an error message indicating that it cannot find the
@@ -51,12 +51,12 @@ fn main() {
5151
}
5252
```
5353

54-
#### and its template text format :
54+
#### and its template text format:
5555

5656
```
57-
Title of text : @title
58-
Value in the text : @non_string_type
59-
HTML tags are always escaped in text file : @html_section
57+
Title of text: @title
58+
Value in the text: @non_string_type
59+
HTML tags are always escaped in text file: @html_section
6060
```
6161

6262
### 2. Minimal Vweb example:
@@ -85,16 +85,14 @@ fn main() {
8585
app.dtmi.stop_cache_handler()
8686
}
8787
88-
/*
89-
Here is an example of init configuration :
88+
// Here is an example of init configuration:
9089
9190
dtm.initialize(
92-
def_cache_path: cache_folder_path
93-
compress_html: false
94-
active_cache_server: false
95-
max_size_data_in_mem: 100
96-
)
97-
*/
91+
def_cache_path: cache_folder_path
92+
compress_html: false
93+
active_cache_server: false
94+
max_size_data_in_mem: 100
95+
)
9896
9997
veb.run[App, Context](mut app, 18081)
10098
}
@@ -108,7 +106,7 @@ pub fn (mut app App) index(mut ctx Context) veb.Result {
108106
}
109107
```
110108

111-
#### and its template html format :
109+
#### and its template html format:
112110

113111
```html
114112
<!doctype html>
@@ -138,18 +136,18 @@ There are two types of option possibilities:
138136

139137
Three parameters are available:
140138

141-
- `def_cache_path` : ( **String** value ) User can define the path of cache folder.
142-
- `max_size_data_in_mem` : ( **Int** value ) Maximum size of data allowed in memory for each cached
143-
template. The value must be specified in kilobytes. ( Default is: 500KB / Limit max is : 500KB )
144-
- `compress_html` : ( **Bool** value ) Light '**minifier**' of the HTML output, to remove all
145-
unnecessary spacing. ( Default is true, parameter taken into account only for HTML files )
146-
- `active_cache_server` : ( **Bool** value ) Activate or not the template cache system. ( Default
147-
is true, ***_Highly recommended to keep it enabled for optimal performance_*** )
139+
- `def_cache_path` (**string** value): User can define the path of cache folder.
140+
- `max_size_data_in_mem` (**int** value): Maximum size of data allowed in memory for each cached.
141+
template. The value must be specified in kilobytes (default is: 500KB; limit max is: 500KB).
142+
- `compress_html` (**bool** value): Light **minifier** of the HTML output, to remove all
143+
unnecessary spacing (default is `true`, parameter taken into account only for HTML files).
144+
- `active_cache_server` (**bool** value): Activate or not the template cache system (default
145+
is true, ***_highly recommended to keep it enabled for optimal performance_***).
148146

149147
Regarding the `compress_html` option, it is recommended for performance reasons to disable it
150148
when working directly with raw template generation (i.e., with the cache system disabled).
151149

152-
Use it like this :
150+
Use it like this:
153151

154152
```v ignore
155153
initialize(
@@ -162,30 +160,30 @@ initialize(
162160

163161
### Defined for each call of expand function
164162

165-
- `placeholders` ( **&map[string]DtmMultiTypeMap** value ) Used to map placeholders within the
163+
- `placeholders` (**&map[string]DtmMultiTypeMap** value): Used to map placeholders within the
166164
template to their corresponding content, facilitating dynamic content insertion, by specifying
167165
values in the placeholders map. Templates can dynamically display content.
168166

169-
- `cache_delay_expiration` ( **i64** value ) Specifies the cache expiration time for the concerned
170-
page in seconds. ( Default value is **86400** seconds or one day ). You can add any value you
171-
want in seconds as long as it remains within the indicated range ( see below ).
167+
- `cache_delay_expiration` (**i64** value): Specifies the cache expiration time for the concerned
168+
page in seconds (default value is `86400` seconds or one day). You can add any value you
169+
want in seconds as long as it remains within the indicated range (see below).
172170

173171
Possibility to use already defined cache delay constants like:
174172

175-
- `cache_delay_expiration_at_min` : five minutes
176-
- `cache_delay_expiration_at_max` : one year
177-
- `cache_delay_expiration_by_default` : one day
173+
- `cache_delay_expiration_at_min`: five minutes.
174+
- `cache_delay_expiration_at_max`: one year.
175+
- `cache_delay_expiration_by_default`: one day.
178176

179177
For specific cases, you can cancel the generation and use of cache file, even if the cache system
180-
is active :
178+
is active:
181179

182-
- `cache_delay_expiration` : -1
180+
- `cache_delay_expiration: -1`.
183181

184182
Or set a cache that will never expire:
185183

186-
- `cache_delay_expiration` : 0
184+
- `cache_delay_expiration: 0`.
187185

188-
Example :
186+
Example:
189187

190188
```v ignore
191189
expand('path/of/template.html',
@@ -196,7 +194,7 @@ expand('path/of/template.html',
196194

197195
## The PlaceHolders System
198196

199-
### On The User's Side Code :
197+
### On The User's Side Code:
200198

201199
The placeholder system allows for the insertion of dynamic content into your template. As of the
202200
current state of the module, it accepts the following types like:
@@ -221,7 +219,7 @@ expand('path/of/template.html',
221219
)
222220
```
223221

224-
Pay attention to this particular tag: "**_#includehtml**", it enables you to include HTML in the
222+
Pay attention to this particular tag: `_#includehtml`, it enables you to include HTML in the
225223
dynamic content. Without this tag, all characters will be escaped for obvious security reasons. By
226224
using this tag, only certain HTML tags are allowed. Here is the list:
227225

@@ -239,7 +237,7 @@ using this tag, only certain HTML tags are allowed. Here is the list:
239237

240238
#### Note that with a raw text template, all HTML tag inclusions are escaped.
241239

242-
### On The Template Side :
240+
### On The Template Side:
243241

244242
An example of a template, corresponding to the previous subsection:
245243

@@ -259,13 +257,13 @@ An example of a template, corresponding to the previous subsection:
259257
</html>
260258
```
261259

262-
You will note that the `'_#includehtml'` directive is not found in the template with
263-
`'@placeholder_name_3'`, and this is entirely normal. Directives are specially handled by the DTM,
264-
and including them in the name of your placeholders within the template will result in the
265-
placeholder not being found because it does not match the key name defined in the map containing
266-
the dynamic content.
260+
You will note that the `_#includehtml` directive is not found in the template with
261+
`@placeholder_name_3`, and this is entirely normal. Directives are specially handled
262+
by the DTM, and including them in the name of your placeholders within the template
263+
will result in the placeholder not being found because it does not match the key name
264+
defined in the map containing the dynamic content.
267265

268-
Like the traditional template system in V, inclusions or placeholders start with the '**@**'
266+
Like the traditional template system in V, inclusions or placeholders start with the `@`
269267
character. The traditional inclusion system is still perfectly usable, such as:
270268

271269
```

0 commit comments

Comments
 (0)