Skip to content

Commit

Permalink
dtm: hard reset on the branch to resolve all the git conflict issues
Browse files Browse the repository at this point in the history
  • Loading branch information
GGRei committed Jan 26, 2024
1 parent 754c83a commit 3d3e469
Show file tree
Hide file tree
Showing 8 changed files with 1,657 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import vweb
import time
import x.templating.dtm
import os

struct App {
vweb.Context
pub mut:
dtm &dtm.DynamicTemplateManager = dtm.create_dtm() @[vweb_global]
shared_data_string []string @[vweb_global]
shared_data_int []int @[vweb_global]
shared_switch int = 1 @[vweb_global]
}

fn main() {
mut app := &App{}

app.shared_data_string << 'vweb dtm'
app.shared_data_string << 'VWEB DTM'
app.shared_data_string << '<span>this <br> is <br> a <br> test <br> with <br> included <br> HTML!</span>'
app.shared_data_string << '<span>THIS <br> NOT <br> A <br> TEST!</span>'
app.shared_data_string << '<p>escaped html tags test</p>'
app.shared_data_int << 123456
app.shared_data_int << 7891011

dtm.initialize_dtm(mut app.dtm) or { eprintln(err) }
/*
app.initialize_dtm(mut &app.dtm,
compress_html: false
active_cache_server: false
max_size_data_in_mem: 100) or { eprintln(err) }
*/
go app.update_data()

app.mount_static_folder_at(os.resource_abs_path('static'), '/')

vweb.run(app, 18081)
}

@['/']
pub fn (mut app App) index() vweb.Result {
mut tmpl_var := map[string]dtm.DtmMultiTypeMap{}
tmpl_var['title'] = app.shared_data_string[app.shared_switch]
tmpl_var['non_string_type'] = app.shared_data_int[app.shared_switch]
tmpl_var['string_type'] = app.shared_data_string[4]
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',
placeholders: &tmpl_var
cache_delay_expiration: dtm.cache_delay_expiration_at_min
)
return app.html(html_content)
}

fn (mut app App) update_data() {
for {
if app.shared_switch == 1 {
app.shared_switch = 0
} else {
app.shared_switch = 1
}
time.sleep(10 * time.second)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
body {
font-family: Arial, sans-serif;
background-color: #f8f8f8;
color: #333;
margin: 0;
padding: 0;
}

#container {
width: 80%;
margin: 0 auto;
background-color: #fff;
padding: 20px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

h1 {
color: #007bff;
text-align: center;
}

p {
font-size: 16px;
line-height: 1.6;
}

span {
color: #28a745;
font-weight: bold;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<p>This is from a file inclusion!</p>
<span>DTM</span>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<title>@title</title>
@css '/index.css'
</head>
<body>
@include 'comment.html'
<div id="container">
<H1>@title</H1>
<p>@non_string_type</p>
<p>@string_type</p>
@html
</div>
</body>
</html>
Empty file.
Loading

0 comments on commit 3d3e469

Please sign in to comment.