Skip to content

Commit c4a6791

Browse files
authored
examples, readme: fix typos (#18994)
1 parent 490a014 commit c4a6791

4 files changed

Lines changed: 248 additions & 232 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,11 @@ make
205205

206206
To bring IDE functions for the V programming languages to your editor, check out
207207
[v-analyzer](https://github.com/v-analyzer/v-analyzer). It provides a
208-
[VS code extension](https://marketplace.visualstudio.com/items?itemName=VOSCA.vscode-v-analyzer)
208+
[VS Code extension](https://marketplace.visualstudio.com/items?itemName=VOSCA.vscode-v-analyzer)
209209
and language server capabilities for other editors.
210210

211-
The plugin for JetBrains IDEs (IntelliJ, CLion, GoLand, etc.) also offer a great development
212-
experience with V. You can check out all the features it [its documentation](https://plugins.jetbrains.com/plugin/20287-vlang/docs/syntax-highlighting.html).
211+
The plugin for JetBrains IDEs (IntelliJ, CLion, GoLand, etc.) also offers a great development
212+
experience with V. You can find all features in [its documentation](https://plugins.jetbrains.com/plugin/20287-vlang/docs/syntax-highlighting.html).
213213

214214
Other Plugins:
215215

examples/js_dom_cube/README.md

Lines changed: 94 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,150 +1,148 @@
1-
# Serve
1+
# JS DOM Cube
22

3-
This project has a no dependence serve in `./server.js` path.
4-
That can be run with `node` command after build.
3+
## Compiling
54

6-
or just run: `npm run start`
5+
```
6+
v -b js_browser examples/js_dom_cube/cube.js.v
7+
```
8+
9+
Then you can open `index.html` in your favorite browser.
10+
11+
## Serve Examples
712

8-
To install node, you can access node [download page](https://nodejs.org/en/download/)
9-
or [package manager](https://nodejs.org/en/download/package-manager)
10-
Drawing with mouse events using DOM API. Adopted from MDN examples.
13+
### JS Server
14+
15+
> **NOTE**\
16+
> The JS server example in the following steps requires Node.js.
17+
> To install Node, please refer to the [download page](https://nodejs.org/en/download/)
18+
> or the installation via your operating systems [package manager](https://nodejs.org/en/download/package-manager).
19+
20+
Initialize the example as a Node project
1121

12-
# Compiling
1322
```
14-
v -b js_browser examples/js_dom_cube/cube.js.v
23+
cd examples/js_dom_cube/
24+
npm init -y
1525
```
1626

17-
Drawing with mouse events using DOM API. Adopted from MDN examples.
18-
Then you can open `index.html` with your favourite browser.
19-
# Serve examples
27+
Add a `start` and `build` script to the generated `./package.json` file.
2028

21-
### JS server
22-
After run `npm init -y` code and genared `./package.json`
23-
You can put `start` and `build` at script in jason leaf.
24-
`path './package.json'`
2529
```json
2630
"scripts": {
31+
...
2732
"start": "npm run build && node server.js",
28-
"build":"v -b js_browser cube.js.v"
33+
"build": "v -b js_browser cube.js.v"
2934
},
30-
3135
```
32-
here is the pure javascript server code
33-
`path './server.js'`
36+
37+
Below is an example of a Node.js server without external dependencies.
38+
You can use it for `./server.js`.
3439

3540
```javascript
36-
const http = require("http");
37-
const fs = require("fs");
41+
const http = require('http');
42+
const fs = require('fs');
3843
var path = require('path');
3944

40-
const host = "localhost";
45+
const host = 'localhost';
4146
const port = 3000;
4247

4348
const reqListener = function (req, res) {
44-
console.log('[route] - ', req.url);
45-
46-
var filePath = '.' + req.url;
47-
if (filePath == './') {
48-
filePath = './index.html';
49-
}
50-
51-
var extname = String(path.extname(filePath)).toLowerCase();
52-
var mimeTypes = {
53-
'.html': 'text/html',
54-
'.js': 'text/javascript',
55-
'.css': 'text/css',
56-
'.json': 'application/json',
57-
'.png': 'image/png',
58-
'.jpg': 'image/jpg',
59-
'.gif': 'image/gif',
60-
'.svg': 'image/svg+xml',
61-
'.wav': 'audio/wav',
62-
'.mp4': 'video/mp4',
63-
'.woff': 'application/font-woff',
64-
'.ttf': 'application/font-ttf',
65-
'.eot': 'application/vnd.ms-fontobject',
66-
'.otf': 'application/font-otf',
67-
'.wasm': 'application/wasm'
68-
};
69-
70-
var contentType = mimeTypes[extname] || 'application/octet-stream';
71-
72-
fs.readFile(filePath, function(error, content) {
73-
if (error) {
74-
if(error.code == 'ENOENT') {
75-
fs.readFile('./404.html', function(error, content) {
76-
res.writeHead(404, { 'Content-Type': 'text/html' });
77-
res.end(content, 'utf-8');
78-
});
79-
}
80-
else {
81-
res.writeHead(500);
82-
res.end('Sorry, check with the site admin for error: '+error.code+' ..\n');
83-
}
84-
}
85-
else {
86-
res.writeHead(200, { 'Content-Type': contentType });
87-
res.end(content, 'utf-8');
88-
}
89-
});
49+
console.log('[route] - ', req.url);
50+
51+
var filePath = '.' + req.url;
52+
if (filePath == './') {
53+
filePath = './index.html';
54+
}
55+
56+
var extname = String(path.extname(filePath)).toLowerCase();
57+
var mimeTypes = {
58+
'.html': 'text/html',
59+
'.js': 'text/javascript',
60+
'.css': 'text/css',
61+
'.json': 'application/json',
62+
'.png': 'image/png',
63+
'.jpg': 'image/jpg',
64+
'.gif': 'image/gif',
65+
'.svg': 'image/svg+xml',
66+
'.wav': 'audio/wav',
67+
'.mp4': 'video/mp4',
68+
'.woff': 'application/font-woff',
69+
'.ttf': 'application/font-ttf',
70+
'.eot': 'application/vnd.ms-fontobject',
71+
'.otf': 'application/font-otf',
72+
'.wasm': 'application/wasm',
73+
};
74+
75+
var contentType = mimeTypes[extname] || 'application/octet-stream';
76+
77+
fs.readFile(filePath, function (error, content) {
78+
if (error) {
79+
if (error.code == 'ENOENT') {
80+
fs.readFile('./404.html', function (error, content) {
81+
res.writeHead(404, { 'Content-Type': 'text/html' });
82+
res.end(content, 'utf-8');
83+
});
84+
} else {
85+
res.writeHead(500);
86+
res.end('Sorry, check with the site admin for error: ' + error.code + ' ..\n');
87+
}
88+
} else {
89+
res.writeHead(200, { 'Content-Type': contentType });
90+
res.end(content, 'utf-8');
91+
}
92+
});
9093
};
9194

9295
const server = http.createServer(reqListener);
9396
server.listen(port, host, () => {
94-
console.log(`Server is running on http://${host}:${port}`);
97+
console.log(`Server is running on http://${host}:${port}`);
9598
});
96-
9799
```
98100

99-
This project has a no dependence serve in `./server.js` path.
100-
That can be run with `node` command after build.
101-
102-
or just run: `npm run start`
101+
Now you can build and run the project with the added scripts.
103102

104-
To install node, you can access node [download page](https://nodejs.org/en/download/)
105-
or [package manager](https://nodejs.org/en/download/package-manager)
106-
107-
```
108-
$ cd examples/js_dom_draw/
109-
$ npm run build
103+
```sh
104+
npm run build
105+
npm run start
110106
```
111107

112-
113108
### V server
114-
```v ignore
109+
110+
The example below uses `vweb` to serve the project.
111+
112+
```v
115113
module main
116114
117115
import vweb
118116
import os
119117
120118
const (
121-
http_port = 3001
119+
http_port = 3001
122120
)
123121
124122
struct App {
125-
vweb.Context
123+
vweb.Context
126124
}
127125
128126
fn main() {
129-
vweb.run(new_app(), http_port)
127+
vweb.run(new_app(), http_port)
130128
}
131129
132130
pub fn (mut app App) before_request() {
133-
// This build server json files
134-
os.execute_or_panic('v -b js_browser cube.js.v ')
131+
// Build the cube.js javascript file
132+
os.execute_or_panic('v -b js_browser cube.js.v ')
135133
}
136134
137135
fn new_app() &App {
138-
mut app := &App{}
139-
app.serve_static('/favicon.ico', 'favicon.ico')
140-
app.serve_static('/cube.js', 'cube.js')
141-
app.mount_static_folder_at(os.resource_abs_path('.'), '/')
142-
return app
136+
mut app := &App{}
137+
app.serve_static('/favicon.ico', 'favicon.ico')
138+
app.serve_static('/cube.js', 'cube.js')
139+
app.mount_static_folder_at(os.resource_abs_path('.'), '/')
140+
return app
143141
}
144142
145143
['/'; get]
146144
pub fn (mut app App) controller_get_all_task() vweb.Result {
147-
file :=os.read_file('./index.html') or { panic(err) }
148-
return app.html(file)
145+
file := os.read_file('./index.html') or { panic(err) }
146+
return app.html(file)
149147
}
150-
```
148+
```

0 commit comments

Comments
 (0)