diff --git a/common/template_init.go b/common/template_init.go index 0ea8b83f..75849296 100644 --- a/common/template_init.go +++ b/common/template_init.go @@ -748,6 +748,10 @@ func initDefaultTmplFuncMap() { return template.HTML(BuildWidget(dock.(string), headerInt.(*Header))) } + fmap["hasWidgets"] = func(dock interface{}, headerInt interface{}) interface{} { + return HasWidgets(dock.(string), headerInt.(*Header)) + } + fmap["elapsed"] = func(startedAtInt interface{}) interface{} { return time.Since(startedAtInt.(time.Time)).String() } diff --git a/common/templates/templates.go b/common/templates/templates.go index 04e2ae12..c183e354 100644 --- a/common/templates/templates.go +++ b/common/templates/templates.go @@ -85,22 +85,23 @@ func NewCTemplateSet(in string) *CTemplateSet { baseImportMap: map[string]string{}, overridenRoots: map[string]map[string]bool{}, funcMap: map[string]interface{}{ - "and": "&&", - "not": "!", - "or": "||", - "eq": "==", - "ge": ">=", - "gt": ">", - "le": "<=", - "lt": "<", - "ne": "!=", - "add": "+", - "subtract": "-", - "multiply": "*", - "divide": "/", - "dock": true, - "elapsed": true, - "lang": true, + "and": "&&", + "not": "!", + "or": "||", + "eq": "==", + "ge": ">=", + "gt": ">", + "le": "<=", + "lt": "<", + "ne": "!=", + "add": "+", + "subtract": "-", + "multiply": "*", + "divide": "/", + "dock": true, + "hasWidgets": true, + "elapsed": true, + "lang": true, //"langf":true, "level": true, "abstime": true, @@ -1040,6 +1041,30 @@ ArgLoop: // TODO: Refactor this litString("common.BuildWidget("+leftParam+","+rightParam+")", false) break ArgLoop + case "hasWidgets": + // TODO: Implement string literals properly + leftOperand := node.Args[pos+1].String() + rightOperand := node.Args[pos+2].String() + if len(leftOperand) == 0 || len(rightOperand) == 0 { + panic("The left or right operand for function dock cannot be left blank") + } + leftParam := leftOperand + if leftOperand[0] != '"' { + leftParam, _ = c.compileIfVarSub(con, leftParam) + } + if rightOperand[0] == '"' { + panic("The right operand for function dock cannot be a string") + } + rightParam, val3 := c.compileIfVarSub(con, rightOperand) + if !val3.IsValid() { + panic("val3 is invalid") + } + val = val3 + + // TODO: Refactor this + out = "common.HasWidgets(" + leftParam + "," + rightParam + ")" + literal = true + break ArgLoop case "lang": // TODO: Implement string literals properly leftOperand := node.Args[pos+1].String() diff --git a/common/widgets.go b/common/widgets.go index 21a72ebe..8b1ab40c 100644 --- a/common/widgets.go +++ b/common/widgets.go @@ -137,6 +137,42 @@ func HasDock(dock string) bool { return false } +// TODO: Find a more optimimal way of doing this... +func HasWidgets(dock string, header *Header) bool { + if !header.Theme.HasDock(dock) { + return false + } + + // Let themes forcibly override this slot + sbody := header.Theme.BuildDock(dock) + if sbody != "" { + return true + } + + var widgets []*Widget + switch dock { + case "leftOfNav": + widgets = Docks.LeftOfNav + case "rightOfNav": + widgets = Docks.RightOfNav + case "rightSidebar": + widgets = Docks.RightSidebar.Items + case "footer": + widgets = Docks.Footer.Items + } + + wcount := 0 + for _, widget := range widgets { + if !widget.Enabled { + continue + } + if widget.Allowed(header.Zone) { + wcount++ + } + } + return wcount > 0 +} + func BuildWidget(dock string, header *Header) (sbody string) { var widgets []*Widget if !header.Theme.HasDock(dock) { diff --git a/templates/header.html b/templates/header.html index a4fdafda..cb39c6e6 100644 --- a/templates/header.html +++ b/templates/header.html @@ -56,7 +56,7 @@ {{/****/}}
-
+
{{range .Header.NoticeList}} {{template "notice.html" . }}{{end}}