You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
404 B
Dart
20 lines
404 B
Dart
2 years ago
|
class SimpleTemplate {
|
||
|
String? tpl;
|
||
|
|
||
|
SimpleTemplate({this.tpl});
|
||
|
|
||
|
String fetch(Map<String, String> params) {
|
||
|
if (tpl == null) return "";
|
||
|
|
||
|
var re = RegExp(r"{{(?<name>[^,;:'\n]+?)}}");
|
||
|
|
||
|
return tpl!.replaceAllMapped(re, (match) {
|
||
|
var key = match.group(1)!.trim();
|
||
|
if (params.containsKey(key)) {
|
||
|
return params[key]!;
|
||
|
}
|
||
|
return match.group(0)!;
|
||
|
});
|
||
|
}
|
||
|
}
|