- {{ template "components/role" .TestRole }} {{ template "components/role"
- .TestRole2 }} {{ template "components/role" .TestRole3 }}
+
+
Multi
+ {{ range $_, $r := .Category1 }} {{ template "components/role" $r }} {{ end
+ }}
-
- {{ template "components/role" .TestRole4 }} {{ template "components/role"
- .TestRole5 }} {{ template "components/role" .TestRole6 }}
+
+
Single
+ {{ range $_, $r := .Category2 }} {{ template "components/role" $r }} {{ end
+ }}
+
+
+
Bad
+ {{ range $_, $r := .Category3 }} {{ template "components/role" $r }} {{ end
+ }}
+
+
+
Hmm
+ {{ range $_, $r := .Category4 }} {{ template "components/role" $r }} {{ end
+ }}
diff --git a/testing/testing.go b/testing/testing.go
index 71d4f82..cea9f71 100644
--- a/testing/testing.go
+++ b/testing/testing.go
@@ -38,13 +38,37 @@ func (t *TestingController) TestTemplate(c fiber.Ctx) error {
which := c.Params("which")
cat1 := fixtures.Category(fixtures.CategoryMulti)
cat2 := fixtures.Category(fixtures.CategorySingle)
+ cat3 := fixtures.Category(fixtures.CategoryMulti)
+ cat4 := fixtures.Category(fixtures.CategorySingle)
return c.Render("tests/"+which, fiber.Map{
- "TestRole": components.Role(cat1, &fixtures.RoleWithDarkColor, false),
- "TestRole2": components.Role(cat1, &fixtures.RoleWithDarkMediumColor, false),
- "TestRole3": components.Role(cat1, &fixtures.RoleWithLightColor, true),
- "TestRole4": components.Role(cat1, &fixtures.RoleWithDarkColor, false),
- "TestRole5": components.Role(cat2, &fixtures.RoleWithLightColor, true),
- "TestRole6": components.Role(cat1, &fixtures.RoleWithLightMediumColor, false),
+ // multi
+ "Category1": []components.RoleTemplateData{
+ components.Role(cat1, &fixtures.RoleWithDarkColor, true, true),
+ components.Role(cat1, &fixtures.RoleWithDarkMediumColor, true, true),
+ components.Role(cat1, &fixtures.RoleWithLightMediumColor, true, true),
+ components.Role(cat1, &fixtures.RoleWithLightColor, true, true),
+ },
+ // single
+ "Category2": []components.RoleTemplateData{
+ components.Role(cat2, &fixtures.RoleWithDarkColor, true, true),
+ components.Role(cat2, &fixtures.RoleWithDarkMediumColor, true, true),
+ components.Role(cat2, &fixtures.RoleWithLightMediumColor, true, true),
+ components.Role(cat2, &fixtures.RoleWithLightColor, true, true),
+ },
+ // unsafe
+ "Category3": []components.RoleTemplateData{
+ components.Role(cat3, &fixtures.RoleWithDarkColor, true, false),
+ components.Role(cat3, &fixtures.RoleWithDarkMediumColor, false, false),
+ components.Role(cat3, &fixtures.RoleWithLightMediumColor, false, false),
+ components.Role(cat3, &fixtures.RoleWithLightColor, true, false),
+ },
+ // unselected
+ "Category4": []components.RoleTemplateData{
+ components.Role(cat4, &fixtures.RoleWithDarkColor, true, true),
+ components.Role(cat4, &fixtures.RoleWithDarkMediumColor, false, true),
+ components.Role(cat4, &fixtures.RoleWithLightMediumColor, false, true),
+ components.Role(cat4, &fixtures.RoleWithLightColor, false, true),
+ },
}, "layouts/main")
}
diff --git a/utils/template_fns.go b/utils/template_fns.go
index fbe7cc8..cd4ac8b 100644
--- a/utils/template_fns.go
+++ b/utils/template_fns.go
@@ -2,14 +2,20 @@ package utils
import (
"fmt"
-
- "git.sapphic.engineer/roleypoly/v4/types"
+ "html/template"
)
-func RoleInputID(c *types.Category, r *types.Role) string {
- return fmt.Sprintf("category-%s_role-%s", c.ID, r.ID)
+func RoleInputID(c string, r string) string {
+ return fmt.Sprintf("category-%s_role-%s", c, r)
}
-func RoleInputName(c *types.Category) string {
- return fmt.Sprintf("category_group_%s", c.ID)
+func RoleInputName(c string) string {
+ return fmt.Sprintf("category_group_%s", c)
+}
+
+func TemplateFuncs() template.FuncMap {
+ return template.FuncMap{
+ "roleInputID": RoleInputID,
+ "roleInputName": RoleInputName,
+ }
}
diff --git a/utils/template_fns_test.go b/utils/template_fns_test.go
index 00d7131..3b2fe41 100644
--- a/utils/template_fns_test.go
+++ b/utils/template_fns_test.go
@@ -3,15 +3,14 @@ package utils_test
import (
"testing"
- "git.sapphic.engineer/roleypoly/v4/types"
"git.sapphic.engineer/roleypoly/v4/utils"
"github.com/stretchr/testify/assert"
)
func TestRoleInputID(t *testing.T) {
- assert.Equal(t, "category-123_role-456", utils.RoleInputID(&types.Category{ID: "123"}, &types.Role{ID: "456"}))
+ assert.Equal(t, "category-123_role-456", utils.RoleInputID("123", "456"))
}
func TestRoleInputName(t *testing.T) {
- assert.Equal(t, "category_group_123", utils.RoleInputName(&types.Category{ID: "123"}))
+ assert.Equal(t, "category_group_123", utils.RoleInputName("123"))
}