mirror of
https://github.com/flarum/core.git
synced 2025-08-16 13:24:11 +02:00
Merge branch 'master' into 1236-database-changes
This commit is contained in:
@@ -21,7 +21,7 @@ class Assets implements ExtenderInterface
|
||||
protected $appName;
|
||||
|
||||
protected $assets = [];
|
||||
protected $bootstrapper;
|
||||
protected $js;
|
||||
|
||||
public function __construct($appName)
|
||||
{
|
||||
@@ -35,9 +35,9 @@ class Assets implements ExtenderInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function bootstrapper($name)
|
||||
public function js($path)
|
||||
{
|
||||
$this->bootstrapper = $name;
|
||||
$this->js = $path;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -46,15 +46,19 @@ class Assets implements ExtenderInterface
|
||||
{
|
||||
$container->make(Dispatcher::class)->listen(
|
||||
Rendering::class,
|
||||
function (Rendering $event) {
|
||||
function (Rendering $event) use ($extension) {
|
||||
if (! $this->matches($event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$event->addAssets($this->assets);
|
||||
|
||||
if ($this->bootstrapper) {
|
||||
$event->addBootstrapper($this->bootstrapper);
|
||||
if ($this->js) {
|
||||
$event->view->getJs()->addString(function () use ($extension) {
|
||||
$name = $extension->getId();
|
||||
|
||||
return 'var module={};'.file_get_contents($this->js).";\nflarum.extensions['$name']=module.exports";
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
|
55
src/Extend/Formatter.php
Normal file
55
src/Extend/Formatter.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Extend;
|
||||
|
||||
use Flarum\Extension\Event\Disabled;
|
||||
use Flarum\Extension\Event\Enabled;
|
||||
use Flarum\Extension\Extension;
|
||||
use Flarum\Formatter\Event\Configuring;
|
||||
use Flarum\Formatter\Formatter as ActualFormatter;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use Illuminate\Events\Dispatcher;
|
||||
|
||||
class Formatter implements ExtenderInterface
|
||||
{
|
||||
protected $callback;
|
||||
|
||||
public function configure(callable $callback)
|
||||
{
|
||||
$this->callback = $callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function __invoke(Container $container, Extension $extension = null)
|
||||
{
|
||||
$events = $container->make(Dispatcher::class);
|
||||
|
||||
$events->listen(
|
||||
Configuring::class,
|
||||
function (Configuring $event) {
|
||||
call_user_func($this->callback, $event->configurator);
|
||||
}
|
||||
);
|
||||
|
||||
// Also set up an event listener to flush the formatter cache whenever
|
||||
// this extension is enabled or disabled.
|
||||
$events->listen(
|
||||
[Enabled::class, Disabled::class],
|
||||
function ($event) use ($container, $extension) {
|
||||
if ($event->extension === $extension) {
|
||||
$container->make(ActualFormatter::class)->flush();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
@@ -1,37 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Extend;
|
||||
|
||||
use Flarum\Extension\Extension;
|
||||
use Flarum\Formatter\Event\Configuring;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use Illuminate\Events\Dispatcher;
|
||||
|
||||
class FormatterConfiguration implements ExtenderInterface
|
||||
{
|
||||
protected $callback;
|
||||
|
||||
public function __construct(callable $callback)
|
||||
{
|
||||
$this->callback = $callback;
|
||||
}
|
||||
|
||||
public function __invoke(Container $container, Extension $extension = null)
|
||||
{
|
||||
$container->make(Dispatcher::class)->listen(
|
||||
Configuring::class,
|
||||
function (Configuring $event) {
|
||||
call_user_func($this->callback, $event->configurator);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
@@ -107,8 +107,8 @@ abstract class AbstractFrontend
|
||||
$root = __DIR__.'/../..';
|
||||
$name = $this->getName();
|
||||
|
||||
$view->getJs()->addFile("$root/js/$name/dist/app.js");
|
||||
$view->getCss()->addFile("$root/less/$name/app.less");
|
||||
$view->getJs()->addFile("$root/js/dist/$name.js");
|
||||
$view->getCss()->addFile("$root/less/$name.less");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -11,11 +11,7 @@
|
||||
|
||||
namespace Flarum\Frontend\Asset;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Cache\Repository;
|
||||
use MatthiasMullie\Minify;
|
||||
use s9e\TextFormatter\Configurator;
|
||||
use s9e\TextFormatter\Configurator\JavaScript\Minifiers\FirstAvailable;
|
||||
|
||||
class JsCompiler extends RevisionCompiler
|
||||
{
|
||||
@@ -42,14 +38,6 @@ class JsCompiler extends RevisionCompiler
|
||||
*/
|
||||
protected function format($string)
|
||||
{
|
||||
if (! $this->watch) {
|
||||
$key = 'js.'.sha1($string);
|
||||
|
||||
$string = $this->cache->rememberForever($key, function () use ($string) {
|
||||
return $this->minify($string);
|
||||
});
|
||||
}
|
||||
|
||||
return $string.";\n";
|
||||
}
|
||||
|
||||
@@ -60,59 +48,4 @@ class JsCompiler extends RevisionCompiler
|
||||
{
|
||||
return $this->watch;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $source
|
||||
* @return string
|
||||
*/
|
||||
protected function minify($source)
|
||||
{
|
||||
set_time_limit(60);
|
||||
|
||||
try {
|
||||
$source = $this->minifyWithClosureCompilerService($source);
|
||||
} catch (Exception $e) {
|
||||
$source = $this->minifyWithFallback($source);
|
||||
}
|
||||
|
||||
return $source;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $source
|
||||
* @return string
|
||||
*/
|
||||
protected function minifyWithClosureCompilerService($source)
|
||||
{
|
||||
// The minifier may need some classes bundled with the Configurator so we autoload it
|
||||
class_exists(Configurator::class);
|
||||
|
||||
$minifier = new FirstAvailable;
|
||||
|
||||
$remoteCache = $minifier->add('RemoteCache');
|
||||
$remoteCache->url = 'http://s9e-textformatter.rhcloud.com/flarum-minifier/';
|
||||
|
||||
$hostedMinifer = $minifier->add('HostedMinifier');
|
||||
$hostedMinifer->url = 'http://s9e-textformatter.rhcloud.com/flarum-minifier/';
|
||||
$hostedMinifer->httpClient->timeout = 30;
|
||||
|
||||
$ccs = $minifier->add('ClosureCompilerService');
|
||||
$ccs->compilationLevel = 'SIMPLE_OPTIMIZATIONS';
|
||||
$ccs->httpClient->timeout = 30;
|
||||
|
||||
$minifier->add('MatthiasMullieMinify');
|
||||
|
||||
return $minifier->minify($source);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $source
|
||||
* @return string
|
||||
*/
|
||||
protected function minifyWithFallback($source)
|
||||
{
|
||||
$minifier = new Minify\JS($source);
|
||||
|
||||
return $minifier->minify();
|
||||
}
|
||||
}
|
||||
|
@@ -22,23 +22,12 @@ class LocaleJsCompiler extends JsCompiler
|
||||
|
||||
public function compile()
|
||||
{
|
||||
$output = "
|
||||
System.register('locale', [], function(_export) {
|
||||
return {
|
||||
execute: function() {
|
||||
_export('default', function(app) {
|
||||
app.translator.translations = ".json_encode($this->translations).";\n";
|
||||
$output = 'flarum.core.app.translator.translations='.json_encode($this->translations).";\n";
|
||||
|
||||
foreach ($this->files as $filename) {
|
||||
$output .= file_get_contents($filename);
|
||||
}
|
||||
|
||||
$output .= '
|
||||
});
|
||||
}
|
||||
};
|
||||
});';
|
||||
|
||||
return $this->format($output);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user