-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added extension node (used in Confluence documents)
- Loading branch information
1 parent
b7bb3d7
commit ce1fce9
Showing
9 changed files
with
218 additions
and
0 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,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DH\Adf\Builder; | ||
|
||
use DH\Adf\Node\Inline\Extension; | ||
|
||
trait ExtensionBuilder | ||
{ | ||
public function extension( | ||
string $layout, | ||
string $extensionType, | ||
string $extensionKey, | ||
array $parameters, | ||
string $localId | ||
): self { | ||
$mention = new Extension($layout, $extensionType, $extensionKey, $parameters, $localId); | ||
$this->append($mention); | ||
|
||
return $this; | ||
} | ||
} |
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,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DH\Adf\Exporter\Html\Inline; | ||
|
||
use DH\Adf\Exporter\Html\HtmlExporter; | ||
use DH\Adf\Node\Inline\Extension; | ||
|
||
class ExtensionExporter extends HtmlExporter | ||
{ | ||
public function export(): string | ||
{ | ||
\assert($this->node instanceof Extension); | ||
|
||
return '<div class="adf-extension">The contents of the extension cannot be exported.</div>'; | ||
} | ||
} |
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,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DH\Adf\Node\Inline; | ||
|
||
use DH\Adf\Node\InlineNode; | ||
|
||
class Extension extends InlineNode | ||
{ | ||
protected string $type = 'extension'; | ||
private string $layout; | ||
private string $extensionType; | ||
private string $extensionKey; | ||
private array $parameters; | ||
private string $localId; | ||
|
||
public function __construct( | ||
string $layout, | ||
string $extensionType, | ||
string $extensionKey, | ||
array $parameters, | ||
string $localId | ||
) { | ||
$this->layout = $layout; | ||
$this->extensionType = $extensionType; | ||
$this->extensionKey = $extensionKey; | ||
$this->parameters = $parameters; | ||
$this->localId = $localId; | ||
} | ||
|
||
protected function attrs(): array | ||
{ | ||
$attrs = parent::attrs(); | ||
$attrs['layout'] = $this->layout; | ||
$attrs['extensionType'] = $this->extensionType; | ||
$attrs['extensionKey'] = $this->extensionKey; | ||
if ($this->parameters) { | ||
$attrs['parameters'] = $this->parameters; | ||
} | ||
$attrs['localId'] = $this->localId; | ||
|
||
return $attrs; | ||
} | ||
} |
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,105 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DH\Adf\Tests\Node\Inline; | ||
|
||
use DH\Adf\Node\Block\Document; | ||
use DH\Adf\Node\Inline\Extension; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @internal | ||
* | ||
* @small | ||
*/ | ||
final class ExtensionTest extends TestCase | ||
{ | ||
public function testExtension(): void | ||
{ | ||
$extension = new Extension( | ||
'default', | ||
'com.atlassian.confluence.macro.core', | ||
'toc', | ||
[ | ||
'macroParams' => [ | ||
'minLevel' => [ | ||
'value' => '1', | ||
], | ||
'maxLevel' => [ | ||
'value' => '3', | ||
], | ||
'outline' => [ | ||
'value' => 'false', | ||
], | ||
'type' => [ | ||
'value' => 'list', | ||
], | ||
'printable' => [ | ||
'value' => 'false', | ||
], | ||
], | ||
], | ||
'123cad9c-95d8-49df-8b99-00886ba0af5d', | ||
); | ||
$doc = $extension->toJson(); | ||
|
||
self::assertJsonStringEqualsJsonString($doc, json_encode([ | ||
'type' => 'extension', | ||
'attrs' => [ | ||
"extensionKey" => "toc", | ||
"extensionType" => "com.atlassian.confluence.macro.core", | ||
"layout" => "default", | ||
"localId" => "123cad9c-95d8-49df-8b99-00886ba0af5d", | ||
"parameters" => [ | ||
"macroParams" => [ | ||
"maxLevel" => [ | ||
"value" => "3" | ||
], | ||
"minLevel" => [ | ||
"value" => "1" | ||
], | ||
"outline" => [ | ||
"value" => "false" | ||
], | ||
"printable" => [ | ||
"value" => "false" | ||
], | ||
"type" => [ | ||
"value" => "list" | ||
] | ||
] | ||
], | ||
], | ||
])); | ||
} | ||
|
||
public function testExtensionToDocument(): void | ||
{ | ||
$doc = (new Document()) | ||
->extension( | ||
'default', | ||
'com.atlassian.confluence.macro.core', | ||
'toc', | ||
[], | ||
'123cad9c-95d8-49df-8b99-00886ba0af5d', | ||
) | ||
->toJson(); | ||
|
||
self::assertJsonStringEqualsJsonString($doc, json_encode([ | ||
'version' => 1, | ||
'type' => 'doc', | ||
'content' => [ | ||
[ | ||
'type' => 'extension', | ||
'attrs' => [ | ||
"extensionKey" => "toc", | ||
"extensionType" => "com.atlassian.confluence.macro.core", | ||
"layout" => "default", | ||
"localId" => "123cad9c-95d8-49df-8b99-00886ba0af5d" | ||
], | ||
], | ||
], | ||
])); | ||
} | ||
} |