@ -159,28 +159,39 @@ func Profile(ctx *context.Context) {
ctx . Data [ "HeatmapData" ] = data
}
var renderErr error
var (
renderErr error
content string
)
renderErr = getRenderedTextField ( ctx , ctxUser , "Description" )
if renderErr != nil {
content , renderErr = GetRenderedTextField ( ctx , ctxUser , "Description" )
if renderErr == nil {
ctx . Data [ "RenderedDescription" ] = content
} else {
ctx . ServerError ( "RenderString" , renderErr )
return
}
renderErr = getRenderedTextField ( ctx , ctxUser , "Competences" )
if renderErr != nil {
content , renderErr = GetRenderedTextField ( ctx , ctxUser , "Competences" )
if renderErr == nil {
ctx . Data [ "RenderedCompetences" ] = content
} else {
ctx . ServerError ( "RenderString" , renderErr )
return
}
renderErr = getRenderedTextField ( ctx , ctxUser , "Resources" )
if renderErr != nil {
content , renderErr = GetRenderedTextField ( ctx , ctxUser , "Resources" )
if renderErr == nil {
ctx . Data [ "RenderedResources" ] = content
} else {
ctx . ServerError ( "RenderString" , renderErr )
return
}
renderErr = getRenderedTextField ( ctx , ctxUser , "Interests" )
if renderErr != nil {
content , renderErr = GetRenderedTextField ( ctx , ctxUser , "Interests" )
if renderErr == nil {
ctx . Data [ "RenderedInterests" ] = content
} else {
ctx . ServerError ( "RenderString" , renderErr )
return
}
@ -391,13 +402,13 @@ func Action(ctx *context.Context) {
ctx . RedirectToFirst ( ctx . FormString ( "redirect_to" ) , u . HomeLink ( ) )
}
func getTextField ( user * user_model . User , fieldName string ) string {
func getTextField ( user interface { } , fieldName string ) string {
reflectedObj := reflect . ValueOf ( user )
dynamicField := reflect . Indirect ( reflectedObj ) . FieldByName ( fieldName )
return dynamicField . String ( )
}
func g etRenderedTextField( ctx * context . Context , ctxUser * user_model . User , fieldName string ) error {
func G etRenderedTextField( ctx * context . Context , ctxUser interface { } , fieldName string ) ( string , error ) {
var err error = nil
var content string
fieldVal := getTextField ( ctxUser , fieldName )
@ -408,10 +419,6 @@ func getRenderedTextField(ctx *context.Context, ctxUser *user_model.User, fieldN
GitRepo : ctx . Repo . GitRepo ,
Ctx : ctx ,
} , fieldVal )
if err == nil {
renderedFieldName := fmt . Sprintf ( "Rendered%s" , fieldName )
ctx . Data [ renderedFieldName ] = content
}
}
return err
return content , err
}