vss/internal/config/config.v

41 lines
767 B
Coq
Raw Normal View History

2022-09-22 09:47:20 +09:00
module config
import toml
2022-09-25 16:09:07 +09:00
// template_params list of field names to convert as_map
const template_params = ['title', 'description', 'base_url']
2022-09-22 09:47:20 +09:00
// Build settings for build
struct Build {
pub mut:
ignore_files []string
}
2022-09-25 16:09:07 +09:00
// Config general settings for vss
2022-09-22 09:47:20 +09:00
struct Config {
pub mut:
build Build
title string
description string
base_url string
}
2022-09-25 16:09:07 +09:00
// load
2022-09-22 09:47:20 +09:00
pub fn load(toml_text string) ?Config {
doc := toml.parse_text(toml_text)?
mut config := doc.reflect<Config>()
config.build = doc.value('build').reflect<Build>()
return config
}
// as_map for template.parse
2022-09-25 16:09:07 +09:00
pub fn (c Config) as_map() map[string]string {
mut mp := map[string]string{}
mp['title'] = c.title
mp['description'] = c.description
mp['base_url'] = c.base_url
return mp
}