-
-
Notifications
You must be signed in to change notification settings - Fork 319
Expand file tree
/
Copy pathCode.php
More file actions
48 lines (40 loc) · 1.22 KB
/
Code.php
File metadata and controls
48 lines (40 loc) · 1.22 KB
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
<?php
declare(strict_types = 1);
namespace Embed\Adapters\Sassmeister\Detectors;
use Embed\Detectors\Code as Detector;
use Embed\EmbedCode;
use function Embed\html;
use function Embed\matchPath;
/**
* @extends Detector<\Embed\Adapters\Sassmeister\Extractor>
*/
class Code extends Detector
{
public function detect(): ?EmbedCode
{
$result = parent::detect();
return $result !== null ? $result : $this->fallback();
}
private function fallback(): ?EmbedCode
{
$uri = $this->extractor->getUri();
if (!matchPath('/gist/*', $uri->getPath())) {
return null;
}
$id = explode('/', $uri->getPath())[2];
$height = 480;
$html = [
html('p', [
'class' => 'sassmeister',
'data-gist-id' => $id,
'data-height' => $height,
'data-theme' => 'tomorrow',
], '<a href="http://sassmeister.com/gist/'.$id.'">Play with this gist on SassMeister.</a>'),
html('script', [
'src' => 'http://cdn.sassmeister.com/js/embed.js',
'async' => true,
]),
];
return new EmbedCode(implode('', $html), null, $height);
}
}