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

Method autoRender

display.go:254–288  ·  view source on GitHub ↗

detect and render data types that should be auto-rendered graphically

(mimeType string, arg interface{}, typ xreflect.Type)

Source from the content-addressed store, hash-verified

252
253// detect and render data types that should be auto-rendered graphically
254func (kernel *Kernel) autoRender(mimeType string, arg interface{}, typ xreflect.Type) Data {
255 var data Data
256 // try Data
257 if x, ok := arg.(Data); ok {
258 data = x
259 }
260
261 if kernel == nil || typ == nil {
262 // try all autoRenderers
263 for _, fun := range autoRenderers {
264 data = fun(data, arg)
265 }
266 } else {
267 // in gomacro, methods of interpreted types are emulated.
268 // Thus type-asserting them to interface types as done by autoRenderer functions above cannot succeed.
269 // Manually check if emulated type "pretends" to implement one or more of the above interfaces
270 // and, in case, tell the interpreter to convert to them
271 for name, xtyp := range kernel.render {
272 fun := autoRenderers[name]
273 if fun == nil || !typ.Implements(xtyp) {
274 continue
275 }
276 conv := kernel.ir.Comp.Converter(typ, xtyp)
277 x := arg
278 if conv != nil {
279 x = basereflect.ValueInterface(conv(xreflect.ValueOf(x)))
280 if x == nil {
281 continue
282 }
283 }
284 data = fun(data, x)
285 }
286 }
287 return fillDefaults(data, arg, "", nil, "", nil)
288}
289
290func fillDefaults(data Data, arg interface{}, s string, b []byte, mimeType string, err error) Data {
291 if err != nil {

Callers 2

autoRenderResultsMethod · 0.95
renderFunction · 0.95

Calls 1

fillDefaultsFunction · 0.85

Tested by

no test coverage detected