resolve static method
Resolves o
to an HTML string.
Accepts:
- String.
- StringBuffer.
- Function.
- MapEntry:
- If is a
MapEntry<String, TypeInfo>
orMapEntry<String, Type>
will be converted to an input.
- If is a
- Iterable: maps elements calling resolve.
- Map: encodes to JSON calling Json.encode.
Implementation
static String resolve(Object? o) {
if (o == null) return '';
if (o is Function()) {
o = o();
}
if (o is MapEntry) {
if (o is MapEntry<String, TypeInfo>) {
o = HTMLInput.from(o);
} else if (o is MapEntry<String, Type>) {
o = HTMLInput.from(o);
} else {
var k = resolve(o.key);
var v = resolve(o.value);
return '$k: $v';
}
}
if (o is HTMLInput) {
return o.build();
}
if (o is EntityReference) {
return resolve(o.entityOrID);
} else if (o is EntityReferenceList) {
return resolve(o.entitiesOrIDs);
}
if (o is Iterable) {
return o.map(resolve).join();
}
if (o is Map) {
var jsonEnc = Json.encode(o, pretty: true);
return '<pre>$jsonEnc</pre>';
}
if (o is StringBuffer) return o.toString();
if (o is String) return o;
var s = o.toString();
return s;
}