MCPcopy Index your code
hub / github.com/gopherdata/gophernotes / autoRenderResults

Method autoRenderResults

display.go:114–134  ·  view source on GitHub ↗

if vals[] contain a single non-nil value which is auto-renderable, convert it to Data and return it. otherwise return MakeData("text/plain", fmt.Sprint(vals...))

(vals []interface{}, types []xreflect.Type)

Source from the content-addressed store, hash-verified

112// convert it to Data and return it.
113// otherwise return MakeData("text/plain", fmt.Sprint(vals...))
114func (kernel *Kernel) autoRenderResults(vals []interface{}, types []xreflect.Type) Data {
115 var nilcount int
116 var obj interface{}
117 var typ xreflect.Type
118 for i, val := range vals {
119 if kernel.canAutoRender(val, types[i]) {
120 obj = val
121 typ = types[i]
122 } else if val == nil {
123 nilcount++
124 }
125 }
126 if obj != nil && nilcount == len(vals)-1 {
127 return kernel.autoRender("", obj, typ)
128 }
129 if nilcount == len(vals) {
130 // if all values are nil, return empty Data
131 return Data{}
132 }
133 return MakeData(MIMETypeText, fmt.Sprint(vals...))
134}
135
136// return true if data type should be auto-rendered graphically
137func (kernel *Kernel) canAutoRender(data interface{}, typ xreflect.Type) bool {

Callers 1

handleExecuteRequestMethod · 0.95

Calls 3

canAutoRenderMethod · 0.95
autoRenderMethod · 0.95
MakeDataFunction · 0.85

Tested by

no test coverage detected