Skip to content

Commit

Permalink
dtm: redesign certain parts (#20735)
Browse files Browse the repository at this point in the history
  • Loading branch information
GGRei committed Feb 6, 2024
1 parent 7fd1b16 commit 2f4858c
Show file tree
Hide file tree
Showing 4 changed files with 287 additions and 196 deletions.
Expand Up @@ -6,7 +6,7 @@ import os
struct App {
vweb.Context
pub mut:
dtm &dtm.DynamicTemplateManager = dtm.create_dtm() @[vweb_global]
dtmi &dtm.DynamicTemplateManager = unsafe { nil } @[vweb_global]
shared_data_string []string @[vweb_global]
shared_data_int []int @[vweb_global]
shared_switch int = 1 @[vweb_global]
Expand All @@ -23,12 +23,16 @@ fn main() {
app.shared_data_int << 123456
app.shared_data_int << 7891011

dtm.initialize_dtm(mut app.dtm) or { eprintln(err) }
cache_folder_path := os.join_path(os.dir(os.executable()), 'vcache_dtm')
app.dtmi = dtm.initialize(def_cache_path: cache_folder_path)
defer {
app.dtmi.stop_cache_handler()
}
/*
app.initialize_dtm(mut &app.dtm,
dtm.initialize(
compress_html: false
active_cache_server: false
max_size_data_in_mem: 100) or { eprintln(err) }
max_size_data_in_mem: 100)
*/
go app.update_data()

Expand All @@ -46,7 +50,7 @@ pub fn (mut app App) index() vweb.Result {
tmpl_var['html_#includehtml'] = app.shared_data_string[app.shared_switch + 2]

// You can also modify the HTML template file directly without having to recompile the application.
html_content := app.dtm.serve_dynamic_template('index.html',
html_content := app.dtmi.expand('index.html',
placeholders: &tmpl_var
cache_delay_expiration: dtm.cache_delay_expiration_at_min
)
Expand Down

0 comments on commit 2f4858c

Please sign in to comment.