Пример #1
0
func TemplateVars(typ interface{}) template.VarMap {
	fin := []reflect.Type{reflect.TypeOf(typ)}
	stringOut := []reflect.Type{reflect.TypeOf("")}
	stringFuncTyp := reflect.FuncOf(fin, stringOut, false)
	varFunc := func(in []reflect.Value) []reflect.Value {
		url, _ := updatesURL(in[0])
		return []reflect.Value{reflect.ValueOf(url)}
	}
	boolOut := []reflect.Type{reflect.TypeOf(true)}
	boolFuncTyp := reflect.FuncOf(fin, boolOut, false)
	enabledFunc := func(in []reflect.Value) []reflect.Value {
		url, _ := updatesURL(in[0])
		enabled := url != ""
		return []reflect.Value{reflect.ValueOf(enabled)}
	}
	template.AddFunc(&template.Func{
		Name:   "__gondola_is_live_reload_enabled",
		Fn:     reflect.MakeFunc(boolFuncTyp, enabledFunc).Interface(),
		Traits: template.FuncTraitContext,
	})
	reasonFunc := func(in []reflect.Value) []reflect.Value {
		_, reason := updatesURL(in[0])
		return []reflect.Value{reflect.ValueOf(reason)}
	}
	template.AddFunc(&template.Func{
		Name:   "__gondola_is_live_reload_disabled_reason",
		Fn:     reflect.MakeFunc(stringFuncTyp, reasonFunc).Interface(),
		Traits: template.FuncTraitContext,
	})

	return template.VarMap{
		"BroadcasterWebsocketUrl": reflect.MakeFunc(stringFuncTyp, varFunc).Interface(),
	}
}
Пример #2
0
func init() {
	template.AddFunc(&template.Func{Name: "fa", Fn: fa})
}