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

tutorials: more blog fixes (#5657)

This commit is contained in:
Lukas Neubert
2020-07-04 18:56:18 +02:00
committed by GitHub
parent 0626ac2901
commit fbfd92a899
6 changed files with 60 additions and 64 deletions

View File

@ -15,26 +15,27 @@ fn main() {
vweb.run<App>(8081)
}
fn (mut app App) index_text() {
/*
fn (mut app App) index_text() vweb.Result {
app.vweb.text('Hello, world from vweb!')
return vweb.Result{}
}
/*
fn (app &App) index_html() {
message := 'Hello, world from vweb!'
$vweb.html()
fn (app &App) index_html() vweb.Result {
message := 'Hello, world from Vweb!'
return $vweb.html()
}
*/
fn (app &App) index() vweb.Result {
articles := app.find_all_articles()
return $vweb.html()
}
pub fn (mut app App) init_once() {
db := sqlite.connect(':memory:') or {
db := sqlite.connect('blog.db') or {
panic(err)
}
db.exec('create table `Article` (id integer primary key, title text default "", text text default "")')
app.db = db
}
@ -49,10 +50,10 @@ pub fn (mut app App) new_article() vweb.Result {
title := app.vweb.form['title']
text := app.vweb.form['text']
if title == '' || text == '' {
app.vweb.text('Empty text/titile')
app.vweb.text('Empty text/title')
return vweb.Result{}
}
article := Article{
article := Article {
title: title
text: text
}
@ -60,7 +61,7 @@ pub fn (mut app App) new_article() vweb.Result {
sql app.db {
insert article into Article
}
return app.vweb.redirect('/article/')
return app.vweb.redirect('/')
}
pub fn (mut app App) articles() {