Skip to content

Commit

Permalink
examples: migrate vweb examples to veb
Browse files Browse the repository at this point in the history
  • Loading branch information
medvednikov committed Sep 17, 2024
1 parent f53b5d7 commit c004d0c
Show file tree
Hide file tree
Showing 16 changed files with 64 additions and 117 deletions.
44 changes: 44 additions & 0 deletions examples/veb/file_transform/file_transform.v
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.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Host a static website

Here is an example on how to use the vweb server's static capabilities,
Here is an example on how to use the Veb server's static capabilities,
to host a static website from the `dist/` folder. Just run the server,
it will be available at http://localhost:8080/ :

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
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())
}
62 changes: 0 additions & 62 deletions examples/vweb/cors/vweb_cors_example.v

This file was deleted.

40 changes: 0 additions & 40 deletions examples/vweb/file_transform/file_transform.v

This file was deleted.

1 change: 1 addition & 0 deletions vlib/vweb/vweb.v
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) 2019-2024 Alexander Medvednikov. All rights reserved.
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.
//@[deprecated: '`vweb` is deprecated `veb`. Please use `veb` instead.']
module vweb

import os
Expand Down

0 comments on commit c004d0c

Please sign in to comment.