Exemplo n.º 1
0
Arquivo: starter.go Projeto: ssrl/gon
func renderDefault(context gon.WebContext, ret []reflect.Value, controllerName string, actionName string) {
	if model, ok := ret[0].Interface().(mv.Model); ok {
		context.WriteString(mustache.RenderFile(APP_VIEW_PATH+controllerName+"/"+actionName+".m", model))
	} else if view, ok := ret[0].Interface().(mv.View); ok {
		actionName = view.String()
		context.WriteString(mustache.RenderFile(APP_VIEW_PATH + controllerName + "/" + actionName + ".m"))
	}
}
Exemplo n.º 2
0
Arquivo: starter.go Projeto: ssrl/gon
func instantiateAndInjectController(context gon.WebContext, controllerType reflect.Type) reflect.Value {
	// Instantiate a controller
	conValue := reflect.New(controllerType)
	conIndirect := reflect.Indirect(conValue)

	// Inject Params
	conIndirect.FieldByName("Params").Set(reflect.ValueOf(context.GetParams()))

	//
	// Inject beans
	// This loop tends to be slow. We should loop over field names and look-up a bean.
	//
	for beanName, setterFunc := range bean.Registry() {
		if _, ok := controllerType.FieldByName(beanName); ok {
			if field := conIndirect.FieldByName(beanName); field.IsValid() {
				field.Set(reflect.ValueOf(setterFunc()))
			}
		}
	}
	return conValue
}
Exemplo n.º 3
0
Arquivo: starter.go Projeto: ssrl/gon
func renderWithActionName(context gon.WebContext, ret []reflect.Value, controllerName string) {
	model := ret[0].Interface().(mv.Model)
	view := ret[1].Interface().(mv.View)
	actionName := view.String()
	context.WriteString(mustache.RenderFile(APP_VIEW_PATH+controllerName+"/"+actionName+".m", model))
}
Exemplo n.º 4
0
Arquivo: starter.go Projeto: ssrl/gon
func renderRoot(context gon.WebContext) {
	context.WriteString(mustache.RenderFile(APP_VIEW_PATH + "main.m"))
}