-
-
Notifications
You must be signed in to change notification settings - Fork 826
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[1.x] Theme Extender to Allow overriding
LESS
files (#3008)
This PR introduces the ability to just override a LESS file's contents through an extender. This is mainly useful for theme development, as there are times in extensively customized themes where overriding the actual file makes a huge difference vs overriding CSS styles which can turn into a maintenance hell real fast. Overriding styles is more tedious than overriding files. When you're designing an element, you would normally rather start from a blank canvas, than a styled element. With an already styled element you have to first override and undo the styles you do not wish to have, only then can you start shaping it, but even then you'd always end up constantly undoing default styles. This mostly applies for more advanced themes. (example: https://github.com/afrux/asirem/blob/851c55516d2ab279928a0a0318ca40d49644dd98/less/forum/DiscussionList.less)
- Loading branch information
Showing
11 changed files
with
313 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?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\Extend; | ||
|
||
use Flarum\Extension\Extension; | ||
use Flarum\Frontend\Assets; | ||
use Illuminate\Contracts\Container\Container; | ||
|
||
class Theme implements ExtenderInterface | ||
{ | ||
private $lessImportOverrides = []; | ||
private $fileSourceOverrides = []; | ||
|
||
/** | ||
* This can be used to override LESS files that are imported within the code. | ||
* For example, core's `forum.less` file imports a `forum/DiscussionListItem.less` file. | ||
* The contents of this file can be overriden with this method. | ||
* | ||
* @param string $file : Relative path of the file to override, for example: `forum/Hero.less` | ||
* @param string $newFilePath : Absolute path of the new file. | ||
* @param string|null $extensionId : If overriding an extension file, specify its ID, for example: `flarum-tags`. | ||
* @return self | ||
*/ | ||
public function overrideLessImport(string $file, string $newFilePath, string $extensionId = null): self | ||
{ | ||
$this->lessImportOverrides[] = compact('file', 'newFilePath', 'extensionId'); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* This method allows overriding LESS file sources. | ||
* For example `forum.less`, `admin.less`, `mixins.less` and `variables.less` are file sources, | ||
* and can therefore be overriden using this method. | ||
* | ||
* @param string $file : Name of the file to override, for example: `admin.less` | ||
* @param string $newFilePath : Absolute path of the new file. | ||
* @param string|null $extensionId : If overriding an extension file, specify its ID, for example: `flarum-tags`. | ||
* @return self | ||
*/ | ||
public function overrideFileSource(string $file, string $newFilePath, string $extensionId = null): self | ||
{ | ||
$this->fileSourceOverrides[] = compact('file', 'newFilePath', 'extensionId'); | ||
|
||
return $this; | ||
} | ||
|
||
public function extend(Container $container, Extension $extension = null) | ||
{ | ||
$container->extend('flarum.assets.factory', function (callable $factory) { | ||
return function (...$args) use ($factory) { | ||
/** @var Assets $assets */ | ||
$assets = $factory(...$args); | ||
|
||
$assets->addLessImportOverrides($this->lessImportOverrides); | ||
$assets->addFileSourceOverrides($this->fileSourceOverrides); | ||
|
||
return $assets; | ||
}; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.Imported { | ||
// ... | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.dummy_test_case{color:red} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@import 'Imported'; | ||
|
||
.dummy { | ||
color: yellow; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
body { | ||
color: orange; | ||
} |
Oops, something went wrong.