Skip to content

Commit 2266eaf

Browse files
committed
Added pastie.org support #156
1 parent d43ee90 commit 2266eaf

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

src/Adapters/Pastie.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Embed\Adapters;
4+
5+
use Embed\Request;
6+
use Embed\Utils;
7+
8+
/**
9+
* Adapter to generate embed code from pastie.org.
10+
*/
11+
class Pastie extends Webpage implements AdapterInterface
12+
{
13+
/**
14+
* {@inheritdoc}
15+
*/
16+
public static function check(Request $request)
17+
{
18+
return $request->isValid() && $request->match([
19+
'http://pastie.org/pastes/*',
20+
]);
21+
}
22+
23+
/**
24+
* {@inheritdoc}
25+
*/
26+
public function getCode()
27+
{
28+
$this->width = null;
29+
$this->height = null;
30+
31+
$path = '/'.$this->request->getDirectoryPosition(1).'.js';
32+
33+
return Utils::script($this->request->createUrl($path)->getUrl());
34+
}
35+
}

src/Utils.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,20 @@ public static function iframe($src, $width = 0, $height = 0, $styles = '')
336336
]).'</iframe>';
337337
}
338338

339+
/**
340+
* Creates an <script> element.
341+
*
342+
* @param string $src The src attribute
343+
*
344+
* @return string
345+
*/
346+
public static function script($src)
347+
{
348+
return self::element('script', [
349+
'src' => $src,
350+
]).'</script>';
351+
}
352+
339353
/**
340354
* Creates an <iframe> element with a google viewer.
341355
*

tests/PastieTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
class PastieTest extends TestCaseBase
4+
{
5+
public function testOne()
6+
{
7+
$this->assertEmbed(
8+
'http://pastie.org/pastes/10916298',
9+
[
10+
'title' => '#10916298 - Pastie',
11+
'type' => 'rich',
12+
'providerName' => 'pastie',
13+
'providerUrl' => 'http://pastie.org',
14+
'code' => '<script src="http://pastie.org/10916298.js"></script>'
15+
]
16+
);
17+
}
18+
}

0 commit comments

Comments
 (0)