-
-
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.
examples: migrate vweb examples to veb
- Loading branch information
1 parent
f53b5d7
commit c004d0c
Showing
16 changed files
with
64 additions
and
117 deletions.
There are no files selected for viewing
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,44 @@ | ||
module main | ||
|
||
import veb | ||
|
||
const port = 8082 | ||
|
||
pub struct Context { | ||
veb.Context | ||
} | ||
|
||
pub struct App { | ||
} | ||
|
||
fn main() { | ||
mut app := &App{} | ||
veb.run[App, Context](mut app, 8080) | ||
} | ||
|
||
pub fn (mut app App) index() veb.Result { | ||
return $veb.html() | ||
} | ||
|
||
@['/upload'; post] | ||
pub fn (mut app App) upload(mut ctx Context) veb.Result { | ||
fdata := ctx.files['upfile'] | ||
|
||
data_rows := fdata[0].data.split('\n') | ||
|
||
mut output_data := '' | ||
|
||
for elem in data_rows { | ||
delim_row := elem.split('\t') | ||
output_data += '${delim_row[0]}\t${delim_row[1]}\t${delim_row[0].int() + delim_row[1].int()}\n' | ||
} | ||
|
||
output_data = output_data.all_before_last('\n') | ||
|
||
println(output_data) | ||
|
||
ctx.set_header(.content_disposition, 'attachment; filename=results.txt') | ||
ctx.send_response_to_client('application/octet-stream', output_data) | ||
|
||
return $veb.html() | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
examples/vweb/static_website/README.md → examples/veb/static_website/README.md
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
32 changes: 18 additions & 14 deletions
32
examples/vweb/vweb_assets/vweb_assets.v → examples/veb/veb_assets/vweb_assets.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 |
---|---|---|
@@ -1,40 +1,44 @@ | ||
module main | ||
|
||
import os | ||
import vweb | ||
import veb | ||
// import vweb.assets | ||
import time | ||
|
||
const port = 8081 | ||
|
||
struct App { | ||
vweb.Context | ||
pub struct Context { | ||
veb.Context | ||
} | ||
|
||
pub struct App { | ||
veb.StaticHandler | ||
} | ||
|
||
fn main() { | ||
mut app := &App{} | ||
app.serve_static('/favicon.ico', 'favicon.ico') | ||
app.serve_static('/favicon.ico', 'favicon.ico')! | ||
// Automatically make available known static mime types found in given directory. | ||
os.chdir(os.dir(os.executable()))! | ||
app.handle_static('assets', true) | ||
vweb.run(app, port) | ||
app.handle_static('assets', true)! | ||
veb.run[App, Context](mut app, 8080) | ||
} | ||
|
||
pub fn (mut app App) index() vweb.Result { | ||
pub fn (mut app App) index() veb.Result { | ||
// We can dynamically specify which assets are to be used in template. | ||
// mut am := assets.new_manager() | ||
// am.add_css('assets/index.css') | ||
// css := am.include_css(false) | ||
title := 'VWeb Assets Example' | ||
subtitle := 'VWeb can serve static assets too!' | ||
title := 'Veb Assets Example' | ||
subtitle := 'Veb can serve static assets too!' | ||
message := 'It also has an Assets Manager that allows dynamically specifying which CSS and JS files to be used.' | ||
return $vweb.html() | ||
return $veb.html() | ||
} | ||
|
||
fn (mut app App) text() vweb.Result { | ||
return app.Context.text('Hello, world from vweb!') | ||
fn (mut app App) text() veb.Result { | ||
return ctx.text('Hello, world from veb!') | ||
} | ||
|
||
fn (mut app App) time() vweb.Result { | ||
return app.Context.text(time.now().format()) | ||
fn (mut app App) time() veb.Result { | ||
return ctx.text(time.now().format()) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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