docs: fix most of the examples (ensure they at least have a valid syntax)

pull/6980/head
Delyan Angelov 2020-11-27 13:03:32 +02:00
parent e6116c47be
commit 7cd9530006
4 changed files with 21 additions and 15 deletions

View File

@ -96,6 +96,7 @@ Vweb often uses convention over configuration and adding a new action requires
no routing rules either:
```v oksyntax
import vweb
fn (mut app App) time() vweb.Result {
app.vweb.text(time.now().format())
return vweb.Result{}
@ -206,6 +207,7 @@ Add a SQLite handle to `App`:
```v oksyntax
import sqlite
import vweb
struct App {
pub mut:
@ -332,6 +334,7 @@ Create `new.html`:
```
```v oksyntax
import vweb
pub fn (mut app App) new_article() vweb.Result {
title := app.vweb.form['title']
text := app.vweb.form['text']
@ -370,6 +373,7 @@ to render everything on the client or need an API, creating JSON endpoints
in V is very simple:
```v oksyntax
import vweb
pub fn (mut app App) articles() vweb.Result {
articles := app.find_all_articles()
app.vweb.json(json.encode(articles))

View File

@ -30,7 +30,7 @@ A module to provide eventing capabilities using pub/sub.
The function given to `subscribe`, `subscribe_method` and `subscribe_once` must match this:
```v oksyntax
fn(receiver voidptr, args voidptr, sender voidptr) {
fn cb(receiver voidptr, args voidptr, sender voidptr) {
}
// Since V can map structs to voidptr, this also works
@ -40,7 +40,7 @@ struct ClickEvent {
}
// Example case where publisher sends ClickEvent as args.
fn onPress(receiver voidptr, e &ClickEvent, sender voidptr){
fn on_press(receiver voidptr, e &ClickEvent, sender voidptr){
println(e.x)
//your code here...
}
@ -48,7 +48,8 @@ fn onPress(receiver voidptr, e &ClickEvent, sender voidptr){
## Usage
For **usage across modules** [check the example](https://github.com/vlang/v/tree/master/examples/eventbus).
For **usage across modules**
[check the example](https://github.com/vlang/v/tree/master/examples/eventbus).
_Note: As a general rule, you will need to **subscribe before publishing**._

View File

@ -410,7 +410,7 @@ pub fn new() RE
pub fn new_by_size(mult int) RE
```
After a base initializer is used, the regex expression must be compiled with:
```v oksyntax
```v ignore
// compile compiles the REgex returning an error if the compilation fails
pub fn (re mut RE) compile_opt(in_txt string) ?
```
@ -419,7 +419,7 @@ pub fn (re mut RE) compile_opt(in_txt string) ?
These are the operative functions
```v oksyntax
```v ignore
// match_string try to match the input string, return start and end index if found else start is -1
pub fn (re mut RE) match_string(in_txt string) (int,int)

View File

@ -41,39 +41,40 @@ This simple program covers many of the principal aspects of the `term ` module.
Here are some functions you should be aware of in the `term `module:
```v oksyntax
import term
// returns the height and the width of the terminal
term.get_terminal_size() (width, height)
width, height := term.get_terminal_size()
// returns the string as green text to be printed on stdout
term.ok_message(string)
term.ok_message('cool')
// returns the string as red text to be printed on stdout
term.fail_message(string)
term.fail_message('oh, no')
// returns the string as yellow text to be printed on stdout
term.warning_message(string)
term.warning_message('be warned')
//clears the entire terminal and leaves a blank one
term.clear()
// colors the output of the output, the available colors are: black,blue,yellow,green,cyan,gray,bright_blue,bright_green,bright_red,bright_black,bright_cyan
term.<color>(string)
term.yellow('submarine')
// transforms the given string into bold text
term.bold(string)
term.bold('and beautiful')
// puts a strikethrough into the given string
term.strikethrough(string)
term.strikethrough('the core of the problem')
// underlines the given string
term.underline(string)
term.underline('important')
// colors the background of the output following the given color
// the available colors are: black, blue, yellow, green, cyan, gray
term.bg_<color>(string)
term.bg_green('field')
// sets the position of the cursor at a given place in the terminal
term.set_cursor_position(term.Coord)
term.set_cursor_position(x: 5, y: 10)
// moves the cursor up
term.cursor_up()