gosora/common/templates/context.go

100 lines
2.3 KiB
Go
Raw Normal View History

package tmpl
import (
"reflect"
)
// For use in generated code
type FragLite struct {
Body string
}
type Fragment struct {
Body string
TemplateName string
Index int
Seen bool
}
type OutBufferFrame struct {
Body string
Type string
TemplateName string
Extra interface{}
Extra2 interface{}
}
type CContext struct {
RootHolder string
VarHolder string
HoldReflect reflect.Value
The Search and Filter Widget is now partly implemented. Just Search to go in the basic implementation. Added AJAX Pagination for the Topic List and Forum Page. A new log file pair is now created every-time Gosora starts up. Added proper per-theme template overrides. Added EasyJSON to make JSON serialisation faster. Moved a bit of boilerplate into paginator.html Improved paginator.html with a richer template with first, last and symbols instead of text. Phased out direct access to Templates.ExecuteTemplate across the software. Fixed the Live Topic List so it should work again. Added MicroAvatar to WsJSONUser for topic list JSON requests. An instance of the plugin is now passed to plugin handlers rather than having the plugins manipulate the globals directly. Added the pre_render_panel_forum_edit and pre_render_panel_forum_edit_perms hooks to replace pre_render_panel_edit_forum. Renamed the pre_render_panel_edit_user hook to pre_render_panel_user_edit Reduced the amount of noise from fsnotify. Added RawPrepare() to qgen.Accumulator. Added a temporary phrase whitelist to the phrase endpoint. Moved the location of the zone data assignments in the topic list to reduce the chances of security issues in the future. Changed the signature of routes/panel/renderTemplate() requiring some changes across the panel routes. Removed bits of boilerplate in some of the panel routes with renderTemplate() Added a BenchmarkTopicsGuestJSRouteParallelWithRouter benchmark. Removed a fair bit of boilerplate for each page struct by generating a couple of interface casts for each template file instead. Added the profile_comments_row_alt template. Added the topics_quick_topic template to reuse part of the quick topic logic for both the topic list and forum page. Tweaked the CSS for the Online Users Widget. Tweaked the CSS for Widgets in every theme with a sidebar. Refactored the template initialisers to hopefully reduce the amount of boilerplate and make things easier to maintain and follow. Add genIntTmpl in the template initialiser file to reduce the amount of boilerplate needed for the fallback template bindings. Removed the topics_head phrase. Moved the paginator_ phrases into the paginator. namespace and renamed them accordingly. Added the paginator.first_page phrase. Added the paginator.first_page_aria phrase. Added the paginator.last_page phrase. Added the paginator.last_page_aria phrase. Added the panel_forum_delete_are_you_sure phrase. Fixed a data race in LogWarning()
2019-02-10 05:52:26 +00:00
RootTemplateName string
TemplateName string
LoopDepth int
OutBuf *[]OutBufferFrame
}
func (con *CContext) Push(nType string, body string) (index int) {
*con.OutBuf = append(*con.OutBuf, OutBufferFrame{body, nType, con.TemplateName, nil, nil})
return con.LastBufIndex()
}
func (con *CContext) PushText(body string, fragIndex int, fragOutIndex int) (index int) {
*con.OutBuf = append(*con.OutBuf, OutBufferFrame{body, "text", con.TemplateName, fragIndex, fragOutIndex})
return con.LastBufIndex()
}
func (con *CContext) PushPhrase(langIndex int) (index int) {
*con.OutBuf = append(*con.OutBuf, OutBufferFrame{"", "lang", con.TemplateName, langIndex, nil})
return con.LastBufIndex()
}
func (con *CContext) StartLoop(body string) (index int) {
con.LoopDepth++
return con.Push("startloop", body)
}
func (con *CContext) EndLoop(body string) (index int) {
return con.Push("endloop", body)
}
func (con *CContext) StartTemplate(body string) (index int) {
return con.addFrame(body, "starttemplate", nil, nil)
}
func (con *CContext) EndTemplate(body string) (index int) {
return con.Push("endtemplate", body)
}
func (con *CContext) AttachVars(vars string, index int) {
outBuf := *con.OutBuf
node := outBuf[index]
if node.Type != "starttemplate" && node.Type != "startloop" {
panic("not a starttemplate node")
}
node.Body += vars
outBuf[index] = node
}
func (con *CContext) addFrame(body string, ftype string, extra1 interface{}, extra2 interface{}) (index int) {
*con.OutBuf = append(*con.OutBuf, OutBufferFrame{body, ftype, con.TemplateName, extra1, extra2})
return con.LastBufIndex()
}
func (con *CContext) LastBufIndex() int {
return len(*con.OutBuf) - 1
}
func (con *CContext) DiscardAndAfter(index int) {
outBuf := *con.OutBuf
if len(outBuf) <= index {
return
}
if index == 0 {
outBuf = nil
} else {
outBuf = outBuf[:index]
}
*con.OutBuf = outBuf
}