43 lines
1.1 KiB
Go
Executable File
43 lines
1.1 KiB
Go
Executable File
package config
|
|
|
|
import (
|
|
"path/filepath"
|
|
|
|
"github.com/gofiber/template/html"
|
|
"github.com/markbates/pkger"
|
|
)
|
|
|
|
// TemplateConfig para la configuración del motor de plantillas
|
|
type TemplateConfig struct {
|
|
TemplateEngine *html.Engine
|
|
Path string `yaml:"path" env-default:"resources/views"`
|
|
Extension string `yaml:"extension" env-default:".html"`
|
|
}
|
|
|
|
// ViewConfig para la configuración de vistas
|
|
type ViewConfig struct {
|
|
Template TemplateConfig `yaml:"template"`
|
|
}
|
|
|
|
// Load carga la configuración de las vistas
|
|
func (v *ViewConfig) Load(path string) {
|
|
path = MakeDir(filepath.Join(path, v.Template.Path))
|
|
v.Template.TemplateEngine = html.NewFileSystem(pkger.Dir(path), v.Template.Extension)
|
|
}
|
|
|
|
// NewDict crea un mapa para usar en las plantillas
|
|
func NewDict(data ...interface{}) map[string]interface{} {
|
|
dict := make(map[string]interface{})
|
|
if len(data)%2 != 0 {
|
|
return dict // Retorna un mapa vacío si hay un número impar de argumentos
|
|
}
|
|
for i := 0; i < len(data); i += 2 {
|
|
key, ok := data[i].(string)
|
|
if !ok {
|
|
continue // Salta si la clave no es un string
|
|
}
|
|
dict[key] = data[i+1]
|
|
}
|
|
return dict
|
|
}
|