This repository has been archived by the owner on Dec 27, 2018. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rebuild content loader, parser and converter.
WIP
- Loading branch information
1 parent
ef2217b
commit d502601
Showing
8 changed files
with
254 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
/* | ||
* Copyright (c) Arnaud Ligny <arnaud@ligny.org> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace PHPoole\Parser; | ||
|
||
/** | ||
* Class Ini. | ||
*/ | ||
class Ini implements ParserInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
* | ||
* @return array | ||
*/ | ||
public static function parse($string) | ||
{ | ||
return parse_ini_string($string); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
/* | ||
* Copyright (c) Arnaud Ligny <arnaud@ligny.org> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace PHPoole\Parser; | ||
|
||
use ParsedownExtra; | ||
|
||
/** | ||
* Class Parsedown. | ||
*/ | ||
class Parsedown implements ParserInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
* | ||
* @return string | ||
*/ | ||
public static function parse($string) | ||
{ | ||
return ParsedownExtra::instance()->text($string); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
/* | ||
* Copyright (c) Arnaud Ligny <arnaud@ligny.org> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace PHPoole\Parser; | ||
|
||
/** | ||
* Interface ParserInterface. | ||
*/ | ||
interface ParserInterface | ||
{ | ||
/** | ||
* Parse string. | ||
* | ||
* @param $string | ||
*/ | ||
public static function parse($string); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
/* | ||
* Copyright (c) Arnaud Ligny <arnaud@ligny.org> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace PHPoole\Parser; | ||
|
||
use PHPoole\Exception\Exception; | ||
use Symfony\Component\Yaml\Exception\ParseException; | ||
use Symfony\Component\Yaml\Yaml; | ||
|
||
/** | ||
* Class SfYaml. | ||
*/ | ||
class SfYaml implements ParserInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
* | ||
* @return array | ||
*/ | ||
public static function parse($string) | ||
{ | ||
try { | ||
return Yaml::parse($string); | ||
} catch (ParseException $e) { | ||
//throw new Exception($e->getMessage()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<?php | ||
/* | ||
* Copyright (c) Arnaud Ligny <arnaud@ligny.org> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace PHPoole\Step; | ||
|
||
use PHPoole\Exception\Exception; | ||
use Symfony\Component\Finder\Finder; | ||
use Symfony\Component\Finder\SplFileInfo; | ||
|
||
/** | ||
* Loads files in the 'content' directory. | ||
*/ | ||
class LoadContent extends AbstractStep | ||
{ | ||
// pattern of a file with a front matter | ||
// https://regex101.com/r/xH7cL3/1 | ||
const PATTERN = '^\s*(?:<!--|---|\+++){1}[\n\r\s]*(.*?)[\n\r\s]*(?:-->|---|\+++){1}[\s\n\r]*(.*)$'; | ||
/** | ||
* {@inheritdoc} | ||
* | ||
* @throws Exception | ||
*/ | ||
public function init() | ||
{ | ||
if (!is_dir($this->phpoole->getConfig()->getContentPath())) { | ||
throw new Exception(sprintf('%s not found!', $this->phpoole->getConfig()->getContentPath())); | ||
} | ||
$this->process = true; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function internalProcess() | ||
{ | ||
$content = []; | ||
// collects files in each supported format | ||
foreach ($this->phpoole->getConfig()->get('content.format') as $format => $data) { | ||
$files = Finder::create() | ||
->files() | ||
->in($this->phpoole->getConfig()->getContentPath()) | ||
->name('/\.('.implode('|', $data['ext']).')$/'); | ||
/* @var $file SplFileInfo */ | ||
foreach ($files as $file) { | ||
$index = $file->getRelativePathname(); | ||
$properties = $this->parse( | ||
$file->getContents(), | ||
$this->phpoole->getConfig()->get('content.frontmatter.'.$data['frontmatter'].'.parser') | ||
); | ||
$content[$index] = $properties; | ||
$content[$index]['content'] = ''; | ||
$content[$index]['format'] = $format; | ||
$content[$index]['lastmodified'] = $file->getMTime(); | ||
} | ||
} | ||
|
||
var_dump($content); | ||
|
||
$this->phpoole->setContent($content); | ||
} | ||
|
||
/** | ||
* Parse the contents of a file. | ||
* | ||
* Example: | ||
* ``` | ||
* --- | ||
* title: Title | ||
* date: 2016-07-29 | ||
* --- | ||
* Lorem Ipsum. | ||
* ``` | ||
* | ||
* @param string $content | ||
* | ||
* @param string $fmParser Class name | ||
* | ||
* @return array | ||
*/ | ||
public function parse($content, $fmParser) | ||
{ | ||
$properties = []; | ||
|
||
// parse front matter | ||
preg_match( | ||
'/'.self::PATTERN.'/s', | ||
$content, | ||
$matches | ||
); | ||
// if not front matter, set 'content' property only | ||
if (!$matches) { | ||
$properties['raw'] = $content; | ||
|
||
return $properties; | ||
} | ||
// parse front matter | ||
/* @var $parser \PHPoole\Parser\ParserInterface */ | ||
$parser = new $fmParser(); | ||
$properties = $parser->parse(trim($matches[1])); | ||
$properties['raw'] = trim($matches[2]); | ||
|
||
return $properties; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.