| 1 | module main |
| 2 | |
| 3 | import os |
| 4 | import veb |
| 5 | // import veb.assets |
| 6 | import time |
| 7 | |
| 8 | pub struct Context { |
| 9 | veb.Context |
| 10 | } |
| 11 | |
| 12 | pub struct App { |
| 13 | veb.StaticHandler |
| 14 | } |
| 15 | |
| 16 | fn main() { |
| 17 | mut app := &App{} |
| 18 | app.serve_static('/favicon.ico', 'favicon.ico')! |
| 19 | // Automatically make available known static mime types found in given directory. |
| 20 | os.chdir(os.dir(os.executable()))! |
| 21 | app.handle_static('assets', true)! |
| 22 | veb.run[App, Context](mut app, 8080) |
| 23 | } |
| 24 | |
| 25 | pub fn (mut app App) index(mut ctx Context) veb.Result { |
| 26 | // We can dynamically specify which assets are to be used in template. |
| 27 | // mut am := assets.new_manager() |
| 28 | // am.add_css('assets/index.css') |
| 29 | // css := am.include_css(false) |
| 30 | title := 'Veb Assets Example' |
| 31 | subtitle := 'Veb can serve static assets too!' |
| 32 | message := 'It also has an Assets Manager that allows dynamically specifying which CSS and JS files to be used.' |
| 33 | return $veb.html() |
| 34 | } |
| 35 | |
| 36 | fn (mut app App) text(mut ctx Context) veb.Result { |
| 37 | return ctx.text('Hello, world from veb!') |
| 38 | } |
| 39 | |
| 40 | fn (mut app App) time(mut ctx Context) veb.Result { |
| 41 | return ctx.text(time.now().format()) |
| 42 | } |
| 43 | |