mirror of
https://github.com/flarum/framework.git
synced 2025-02-21 12:25:57 +08:00
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:
parent
9284322026
commit
7635ef181a
@ -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",
|
||||
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user