Exemple #1
0
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"))
	}
}
Exemple #2
0
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
}
Exemple #3
0
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))
}
Exemple #4
0
func renderRoot(context gon.WebContext) {
	context.WriteString(mustache.RenderFile(APP_VIEW_PATH + "main.m"))
}