From c986506a982960dead20a69716a9a40cbe1507e6 Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 10 Aug 2019 23:57:40 +0300 Subject: [PATCH] Flextype Core: Add ability to work with different types of content #212 #186 - FrontmatterParser implementation --- flextype/parsers/FrontmatterParser.php | 50 ++++++++++++++++++++++++++ flextype/parsers/Parser.php | 15 +++++--- 2 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 flextype/parsers/FrontmatterParser.php diff --git a/flextype/parsers/FrontmatterParser.php b/flextype/parsers/FrontmatterParser.php new file mode 100644 index 00000000..6163639e --- /dev/null +++ b/flextype/parsers/FrontmatterParser.php @@ -0,0 +1,50 @@ + [], 'body' => $content]; + } + + return ['matter' => trim($parts[1]), 'body' => implode(PHP_EOL . '---' . PHP_EOL, array_slice($parts, 2))]; + } + + public static function encode($input) : string + { + return ''; + } + + public static function decode(string $input) + { + return self::frontMatterParser($input); + } +} diff --git a/flextype/parsers/Parser.php b/flextype/parsers/Parser.php index 79f1b9a7..1e14f668 100644 --- a/flextype/parsers/Parser.php +++ b/flextype/parsers/Parser.php @@ -18,12 +18,9 @@ class Parser ], 'yaml' => [ 'name' => 'yaml', 'ext' => 'yaml', - ], 'md' => [ - 'name' => 'md', + ], 'frontmatter' => [ + 'name' => 'frontmatter', 'ext' => 'md', - ], 'toml' => [ - 'name' => 'toml', - 'ext' => 'toml', ], ]; @@ -37,6 +34,10 @@ class Parser case 'yaml': return JsonParser::encode($input); + break; + case 'frontmatter': + return FrontmatterParser::encode($input); + break; default: // code... @@ -54,6 +55,10 @@ class Parser case 'yaml': return YamlParser::decode($input); + break; + case 'frontmatter': + return FrontmatterParser::decode($input); + break; default: // code...