-
-
Notifications
You must be signed in to change notification settings - Fork 834
/
FrontendServiceProvider.php
99 lines (80 loc) · 3.22 KB
/
FrontendServiceProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Frontend;
use Flarum\Foundation\AbstractServiceProvider;
use Flarum\Foundation\Paths;
use Flarum\Frontend\Compiler\Source\SourceCollector;
use Flarum\Http\UrlGenerator;
use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Contracts\View\Factory as ViewFactory;
class FrontendServiceProvider extends AbstractServiceProvider
{
public function register()
{
$this->app->singleton('flarum.assets.factory', function () {
return function (string $name) {
$paths = $this->app[Paths::class];
$assets = new Assets(
$name,
$this->app->make('filesystem')->disk('flarum-assets'),
$paths->storage
);
$assets->setLessImportDirs([
$paths->vendor.'/components/font-awesome/less' => ''
]);
$assets->css([$this, 'addBaseCss']);
$assets->localeCss([$this, 'addBaseCss']);
return $assets;
};
});
$this->app->singleton('flarum.frontend.factory', function () {
return function (string $name) {
$frontend = $this->app->make(Frontend::class);
$frontend->content(function (Document $document) use ($name) {
$document->layoutView = 'flarum::frontend.'.$name;
});
$frontend->content($this->app->make(Content\Assets::class)->forFrontend($name));
$frontend->content($this->app->make(Content\CorePayload::class));
$frontend->content($this->app->make(Content\Meta::class));
return $frontend;
};
});
}
/**
* {@inheritdoc}
*/
public function boot()
{
$this->loadViewsFrom(__DIR__.'/../../views', 'flarum');
$this->app->make(ViewFactory::class)->share([
'translator' => $this->app->make('translator'),
'url' => $this->app->make(UrlGenerator::class)
]);
}
public function addBaseCss(SourceCollector $sources)
{
$sources->addFile(__DIR__.'/../../less/common/variables.less');
$sources->addFile(__DIR__.'/../../less/common/mixins.less');
$this->addLessVariables($sources);
}
private function addLessVariables(SourceCollector $sources)
{
$sources->addString(function () {
$settings = $this->app->make(SettingsRepositoryInterface::class);
$vars = [
'config-primary-color' => $settings->get('theme_primary_color', '#000'),
'config-secondary-color' => $settings->get('theme_secondary_color', '#000'),
'config-dark-mode' => $settings->get('theme_dark_mode') ? 'true' : 'false',
'config-colored-header' => $settings->get('theme_colored_header') ? 'true' : 'false'
];
return array_reduce(array_keys($vars), function ($string, $name) use ($vars) {
return $string."@$name: {$vars[$name]};";
}, '');
});
}
}