use embedded base.html

This commit is contained in:
Niko Abeler 2022-07-23 09:11:25 +02:00
parent 861267c342
commit fc347f9f29
4 changed files with 22 additions and 5 deletions

15
embed/base.html Normal file
View File

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{title}}</title>
</head>
<body>
{{content}}
</body>
</html>

View File

@ -20,7 +20,7 @@ func TestRendererUsesBaseTemplate(t *testing.T) {
user := getTestUser() user := getTestUser()
post, _ := user.CreateNewPost("testpost") post, _ := user.CreateNewPost("testpost")
result, _ := kiss.RenderPost(post) result, _ := kiss.RenderPost(post)
if !strings.Contains(result, "<html>") { if !strings.Contains(result, "<html") {
t.Error("Base template not used. Got: " + result) t.Error("Base template not used. Got: " + result)
} }
} }

View File

@ -1,11 +1,15 @@
package kiss package kiss
import ( import (
_ "embed"
"fmt" "fmt"
"os" "os"
"path" "path"
) )
//go:embed embed/base.html
var base_template string
type Repository struct { type Repository struct {
name string name string
} }
@ -60,8 +64,6 @@ func (repo Repository) CreateUser(name string) (User, error) {
// create public folder // create public folder
os.Mkdir(path.Join(user_dir, "public"), 0755) os.Mkdir(path.Join(user_dir, "public"), 0755)
base_template := "<html><body><{{content}}/body></html>"
// create Meta files // create Meta files
os.WriteFile(path.Join(user_dir, "meta", "VERSION"), []byte("0.0.1"), 0644) os.WriteFile(path.Join(user_dir, "meta", "VERSION"), []byte("0.0.1"), 0644)
os.WriteFile(path.Join(user_dir, "meta", "base.html"), []byte(base_template), 0644) os.WriteFile(path.Join(user_dir, "meta", "base.html"), []byte(base_template), 0644)

View File

@ -31,7 +31,7 @@ func TestCanCreateRepository(t *testing.T) {
repoName := testRepoName() repoName := testRepoName()
_, err := kiss.CreateRepository(repoName) _, err := kiss.CreateRepository(repoName)
if err != nil { if err != nil {
t.Error("Error creating repository: ", err) t.Error("Error creating repository: ", err.Error())
} }
} }
@ -116,7 +116,7 @@ func TestCanOpenRepository(t *testing.T) {
// Open the repository // Open the repository
repo2, err := kiss.OpenRepository(repoName) repo2, err := kiss.OpenRepository(repoName)
if err != nil { if err != nil {
t.Error("Error opening repository: ", err) t.Error("Error opening repository: ", err.Error())
} }
if repo2.Dir() != repo.Dir() { if repo2.Dir() != repo.Dir() {
t.Error("Repository directories do not match") t.Error("Repository directories do not match")