...
This commit is contained in:
parent
2e8ec1735a
commit
c78761fe20
@ -1,6 +1,9 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"git.ourworld.tf/herocode/heroagent/pkg/servers/ui/routes" // Import the routes package
|
||||
"github.com/gofiber/fiber/v2"
|
||||
jetadapter "github.com/gofiber/template/jet/v2" // Aliased for clarity
|
||||
@ -16,17 +19,41 @@ func NewApp(config AppConfig) *fiber.App {
|
||||
// Initialize Jet template engine
|
||||
// Using OSFileSystemLoader to load templates from the filesystem.
|
||||
// The path is relative to where the application is run.
|
||||
// For development, InDevelopmentMode can be true to reload templates on each request.
|
||||
engine := jetadapter.New("./pkg/servers/ui/views", ".jet")
|
||||
// Get current working directory and construct absolute path to views
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
panic("Failed to get current working directory: " + err.Error())
|
||||
}
|
||||
viewsPath := filepath.Join(cwd, "pkg", "servers", "ui", "views")
|
||||
|
||||
// Enable template reloading for development.
|
||||
// Set to false or remove this line for production.
|
||||
// Validate that the views directory and key template files exist
|
||||
if _, err := os.Stat(viewsPath); os.IsNotExist(err) {
|
||||
panic("Views directory does not exist: " + viewsPath)
|
||||
}
|
||||
|
||||
// Check for key template files
|
||||
baseLayoutPath := filepath.Join(viewsPath, "layouts", "base.jet")
|
||||
dashboardPath := filepath.Join(viewsPath, "pages", "dashboard.jet")
|
||||
navbarPath := filepath.Join(viewsPath, "components", "navbar.jet")
|
||||
sidebarPath := filepath.Join(viewsPath, "components", "sidebar.jet")
|
||||
|
||||
requiredFiles := []string{baseLayoutPath, dashboardPath, navbarPath, sidebarPath}
|
||||
for _, filePath := range requiredFiles {
|
||||
if _, err := os.Stat(filePath); os.IsNotExist(err) {
|
||||
panic("Required template file does not exist: " + filePath)
|
||||
}
|
||||
}
|
||||
|
||||
// Log the views path for debugging
|
||||
println("Views directory found at:", viewsPath)
|
||||
println("All required template files exist")
|
||||
|
||||
// Create Fiber Jet adapter
|
||||
engine := jetadapter.New(viewsPath, ".jet")
|
||||
|
||||
// Enable template reloading for development
|
||||
engine.Reload(true)
|
||||
|
||||
// If you need to add custom functions or global variables to Jet:
|
||||
// engine.AddFunc("myCustomFunc", func(arg jet.Arguments) reflect.Value { ... })
|
||||
// engine.AddGlobal("myGlobalVar", "someValue")
|
||||
|
||||
// Create a new Fiber app with the configured Jet engine
|
||||
app := fiber.New(fiber.Config{
|
||||
Views: engine,
|
||||
|
@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{{ block "title" . }}My App{{ end }}</title>
|
||||
<title>{{ block title() }}My App{{ end }}</title>
|
||||
<!-- Bootstrap CSS from CDN -->
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.6/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-4Q6Gf2aSP4eDXB8Miphtr37CMZZQ5oXLH2yaXMJ2w8e2ZtHTl7GptT4jmndRuHDT" crossorigin="anonymous">
|
||||
<!-- Custom CSS -->
|
||||
|
@ -1,4 +1,4 @@
|
||||
{{ extends "/layouts/base.jet" }}
|
||||
{{ extends "layouts/base.jet" }}
|
||||
|
||||
{{ block title() }}Dashboard - HeroApp UI{{ end }}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
{{ extends "/layouts/base.jet" }}
|
||||
{{ extends "layouts/base.jet" }}
|
||||
|
||||
{{ block title() }}Login - HeroApp UI{{ end }}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
{{ extends "/layouts/base.jet" }}
|
||||
{{ extends "layouts/base.jet" }}
|
||||
|
||||
{{ block title() }}Process Manager - HeroApp UI{{ end }}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user