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