Added support for arbitrary lists and experience in markup
This commit is contained in:
+74
-23
@@ -21,9 +21,10 @@ class DartboardData {
|
||||
final tomlData = TomlDocument.loadSync(tomlFilePath).toMap();
|
||||
|
||||
final List<DartboardExperience> exps = tomlData.entries
|
||||
.where((e) => e.value is List && (e.value as List).firstOrNull is Map)
|
||||
.where((e) => DartboardExperience.filter(e.value))
|
||||
.map((MapEntry<String, dynamic> expsEntry) {
|
||||
final String subsection = tomlData['${expsEntry.key}_name'] as String? ?? '';
|
||||
final String subsection =
|
||||
tomlData['${expsEntry.key}_name'] as String? ?? _getSubsectionFromKey(expsEntry.key);
|
||||
final exps = (expsEntry.value as List).map((e) => e as Map<String, dynamic>).toList();
|
||||
return exps.map((exp) {
|
||||
final TomlLocalDate? start = exp['start'] as TomlLocalDate?;
|
||||
@@ -35,34 +36,47 @@ class DartboardData {
|
||||
start: start == null ? null : DateTime(start.date.year, start.date.month),
|
||||
end: end == null ? null : DateTime(end.date.year, end.date.month),
|
||||
),
|
||||
attributes: (exp['attributes'] as List).map((e) => DartboardText(content: e as String)).toList(),
|
||||
attributes: (exp['attributes'] as List)
|
||||
.where((e) => e is String && e.isNotEmpty)
|
||||
.map((e) => DartboardText(content: e as String))
|
||||
.toList(),
|
||||
location: exp['location'] as String?,
|
||||
);
|
||||
}).toList();
|
||||
})
|
||||
.expand((i) => i)
|
||||
.toList();
|
||||
final List<DartboardMisc> misc =
|
||||
tomlData.entries.where((e) => DartboardMisc.filter(e.value)).map((MapEntry<String, dynamic> listEntry) {
|
||||
final String subsection = tomlData['${listEntry.key}_name'] as String? ?? _getSubsectionFromKey(listEntry.key);
|
||||
return DartboardMisc(
|
||||
subsection: subsection,
|
||||
attributes: (listEntry.value as List)
|
||||
.map((e) => (e as Map<String, dynamic>)['attributes'] as List)
|
||||
.expand((i) => i)
|
||||
.where((e) => e is String && e.isNotEmpty)
|
||||
.map((e) => DartboardText(content: e as String))
|
||||
.toList(),
|
||||
);
|
||||
}).toList();
|
||||
return DartboardData(
|
||||
fullName: tomlData['full_name'] as String,
|
||||
phoneNumber: tomlData['phone_number'] as String,
|
||||
email: tomlData['email'] as String,
|
||||
imagePath: tomlData['image'] as String,
|
||||
phoneNumber: tomlData['phone_number'] as String?,
|
||||
email: tomlData['email'] as String?,
|
||||
imagePath: tomlData['image'] as String?,
|
||||
dartboardTheme: DartboardTheme.fromToml(tomlData),
|
||||
experiences: exps,
|
||||
miscList: [
|
||||
DartboardList(subsection: 'Skills & Interest', content: 'Proficient in flutter and other'),
|
||||
],
|
||||
miscList: misc,
|
||||
);
|
||||
}
|
||||
|
||||
final String fullName;
|
||||
final String phoneNumber;
|
||||
final String email;
|
||||
// final String address;
|
||||
final String imagePath;
|
||||
final String? phoneNumber;
|
||||
final String? email;
|
||||
final String? imagePath;
|
||||
final DartboardTheme dartboardTheme;
|
||||
final List<DartboardExperience> experiences;
|
||||
final List<DartboardList> miscList;
|
||||
final List<DartboardMisc> miscList;
|
||||
|
||||
Font get font => dartboardTheme.font;
|
||||
|
||||
@@ -86,9 +100,20 @@ class DartboardData {
|
||||
return exps;
|
||||
}
|
||||
|
||||
Map<String, List<DartboardMisc>> get groupedMisc {
|
||||
final Map<String, List<DartboardMisc>> miscs = {};
|
||||
for (final DartboardMisc misc in miscList) {
|
||||
if (!miscs.containsKey(misc.subsection)) {
|
||||
miscs[misc.subsection] = <DartboardMisc>[];
|
||||
}
|
||||
miscs[misc.subsection]!.add(misc);
|
||||
}
|
||||
return miscs;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return Object.hashAll([fullName, phoneNumber, email, imagePath, ...experiences]);
|
||||
return Object.hashAll([fullName, phoneNumber, email, imagePath, ...experiences, ...miscList]);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -99,17 +124,25 @@ class DartboardData {
|
||||
|
||||
class DartboardExperience {
|
||||
DartboardExperience({
|
||||
required this.subsection,
|
||||
required this.title,
|
||||
required this.attributes,
|
||||
required this.range,
|
||||
required this.subsection,
|
||||
this.range,
|
||||
this.location,
|
||||
});
|
||||
final String subsection;
|
||||
final String title;
|
||||
String? location;
|
||||
final List<DartboardText> attributes;
|
||||
final DateRange range;
|
||||
final DateRange? range;
|
||||
String? location;
|
||||
|
||||
static bool filter(dynamic e) {
|
||||
if (e is! List || !e.every((f) => f is Map)) {
|
||||
return false;
|
||||
}
|
||||
final List<Map<String, dynamic>> entries = e.map((f) => f as Map<String, dynamic>).toList();
|
||||
return entries.every((f) => f['title'] is String && f['attributes'] is List && f.keys.length >= 2);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
@@ -153,19 +186,29 @@ class DateRange {
|
||||
}
|
||||
}
|
||||
|
||||
class DartboardList {
|
||||
DartboardList({required this.subsection, required this.content});
|
||||
class DartboardMisc {
|
||||
DartboardMisc({required this.subsection, required this.attributes});
|
||||
|
||||
final String subsection;
|
||||
final String content;
|
||||
final List<DartboardText> attributes;
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return Object.hashAll([subsection, content]);
|
||||
return Object.hashAll([subsection, ...attributes]);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return super.hashCode == other.hashCode;
|
||||
}
|
||||
|
||||
static bool filter(dynamic e) {
|
||||
if (e is! List || e.firstOrNull is! Map) {
|
||||
return false;
|
||||
}
|
||||
final entries = (e.first as Map).entries;
|
||||
return entries.length == 1 && entries.first.key == 'attributes';
|
||||
}
|
||||
}
|
||||
|
||||
class DartboardTheme {
|
||||
@@ -277,5 +320,13 @@ class DartboardText {
|
||||
String _getSubsectionFromKey(String key) {
|
||||
switch (key) {
|
||||
case 'exp':
|
||||
return 'Experience';
|
||||
case 'misc':
|
||||
return 'Miscelaneous';
|
||||
case 'edu':
|
||||
return 'Education';
|
||||
case '':
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user