v2 / examples / templates / templates.v
43 lines · 37 sloc · 741 bytes · e2e5cf8db56f3562c7baa735061690be936bdf3e
Raw
1module main
2
3import os
4import json
5
6pub struct SiteConfig {
7pub mut:
8 name string
9 url string
10 branch string = 'default' // means is the default branch
11 pull bool
12 cat SiteCat
13 alias string
14 path_code string
15 domains []string
16 descr string
17}
18
19pub enum SiteCat {
20 wiki
21 data
22 web
23}
24
25fn data_load() []SiteConfig {
26 data := os.read_file(os.resource_abs_path('data.json')) or { panic(err) }
27 a := json.decode([]SiteConfig, data) or { panic(err) }
28 return a
29}
30
31fn filled_in_template() string {
32 port_str := '80'
33 sites := data_load()
34 return $tmpl('template.md')
35}
36
37fn main() {
38 // A NICE test how to work with the json module
39 // data := data_get()
40 // data_dump(data)
41 b := filled_in_template()
42 println(b)
43}
44