hlfw.ca

webbing

Download patch

ref: f16d4e23961408d0167dbf1818400bf554be56c3
parent: bf418d79ab6e22d1134882dfa7b938f4e5a941ba
author: halfwit <michaelmisch1985@gmail.com>
date: Fri Nov 8 10:34:51 PST 2019

Run plugins

--- a/plugins/doctor.go
+++ b/plugins/doctor.go
@@ -21,7 +21,7 @@
 
 func init() {
 	b := &router.Plugin{
-		Name:     "List doctors",
+		Name:     "doctors",
 		Run:      ListDocs,
 		Validate: ValidateListDocs,
 	}
--- a/plugins/specialties.go
+++ b/plugins/specialties.go
@@ -6,11 +6,11 @@
 )
 
 // ListServices - Bitmask to list services in native language
-const ListServices router.IncludeExtra = 3
+const ListServices router.IncludeExtra = 1
 
 func init() {
 	b := &router.Plugin{
-		Name:     "List specialties",
+		Name:     "specialties",
 		Run:      Specialties,
 		Validate: ValidateSpecialties,
 	}
--- a/router/pages.go
+++ b/router/pages.go
@@ -94,22 +94,18 @@
 	if uint8(p.role)&uint8(cache.Access) == 0 {
 		return nil, fmt.Errorf("Unauthorized")
 	}
-	i := cache.Data(p.printer)
-	i["css"] = cache.CSS
-	i["header"] = header(p.printer, p.status)
-	i["footer"] = footer(p.printer)
-	i["basedir"] = getBaseDir(cache.Path)
-
-	/*
-		if cache.Extra&ListDoctors != 0 {
-			i["doctors"] = listdoctors()
+	r := cache.Data(p.printer)
+	r["css"] = cache.CSS
+	r["header"] = header(p.printer, p.status)
+	r["footer"] = footer(p.printer)
+	r["basedir"] = getBaseDir(cache.Path)
+	var i IncludeExtra
+	for i = 0; i < Nplugin; i++ {
+		if (cache.Extra & i) != 0 {
+			r[pluginCache[i].Name] = pluginCache[i].Run(p.printer)
 		}
-		if cache.Extra&ListServices != 0 {
-			i["specialties"] = specialties(p.printer)
-		}
-		if cache.Extra&ListCountries != 0 {
-			i["countrylist"] = countrylist
-		}
+	}
+	/*
 		if p.session != nil && cache.Extra&FormErrors != 0 {
 			i["errors"] = p.session.Get("errors")
 		}
@@ -138,9 +134,9 @@
 		}
 	*/
 	if p.session != nil {
-		i["username"] = p.session.Get("username")
+		r["username"] = p.session.Get("username")
 	}
-	return cache.render(i)
+	return cache.render(r)
 }
 
 func (page *Page) render(i map[string]interface{}) ([]byte, error) {
--- a/router/plugins.go
+++ b/router/plugins.go
@@ -11,6 +11,9 @@
 
 var pluginCache map[IncludeExtra]*Plugin
 
+// Nplugin - Number of current plugins
+var Nplugin IncludeExtra
+
 // Plugin - Provide extra data or functionality from GET/POST pages
 type Plugin struct {
 	Name     string
@@ -36,6 +39,7 @@
 			errs = append(errs, fmt.Errorf("Error registering %s: Key requested already in use (%d)", item.Name, key^DEAD))
 		}
 	}
+	Nplugin = IncludeExtra(len(pluginCache))
 	return errs
 }