-
-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathutils.v
More file actions
70 lines (54 loc) · 1.54 KB
/
utils.v
File metadata and controls
70 lines (54 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
module main
import time
import math
import os
import veb
pub fn (mut app App) running_since() string {
duration := time.now().unix() - app.started_at
seconds_in_hour := 60 * 60
days := int(math.floor(f64(duration) / f64(seconds_in_hour * 24)))
hours := int(math.fmod(math.floor(f64(duration) / f64(seconds_in_hour)), 24))
minutes := int(math.floor(f64(duration) / 60.0)) % 60
seconds := duration % 60
return '${days} days ${hours} hours ${minutes} minutes and ${seconds} seconds'
}
pub fn (mut ctx Context) make_path(branch_name string, i int) string {
if i == 0 {
return ctx.path_split[..i + 1].join('/')
}
mut s := ctx.path_split[0]
s += '/tree/${branch_name}/'
s += ctx.path_split[1..i + 1].join('/')
return s
}
fn create_directory_if_not_exists(path string) {
if !os.exists(path) {
os.mkdir(path) or { panic('cannot create ${path} directory') }
}
}
fn calculate_pages(count int, per_page int) int {
if count == 0 {
return 0
}
return int(math.ceil(f32(count) / f32(per_page))) - 1
}
fn generate_prev_next_pages(page int) (int, int) {
prev_page := if page > 0 { page - 1 } else { 0 }
next_page := page + 1
return prev_page, next_page
}
fn check_first_page(page int) bool {
return page == 0
}
fn check_last_page(total int, offset int, per_page int) bool {
return (total - offset) < per_page
}
const is_dev = true
fn css2(s string) veb.RawHtml {
if is_dev {
return '<link href="http://localhost:8000/${s}" rel="stylesheet" type="text/css">'
}
else {
return '<link href="/static/${s}" rel="stylesheet" type="text/css">'
}
}