Upgrade text formatter (#1457)

* upgrade TextFormatter

* remove finalize options

* cleanup JsCompiler

* simplify Formatter

* refactor Formatter cache

* minify formatter js

* remove Closure Compiler
This commit is contained in:
Sajjad Hashemian 2018-07-15 00:52:14 +04:30 committed by Franz Liedke
parent 9284322026
commit 7635ef181a
2 changed files with 15 additions and 17 deletions

View File

@ -50,7 +50,7 @@
"psr/http-message": "^1.0",
"psr/http-server-handler": "^1.0",
"psr/http-server-middleware": "^1.0",
"s9e/text-formatter": "^0.8.1",
"s9e/text-formatter": "^1.2.0",
"symfony/config": "^3.3",
"symfony/console": "^3.3",
"symfony/http-foundation": "^3.3",

View File

@ -96,8 +96,7 @@ class Formatter
*/
public function flush()
{
$this->cache->forget('flarum.formatter.parser');
$this->cache->forget('flarum.formatter.renderer');
$this->cache->forget('flarum.formatter');
}
/**
@ -112,6 +111,13 @@ class Formatter
$configurator->rendering->engine = 'PHP';
$configurator->rendering->engine->cacheDir = $this->cacheDir;
$configurator->enableJavaScript();
$configurator->javascript->exportMethods = ['preview'];
$minifier = $configurator->javascript->setMinifier('FirstAvailable');
$minifier->add('MatthiasMullieMinify');
$minifier->add('Noop');
$configurator->Escaper;
$configurator->Autoemail;
$configurator->Autolink;
@ -142,16 +148,16 @@ class Formatter
/**
* Get a TextFormatter component.
*
* @param string $name "renderer" or "parser"
* @param string $name "renderer" or "parser" or "js"
* @return mixed
*/
protected function getComponent($name)
{
$cacheKey = 'flarum.formatter.'.$name;
return $this->cache->rememberForever($cacheKey, function () use ($name) {
return $this->getConfigurator()->finalize()[$name];
$formatter = $this->cache->rememberForever('flarum.formatter', function () {
return $this->getConfigurator()->finalize();
});
return $formatter[$name];
}
/**
@ -193,14 +199,6 @@ class Formatter
*/
public function getJs()
{
$configurator = $this->getConfigurator();
$configurator->enableJavaScript();
$configurator->javascript->exportMethods = ['preview'];
$configurator->javascript->setMinifier('MatthiasMullieMinify');
return $configurator->finalize([
'returnParser' => false,
'returnRenderer' => false
])['js'];
return $this->getComponent('js');
}
}