From bfbb3bf962f8464fafa1223ddea3dec1cdc28be9 Mon Sep 17 00:00:00 2001 From: Maksim Lin Date: Fri, 30 Sep 2022 09:29:26 +1000 Subject: [PATCH 1/5] update dependencies --- pubspec.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index cc2e0a5..770d5a9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -7,6 +7,6 @@ documentation: https://github.com/izolate/front-matter/blob/master/README.md environment: sdk: '>=2.0.0 <3.0.0' dependencies: - yaml: ^2.1.15 + yaml: ^3.1.1 dev_dependencies: - test: ^1.6.2 + test: ^1.21.6 From dcd31ac70bc3c8819b64c52f3c32f8782f01a7e5 Mon Sep 17 00:00:00 2001 From: Maksim Lin Date: Fri, 30 Sep 2022 09:29:56 +1000 Subject: [PATCH 2/5] remove no longer supported author field --- pubspec.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 770d5a9..5c6f7a6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,6 @@ name: front_matter version: 1.1.0 description: A front matter parser that extracts YAML metadata from the start of a file or string. -author: izolate homepage: https://github.com/izolate/front-matter documentation: https://github.com/izolate/front-matter/blob/master/README.md environment: From 5e08c6a1ad9399fc6f8a82af8ebc31032ddb177f Mon Sep 17 00:00:00 2001 From: Maksim Lin Date: Fri, 30 Sep 2022 09:30:22 +1000 Subject: [PATCH 3/5] remove unused import --- test/front_matter_test.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/test/front_matter_test.dart b/test/front_matter_test.dart index e2bd7f2..8cccd25 100644 --- a/test/front_matter_test.dart +++ b/test/front_matter_test.dart @@ -1,6 +1,5 @@ import 'package:test/test.dart'; import 'package:front_matter/front_matter.dart' as fm; -import 'package:front_matter/src/front_matter.dart'; import 'package:front_matter/src/front_matter_document.dart'; import 'package:front_matter/src/front_matter_exception.dart'; From f39f3c8f9e2b6027dce125691984737c7b27d417 Mon Sep 17 00:00:00 2001 From: Maksim Lin Date: Fri, 30 Sep 2022 09:59:32 +1000 Subject: [PATCH 4/5] migrate to sound null safety --- example/front_matter.dart | 4 ++-- lib/src/front_matter.dart | 11 +++++------ lib/src/front_matter_document.dart | 4 ++-- lib/src/parser.dart | 2 +- pubspec.yaml | 2 +- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/example/front_matter.dart b/example/front_matter.dart index 1ba1455..835a5b2 100644 --- a/example/front_matter.dart +++ b/example/front_matter.dart @@ -2,7 +2,7 @@ import 'dart:io'; import 'package:front_matter/front_matter.dart' as fm; // Example 1 - Parse a string. -void example1() async { +Future example1() async { var file = File('example/hello-world.md'); var fileContents = await file.readAsString(); @@ -14,7 +14,7 @@ void example1() async { } // Example 2 - Read a file and parse its contents. -void example2() async { +Future example2() async { var doc = await fm.parseFile('example/hello-world.md'); print("The author is ${doc.data['author']}"); diff --git a/lib/src/front_matter.dart b/lib/src/front_matter.dart index 75678ff..9c008bb 100644 --- a/lib/src/front_matter.dart +++ b/lib/src/front_matter.dart @@ -27,11 +27,10 @@ Future parseFile(String path, return parser(text, delimiter: delimiter); } catch (e) { // Handle downstream errors, or throw one if file is not readable as text. - switch (e.message) { - case invalidYamlError: - rethrow; - default: - throw FrontMatterException(fileTypeError); - } + if (e is FrontMatterException && e.message == invalidYamlError) { + rethrow; + } else { + throw FrontMatterException(fileTypeError); + } } } diff --git a/lib/src/front_matter_document.dart b/lib/src/front_matter_document.dart index b509a94..976c8d6 100644 --- a/lib/src/front_matter_document.dart +++ b/lib/src/front_matter_document.dart @@ -6,10 +6,10 @@ class FrontMatterDocument { String value; /// The parsed [content] from the [value]. - String content; + String? content; /// The parsed YAML front matter as a [YamlMap]. - YamlMap data; + YamlMap data = YamlMap(); FrontMatterDocument(this.value); diff --git a/lib/src/parser.dart b/lib/src/parser.dart index 694c6bf..5bd9eaf 100644 --- a/lib/src/parser.dart +++ b/lib/src/parser.dart @@ -8,7 +8,7 @@ import 'front_matter_exception.dart'; /// `data` [YamlMap], and the remaining `content` [String]. /// /// Throws a [FrontMatterException] if front matter contains invalid YAML. -FrontMatterDocument parser(String text, {String delimiter}) { +FrontMatterDocument parser(String text, {required String delimiter}) { var doc = FrontMatterDocument(text); // Remove any leading whitespace. diff --git a/pubspec.yaml b/pubspec.yaml index 5c6f7a6..2501547 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,7 +4,7 @@ description: A front matter parser that extracts YAML metadata from the start of homepage: https://github.com/izolate/front-matter documentation: https://github.com/izolate/front-matter/blob/master/README.md environment: - sdk: '>=2.0.0 <3.0.0' + sdk: '>=2.12.0 <3.0.0' dependencies: yaml: ^3.1.1 dev_dependencies: From 4d8bec6613863d8440c2df6e9567ab5572f141c1 Mon Sep 17 00:00:00 2001 From: Maksim Lin Date: Wed, 28 Jun 2023 11:04:42 +1000 Subject: [PATCH 5/5] update to Dart 3 --- pubspec.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index 2501547..57fc3ec 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,8 +4,8 @@ description: A front matter parser that extracts YAML metadata from the start of homepage: https://github.com/izolate/front-matter documentation: https://github.com/izolate/front-matter/blob/master/README.md environment: - sdk: '>=2.12.0 <3.0.0' + sdk: '>=3.0.0 <4.0.0' dependencies: - yaml: ^3.1.1 + yaml: ^3.1.2 dev_dependencies: test: ^1.21.6