fmt: remove space in front of ? and ! (#14366)

Daniel Däschle 2022-05-13 05:56:21 +02:00 committed by Jef Roosens
parent 0866c73f4b
commit 54bbc00493
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
324 changed files with 1865 additions and 1879 deletions

View File

@ -5,6 +5,7 @@ Hello,
In this guide, we'll build a simple web blog in V.
The benefits of using V for web:
- A safe, fast, language with the development agility of Python or Ruby and
the performance of C.
- Zero dependencies: everything you need for web development comes with the language
@ -15,11 +16,10 @@ in a 1 MB package.
is enough.
- Fast development without any boilerplate.
*Please note that V and Vweb are at a very early stage and are changing rapidly.*
_Please note that V and Vweb are at a very early stage and are changing rapidly._
The code is available <a href='https://github.com/vlang/v/tree/master/tutorials/code/blog'>here</a>.
### Installing V
```
@ -32,17 +32,15 @@ sudo ./v symlink
Now V should be globally available on your system.
> On macOS use `v_macos.zip`, on Windows - `v_windows.zip`.
If you use a BSD system, Solaris, Android, or simply want to install V
from source, follow the simple instructions here:
https://github.com/vlang/v#installing-v-from-source
> If you use a BSD system, Solaris, Android, or simply want to install V
> from source, follow the simple instructions here:
> https://github.com/vlang/v#installing-v-from-source
### Install SQLite development dependency
If you don't have it already installed, look at the
[`sqlite` README](../../vlib/sqlite/README.md) for instructions.
### Creating a new Vweb project
V projects can be created anywhere and don't need to have a certain structure:
@ -94,7 +92,6 @@ with an MVC web framework, you can think of it as a controller. (Vweb is
not an MVC framework however.) It embeds the vweb Context object, that's why we get access
to methods like `.text()`.
As you can see, there are no routing rules. The `index()` action handles the `/` request by default.
Vweb often uses convention over configuration and adding a new action requires
no routing rules either:
@ -109,7 +106,6 @@ fn (mut app App) time() vweb.Result {
}
```
<img width=662 src="https://github.com/vlang/v/blob/master/tutorials/building_a_simple_web_blog_with_vweb/img/time.png?raw=true">
> TIP: run the following command to live-reload the server: `v watch run blog.v`
@ -117,7 +113,6 @@ fn (mut app App) time() vweb.Result {
The `.text(string)` method returns a plain text document with the provided
text, which isn't frequently used in websites.
### HTML View
Let's return an HTML view instead. Create `index.html` in the same directory:
@ -129,8 +124,8 @@ Let's return an HTML view instead. Create `index.html` in the same directory:
</head>
<body>
<b>@message</b>
<br>
<img src='https://vlang.io/img/v-logo.png' width=100>
<br />
<img src="https://vlang.io/img/v-logo.png" width="100" />
</body>
</html>
```
@ -176,7 +171,6 @@ into a single binary file together with the web application itself.
- All errors in the templates are guaranteed to be caught during compilation.
### Fetching data with V ORM
Now let's display some articles!
@ -184,7 +178,6 @@ Now let's display some articles!
We'll be using V's builtin ORM and a SQLite database.
(V ORM will also support MySQL, Postgre, and SQL Server soon.)
Add a SQLite handle to `App`:
```v oksyntax
@ -199,14 +192,11 @@ pub mut:
}
```
In `fn main()` we'll connect to a database.
Code in the `main()` function is run only once during app's startup, so we are going
to have one DB connection for all requests. This improves the performance of the web application,
since a DB connection doesn't have to be set up for each request.
```v oksyntax
// blog.v
fn main() {
@ -268,14 +258,13 @@ pub fn (app &App) index() vweb.Result {
}
```
Finally, let's update our view:
```html
<body>
@for article in articles
<div>
<b>@article.title</b> <br>
<b>@article.title</b> <br />
@article.text
</div>
@end
@ -323,7 +312,6 @@ article := app.retrieve_article(10) or {
}
```
### Adding new articles
Create `new.html`:
@ -334,10 +322,10 @@ Create `new.html`:
<title>V Blog</title>
</head>
<body>
<form action='/new_article' method='post'>
<input type='text' placeholder='Title' name='title'> <br>
<textarea placeholder='Text' name='text'></textarea>
<input type='submit'>
<form action="/new_article" method="post">
<input type="text" placeholder="Title" name="title" /> <br />
<textarea placeholder="Text" name="text"></textarea>
<input type="submit" />
</form>
</body>
</html>
@ -373,7 +361,7 @@ not necessary).
We need to update `index.html` to add a link to the "new article" page:
```html
<a href='/new'>New article</a>
<a href="/new">New article</a>
```
Next we need to add the HTML endpoint to our code like we did with `index.html`:
@ -387,7 +375,6 @@ pub fn (mut app App) new() vweb.Result {
Re-running this code will now allow us to add new posts to our blog endpoint
### JSON endpoints
This tutorial used the traditional server-side rendering. If you prefer
@ -406,10 +393,10 @@ pub fn (mut app App) articles() vweb.Result {
}
```
<img width=662 src="https://github.com/vlang/v/blob/master/tutorials/building_a_simple_web_blog_with_vweb/img/articles_json.png?raw=true">
### Persistent data
If one wants to persist data they need to use a file instead of memory SQLite Database.
Replace the db setup code with this instead:
@ -422,7 +409,6 @@ If the database file doesn't exist it will create it. The second command will
create the table `Article` if none exists already. Now every time the
app is run you will see the articles created from the previous executions
To be continued...
For an example of a more sophisticated web app written in V, check out Vorum: https://github.com/vlang/vorum

View File

@ -6,7 +6,6 @@ from a terminal in an easy and structured manner.
The module provides an easy way to prompt the user for
questions or even make a REPL or an embedded console.
# Usage:
```v
@ -18,6 +17,7 @@ println(answer)
```
or just:
```v
import readline { read_line }

View File

@ -1,4 +1,4 @@
vlib/v/checker/tests/go_wait_or.vv:11:17: error: unexpected `?`, the function `wait` does neither return an optional nor a result
vlib/v/checker/tests/go_wait_or.vv:11:16: error: unexpected `?`, the function `wait` does neither return an optional nor a result
9 | go d(1)
10 | ]
11 | r := tg.wait()?
@ -19,7 +19,7 @@ vlib/v/checker/tests/go_wait_or.vv:19:13: error: unexpected `or` block, the func
| ~~~~~~~~~~~~~~~~~~~~~~~
20 | tg2[0].wait()?
21 | tg3 := [
vlib/v/checker/tests/go_wait_or.vv:20:16: error: unexpected `?`, the function `wait` does neither return an optional nor a result
vlib/v/checker/tests/go_wait_or.vv:20:15: error: unexpected `?`, the function `wait` does neither return an optional nor a result
18 | ]
19 | tg2.wait() or { panic('problem') }
20 | tg2[0].wait()?

View File

@ -1,11 +1,11 @@
vlib/v/checker/tests/optional_propagate_nested.vv:10:19: error: to propagate the optional call, `xx_prop` must return an optional
vlib/v/checker/tests/optional_propagate_nested.vv:10:18: error: to propagate the optional call, `xx_prop` must return an optional
8 |
9 | fn xx_prop() string {
10 | s := ret(raise()?)
| ^
11 | return s
12 | }
vlib/v/checker/tests/optional_propagate_nested.vv:28:22: error: to propagate the optional call, `aa_propagate` must return an optional
vlib/v/checker/tests/optional_propagate_nested.vv:28:21: error: to propagate the optional call, `aa_propagate` must return an optional
26 |
27 | fn (mut s St) aa_propagate() {
28 | f := retf(s.raise()?)

View File

@ -1,4 +1,4 @@
vlib/v/checker/tests/propagate_option_with_result_err.vv:6:8: error: to propagate an option, the call must also return an optional type
vlib/v/checker/tests/propagate_option_with_result_err.vv:6:7: error: to propagate an option, the call must also return an optional type
4 |
5 | fn bar() ?string {
6 | foo()?

View File

@ -1,4 +1,4 @@
vlib/v/parser/tests/defer_propagate.vv:9:15: error: error propagation not allowed inside `defer` blocks
vlib/v/parser/tests/defer_propagate.vv:9:14: error: error propagation not allowed inside `defer` blocks
7 | mut a := 0
8 | defer {
9 | a = test1()?

View File

@ -1,4 +1,4 @@
vlib/v/parser/tests/defer_propagate2.vv:16:13: error: error propagation not allowed inside `defer` blocks
vlib/v/parser/tests/defer_propagate2.vv:16:12: error: error propagation not allowed inside `defer` blocks
14 | dump(s.x)
15 | defer {
16 | s.close()?