1
0
mirror of https://github.com/flarum/core.git synced 2025-08-01 14:10:37 +02:00

feat: add Less custom function extender, is-extension-enabled function (#3190)

Co-authored-by: luceos <luceos@users.noreply.github.com>
Co-authored-by: Sami Mazouz <sychocouldy@gmail.com>
This commit is contained in:
David Wheatley
2021-12-14 19:25:39 +00:00
committed by GitHub
parent eb7382b672
commit fbfc80f979
6 changed files with 129 additions and 2 deletions

View File

@@ -0,0 +1,7 @@
.dummy_func_test when (is-flarum("flarum") = true) {
color: green;
}
.dummy_func_test2 {
--x: is-flarum("not flarum") * 10;
--y: is-gt(1, 2);
}

View File

@@ -104,4 +104,32 @@ class ThemeTest extends TestCase
$this->assertStringContainsString('Less_Exception_Compiler', $response->getBody()->getContents());
$this->assertEquals(500, $response->getStatusCode());
}
/**
* @test
*/
public function theme_extender_can_add_custom_function()
{
$this->extend(
(new Extend\Frontend('forum'))
->css(__DIR__.'/../../fixtures/less/custom_function.less'),
(new Extend\Theme)
->addCustomLessFunction('is-flarum', function ($text) {
return strtolower($text) === 'flarum' ? 'true' : 100;
})
->addCustomLessFunction('is-gt', function ($a, $b) {
return $a > $b;
})
);
$response = $this->send($this->request('GET', '/'));
$this->assertEquals(200, $response->getStatusCode());
$cssFilePath = $this->app()->getContainer()->make('filesystem')->disk('flarum-assets')->path('forum.css');
$contents = file_get_contents($cssFilePath);
$this->assertStringContainsString('.dummy_func_test{color:green}', $contents);
$this->assertStringContainsString('.dummy_func_test2{--x:1000;--y:false}', $contents);
}
}