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)
| 112 | // convert it to Data and return it. |
| 113 | // otherwise return MakeData("text/plain", fmt.Sprint(vals...)) |
| 114 | func (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 |
| 137 | func (kernel *Kernel) canAutoRender(data interface{}, typ xreflect.Type) bool { |
no test coverage detected