mirror of
https://github.com/flarum/framework.git
synced 2025-02-22 13:38:38 +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-message": "^1.0",
|
||||||
"psr/http-server-handler": "^1.0",
|
"psr/http-server-handler": "^1.0",
|
||||||
"psr/http-server-middleware": "^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/config": "^3.3",
|
||||||
"symfony/console": "^3.3",
|
"symfony/console": "^3.3",
|
||||||
"symfony/http-foundation": "^3.3",
|
"symfony/http-foundation": "^3.3",
|
||||||
|
@ -96,8 +96,7 @@ class Formatter
|
|||||||
*/
|
*/
|
||||||
public function flush()
|
public function flush()
|
||||||
{
|
{
|
||||||
$this->cache->forget('flarum.formatter.parser');
|
$this->cache->forget('flarum.formatter');
|
||||||
$this->cache->forget('flarum.formatter.renderer');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -112,6 +111,13 @@ class Formatter
|
|||||||
$configurator->rendering->engine = 'PHP';
|
$configurator->rendering->engine = 'PHP';
|
||||||
$configurator->rendering->engine->cacheDir = $this->cacheDir;
|
$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->Escaper;
|
||||||
$configurator->Autoemail;
|
$configurator->Autoemail;
|
||||||
$configurator->Autolink;
|
$configurator->Autolink;
|
||||||
@ -142,16 +148,16 @@ class Formatter
|
|||||||
/**
|
/**
|
||||||
* Get a TextFormatter component.
|
* Get a TextFormatter component.
|
||||||
*
|
*
|
||||||
* @param string $name "renderer" or "parser"
|
* @param string $name "renderer" or "parser" or "js"
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
protected function getComponent($name)
|
protected function getComponent($name)
|
||||||
{
|
{
|
||||||
$cacheKey = 'flarum.formatter.'.$name;
|
$formatter = $this->cache->rememberForever('flarum.formatter', function () {
|
||||||
|
return $this->getConfigurator()->finalize();
|
||||||
return $this->cache->rememberForever($cacheKey, function () use ($name) {
|
|
||||||
return $this->getConfigurator()->finalize()[$name];
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return $formatter[$name];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -193,14 +199,6 @@ class Formatter
|
|||||||
*/
|
*/
|
||||||
public function getJs()
|
public function getJs()
|
||||||
{
|
{
|
||||||
$configurator = $this->getConfigurator();
|
return $this->getComponent('js');
|
||||||
$configurator->enableJavaScript();
|
|
||||||
$configurator->javascript->exportMethods = ['preview'];
|
|
||||||
$configurator->javascript->setMinifier('MatthiasMullieMinify');
|
|
||||||
|
|
||||||
return $configurator->finalize([
|
|
||||||
'returnParser' => false,
|
|
||||||
'returnRenderer' => false
|
|
||||||
])['js'];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user