shrink_main should work again.

This commit is contained in:
Azareal 2019-02-28 19:31:13 +10:00
parent 75668db3ea
commit 25846d8942
4 changed files with 82 additions and 17 deletions

View File

@ -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()
}

View File

@ -99,6 +99,7 @@ func NewCTemplateSet(in string) *CTemplateSet {
"multiply": "*",
"divide": "/",
"dock": true,
"hasWidgets": true,
"elapsed": true,
"lang": true,
//"langf":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()

View File

@ -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) {

View File

@ -56,7 +56,7 @@
{{/**<!--</div>-->**/}}
<div class="midRow">
<div class="midLeft"></div>
<div id="back" class="zone_{{.Header.Zone}}{{if .Header.Widgets.RightSidebar}} shrink_main{{end}}">
<div id="back" class="zone_{{.Header.Zone}}{{if hasWidgets "rightSidebar" .Header }} shrink_main{{end}}">
<div id="main" >
<div class="alertbox initial_alertbox">{{range .Header.NoticeList}}
{{template "notice.html" . }}{{end}}