Lazy load CommonMark converter, speeds up generation in serve mode when file is cached (~ -10ms)
This commit is contained in:
parent
727c5c015e
commit
abaf36bec6
@ -12,12 +12,23 @@ class ContentType implements \Todaymade\Daux\ContentTypes\ContentType
|
|||||||
protected $config;
|
protected $config;
|
||||||
|
|
||||||
/** @var CommonMarkConverter */
|
/** @var CommonMarkConverter */
|
||||||
protected $converter;
|
private $converter;
|
||||||
|
|
||||||
public function __construct(Config $config)
|
public function __construct(Config $config)
|
||||||
{
|
{
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
$this->converter = new CommonMarkConverter(['daux' => $config]);
|
}
|
||||||
|
|
||||||
|
protected function createConverter() {
|
||||||
|
return new CommonMarkConverter(['daux' => $this->config]);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getConverter() {
|
||||||
|
if (!$this->converter) {
|
||||||
|
$this->converter = $this->createConverter();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->converter;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,7 +42,7 @@ class ContentType implements \Todaymade\Daux\ContentTypes\ContentType
|
|||||||
protected function doConversion($raw)
|
protected function doConversion($raw)
|
||||||
{
|
{
|
||||||
Daux::writeln("Running conversion", OutputInterface::VERBOSITY_VERBOSE);
|
Daux::writeln("Running conversion", OutputInterface::VERBOSITY_VERBOSE);
|
||||||
return $this->converter->convertToHtml($raw);
|
return $this->getConverter()->convertToHtml($raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function convert($raw, Content $node)
|
public function convert($raw, Content $node)
|
||||||
|
@ -4,9 +4,7 @@ use Todaymade\Daux\Config;
|
|||||||
|
|
||||||
class ContentType extends \Todaymade\Daux\ContentTypes\Markdown\ContentType
|
class ContentType extends \Todaymade\Daux\ContentTypes\Markdown\ContentType
|
||||||
{
|
{
|
||||||
public function __construct(Config $config)
|
protected function createConverter() {
|
||||||
{
|
return new CommonMarkConverter(['daux' => $this->config]);
|
||||||
$this->config = $config;
|
|
||||||
$this->converter = new CommonMarkConverter(['daux' => $config]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,7 @@ use Todaymade\Daux\Config;
|
|||||||
|
|
||||||
class ContentType extends \Todaymade\Daux\ContentTypes\Markdown\ContentType
|
class ContentType extends \Todaymade\Daux\ContentTypes\Markdown\ContentType
|
||||||
{
|
{
|
||||||
public function __construct(Config $config)
|
protected function createConverter() {
|
||||||
{
|
return new CommonMarkConverter(['daux' => $this->config]);
|
||||||
$this->config = $config;
|
|
||||||
$this->converter = new CommonMarkConverter(['daux' => $config]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,7 @@ use Todaymade\Daux\Config;
|
|||||||
|
|
||||||
class ContentType extends \Todaymade\Daux\ContentTypes\Markdown\ContentType
|
class ContentType extends \Todaymade\Daux\ContentTypes\Markdown\ContentType
|
||||||
{
|
{
|
||||||
public function __construct(Config $config)
|
protected function createConverter() {
|
||||||
{
|
return new CommonMarkConverter(['daux' => $this->config]);
|
||||||
$this->config = $config;
|
|
||||||
$this->converter = new CommonMarkConverter(['daux' => $config]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user