-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dtm: hard reset on the branch to resolve all the git conflict issues
- Loading branch information
Showing
8 changed files
with
1,657 additions
and
0 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
vlib/vweb/tests/dynamic_template_manager_test_server/dynamic_template_manager_test_server.v
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
vlib/vweb/tests/dynamic_template_manager_test_server/static/index.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
2 changes: 2 additions & 0 deletions
2
vlib/vweb/tests/dynamic_template_manager_test_server/templates/comment.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
16 changes: 16 additions & 0 deletions
16
vlib/vweb/tests/dynamic_template_manager_test_server/templates/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Oops, something went wrong.