1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/examples/vweb/vweb_assets/vweb_assets.v

43 lines
1001 B
V
Raw Normal View History

2020-03-07 16:16:03 +03:00
module main
import os
2020-04-26 14:49:31 +03:00
import vweb
// import vweb.assets
2020-04-26 14:49:31 +03:00
import time
2020-03-07 16:16:03 +03:00
const (
port = 8081
)
struct App {
vweb.Context
2020-03-07 16:16:03 +03:00
}
fn main() {
mut app := &App{}
app.serve_static('/favicon.ico', 'favicon.ico')
2020-03-07 16:16:03 +03:00
// 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)
2020-03-07 16:16:03 +03:00
}
pub fn (mut app App) index() vweb.Result {
2020-03-07 16:16:03 +03:00
// 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)
2020-03-07 16:16:03 +03:00
title := 'VWeb Assets Example'
subtitle := 'VWeb 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()
2020-03-07 16:16:03 +03:00
}
fn (mut app App) text() vweb.Result {
return app.Context.text('Hello, world from vweb!')
2020-03-07 16:16:03 +03:00
}
fn (mut app App) time() vweb.Result {
return app.Context.text(time.now().format())
2020-03-07 16:16:03 +03:00
}