From 856270cac2b23494e5418bcc8caa6fc7f393ead1 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Thu, 23 Jun 2022 00:11:59 +0300 Subject: [PATCH] tutorials: restore the old tutorials/building_a_simple_web_blog_with_vweb/ folder. --- .../code/blog/article.ve | 13 --- .../code/blog/blog.ve | 80 ------------------ .../README.md | 0 .../code/blog/.gitignore | 0 .../code/blog/article.v | 0 .../code/blog/blog.sqlite | 0 .../code/blog/blog.v | 0 .../code/blog/index.html | 0 .../code/blog/new.html | 0 .../img/articles1.png | Bin .../img/articles_json.png | Bin .../img/hello.png | Bin .../img/hello_html.png | Bin .../img/time.png | Bin 14 files changed, 93 deletions(-) delete mode 100644 tutorials/Building a simple web blog with vweb/code/blog/article.ve delete mode 100644 tutorials/Building a simple web blog with vweb/code/blog/blog.ve rename tutorials/{Building a simple web blog with vweb => building_a_simple_web_blog_with_vweb}/README.md (100%) rename tutorials/{Building a simple web blog with vweb => building_a_simple_web_blog_with_vweb}/code/blog/.gitignore (100%) rename tutorials/{Building a simple web blog with vweb => building_a_simple_web_blog_with_vweb}/code/blog/article.v (100%) rename tutorials/{Building a simple web blog with vweb => building_a_simple_web_blog_with_vweb}/code/blog/blog.sqlite (100%) rename tutorials/{Building a simple web blog with vweb => building_a_simple_web_blog_with_vweb}/code/blog/blog.v (100%) rename tutorials/{Building a simple web blog with vweb => building_a_simple_web_blog_with_vweb}/code/blog/index.html (100%) rename tutorials/{Building a simple web blog with vweb => building_a_simple_web_blog_with_vweb}/code/blog/new.html (100%) rename tutorials/{Building a simple web blog with vweb => building_a_simple_web_blog_with_vweb}/img/articles1.png (100%) rename tutorials/{Building a simple web blog with vweb => building_a_simple_web_blog_with_vweb}/img/articles_json.png (100%) rename tutorials/{Building a simple web blog with vweb => building_a_simple_web_blog_with_vweb}/img/hello.png (100%) rename tutorials/{Building a simple web blog with vweb => building_a_simple_web_blog_with_vweb}/img/hello_html.png (100%) rename tutorials/{Building a simple web blog with vweb => building_a_simple_web_blog_with_vweb}/img/time.png (100%) diff --git a/tutorials/Building a simple web blog with vweb/code/blog/article.ve b/tutorials/Building a simple web blog with vweb/code/blog/article.ve deleted file mode 100644 index f12753241f..0000000000 --- a/tutorials/Building a simple web blog with vweb/code/blog/article.ve +++ /dev/null @@ -1,13 +0,0 @@ -module main - -struct Article { - id int [primary; sql: serial] - title string - text string -} - -pub fn (app &App) find_all_articles() []Article { - return sql app.db { - select from Article - } -} diff --git a/tutorials/Building a simple web blog with vweb/code/blog/blog.ve b/tutorials/Building a simple web blog with vweb/code/blog/blog.ve deleted file mode 100644 index d6284ce55e..0000000000 --- a/tutorials/Building a simple web blog with vweb/code/blog/blog.ve +++ /dev/null @@ -1,80 +0,0 @@ -module main - -import vweb -import time -import sqlite -import json - -struct App { - vweb.Context -pub mut: - db sqlite.DB - user_id string -} - -fn main() { - mut app := App{ - db: sqlite.connect('blog.db') or { panic(err) } - } - sql app.db { - create table Article - } - vweb.run(app, 8081) -} - -/* -pub fn (mut app App) index_text() vweb.Result { - app.vweb.text('Hello, world from vweb!') - return vweb.Result{} -} - -pub fn (app &App) index_html() vweb.Result { - message := 'Hello, world from Vweb!' - return $vweb.html() -} -*/ -['/index'] -pub fn (app &App) index() vweb.Result { - articles := app.find_all_articles() - return $vweb.html() -} - -pub fn (mut app App) before_request() { - app.user_id = app.get_cookie('id') or { '0' } -} - -['/new'] -pub fn (mut app App) new() vweb.Result { - return $vweb.html() -} - -['/new_article'; post] -pub fn (mut app App) new_article() vweb.Result { - title := app.form['title'] - text := app.form['text'] - if title == '' || text == '' { - return app.text('Empty text/title') - } - article := Article{ - title: title - text: text - } - println('posting article') - println(article) - sql app.db { - insert article into Article - } - - return app.redirect('/') -} - -['/articles'; get] -pub fn (mut app App) articles() vweb.Result { - articles := app.find_all_articles() - json_result := json.encode(articles) - return app.json(json_result) -} - -fn (mut app App) time() { - app.text(time.now().format()) -} diff --git a/tutorials/Building a simple web blog with vweb/README.md b/tutorials/building_a_simple_web_blog_with_vweb/README.md similarity index 100% rename from tutorials/Building a simple web blog with vweb/README.md rename to tutorials/building_a_simple_web_blog_with_vweb/README.md diff --git a/tutorials/Building a simple web blog with vweb/code/blog/.gitignore b/tutorials/building_a_simple_web_blog_with_vweb/code/blog/.gitignore similarity index 100% rename from tutorials/Building a simple web blog with vweb/code/blog/.gitignore rename to tutorials/building_a_simple_web_blog_with_vweb/code/blog/.gitignore diff --git a/tutorials/Building a simple web blog with vweb/code/blog/article.v b/tutorials/building_a_simple_web_blog_with_vweb/code/blog/article.v similarity index 100% rename from tutorials/Building a simple web blog with vweb/code/blog/article.v rename to tutorials/building_a_simple_web_blog_with_vweb/code/blog/article.v diff --git a/tutorials/Building a simple web blog with vweb/code/blog/blog.sqlite b/tutorials/building_a_simple_web_blog_with_vweb/code/blog/blog.sqlite similarity index 100% rename from tutorials/Building a simple web blog with vweb/code/blog/blog.sqlite rename to tutorials/building_a_simple_web_blog_with_vweb/code/blog/blog.sqlite diff --git a/tutorials/Building a simple web blog with vweb/code/blog/blog.v b/tutorials/building_a_simple_web_blog_with_vweb/code/blog/blog.v similarity index 100% rename from tutorials/Building a simple web blog with vweb/code/blog/blog.v rename to tutorials/building_a_simple_web_blog_with_vweb/code/blog/blog.v diff --git a/tutorials/Building a simple web blog with vweb/code/blog/index.html b/tutorials/building_a_simple_web_blog_with_vweb/code/blog/index.html similarity index 100% rename from tutorials/Building a simple web blog with vweb/code/blog/index.html rename to tutorials/building_a_simple_web_blog_with_vweb/code/blog/index.html diff --git a/tutorials/Building a simple web blog with vweb/code/blog/new.html b/tutorials/building_a_simple_web_blog_with_vweb/code/blog/new.html similarity index 100% rename from tutorials/Building a simple web blog with vweb/code/blog/new.html rename to tutorials/building_a_simple_web_blog_with_vweb/code/blog/new.html diff --git a/tutorials/Building a simple web blog with vweb/img/articles1.png b/tutorials/building_a_simple_web_blog_with_vweb/img/articles1.png similarity index 100% rename from tutorials/Building a simple web blog with vweb/img/articles1.png rename to tutorials/building_a_simple_web_blog_with_vweb/img/articles1.png diff --git a/tutorials/Building a simple web blog with vweb/img/articles_json.png b/tutorials/building_a_simple_web_blog_with_vweb/img/articles_json.png similarity index 100% rename from tutorials/Building a simple web blog with vweb/img/articles_json.png rename to tutorials/building_a_simple_web_blog_with_vweb/img/articles_json.png diff --git a/tutorials/Building a simple web blog with vweb/img/hello.png b/tutorials/building_a_simple_web_blog_with_vweb/img/hello.png similarity index 100% rename from tutorials/Building a simple web blog with vweb/img/hello.png rename to tutorials/building_a_simple_web_blog_with_vweb/img/hello.png diff --git a/tutorials/Building a simple web blog with vweb/img/hello_html.png b/tutorials/building_a_simple_web_blog_with_vweb/img/hello_html.png similarity index 100% rename from tutorials/Building a simple web blog with vweb/img/hello_html.png rename to tutorials/building_a_simple_web_blog_with_vweb/img/hello_html.png diff --git a/tutorials/Building a simple web blog with vweb/img/time.png b/tutorials/building_a_simple_web_blog_with_vweb/img/time.png similarity index 100% rename from tutorials/Building a simple web blog with vweb/img/time.png rename to tutorials/building_a_simple_web_blog_with_vweb/img/time.png