-
-
Notifications
You must be signed in to change notification settings - Fork 15
[FEATURE] add youtube directive #848
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
66 changes: 66 additions & 0 deletions
66
packages/guides-restructured-text/src/RestructuredText/Directives/YoutubeDirective.php
This file contains hidden or 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,66 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * This file is part of phpDocumentor. | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| * | ||
| * @link https://phpdoc.org | ||
| */ | ||
|
|
||
| namespace phpDocumentor\Guides\RestructuredText\Directives; | ||
|
|
||
| use phpDocumentor\Guides\Nodes\EmbeddedFrame; | ||
| use phpDocumentor\Guides\RestructuredText\Parser\BlockContext; | ||
| use phpDocumentor\Guides\RestructuredText\Parser\Directive; | ||
|
|
||
| use function array_filter; | ||
|
|
||
| /** | ||
| * This directive is used to embed a youtube video in the document. | ||
| * | ||
| * Basic usage | ||
| * | ||
| * ```rst | ||
| * .. youtube:: dQw4w9WgXcQ | ||
| * ``` | ||
| * | ||
| * Options: | ||
| * | ||
| * - string title The title of the video | ||
| * - int width The width of the video, default is 560 | ||
| * - int height The height of the video, default is 315 | ||
| * - string allow The allow attribute of the iframe, default is 'encrypted-media; picture-in-picture; web-share' | ||
| * - bool allowfullscreen Whether the video should be allowed to go fullscreen, default is true | ||
| */ | ||
| final class YoutubeDirective extends BaseDirective | ||
| { | ||
| public function getName(): string | ||
| { | ||
| return 'youtube'; | ||
| } | ||
|
|
||
| public function process( | ||
| BlockContext $blockContext, | ||
| Directive $directive, | ||
| ): EmbeddedFrame { | ||
| $node = new EmbeddedFrame( | ||
| 'https://www.youtube-nocookie.com/embed/' . $directive->getData(), | ||
| ); | ||
|
|
||
| return $node->withOptions( | ||
| array_filter( | ||
| [ | ||
| 'width' => $directive->getOption('width')->getValue() ?? 560, | ||
| 'title' => $directive->getOption('title')->getValue(), | ||
| 'height' => $directive->getOption('height')->getValue() ?? 315, | ||
| 'allow' => $directive->getOption('allow')->getValue() ?? 'encrypted-media; picture-in-picture; web-share', | ||
| 'allowfullscreen' => (bool) ($directive->getOption('allowfullscreen')->getValue() ?? true), | ||
| ], | ||
| ), | ||
| ); | ||
| } | ||
| } | ||
8 changes: 8 additions & 0 deletions
8
packages/guides/resources/template/html/body/embedded-frame.html.twig
This file contains hidden or 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,8 @@ | ||
| <iframe src="{{ node.url }}" | ||
| {%- if node.hasOption('width') %} width="{{ node.option('width') }}"{% endif -%} | ||
| {%- if node.hasOption('height') %} height="{{ node.option('height') }}"{% endif -%} | ||
| {%- if node.hasOption('title') %} title="{{ node.option('title') }}"{% endif -%} | ||
| {%- if node.hasOption('allow') %} allow="{{ node.option('allow') }}"{% endif -%} | ||
| {%- if node.hasOption('allowfullscreen') and node.option('allowfullscreen') %} allowfullscreen{% endif -%} | ||
| > | ||
| </iframe> |
This file contains hidden or 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 hidden or 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,28 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * This file is part of phpDocumentor. | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| * | ||
| * @link https://phpdoc.org | ||
| */ | ||
|
|
||
| namespace phpDocumentor\Guides\Nodes; | ||
|
|
||
| final class EmbeddedFrame extends TextNode | ||
| { | ||
| public function __construct( | ||
| private readonly string $url, | ||
| ) { | ||
| parent::__construct($url); | ||
| } | ||
|
|
||
| public function getUrl(): string | ||
| { | ||
| return $this->url; | ||
| } | ||
| } |
6 changes: 5 additions & 1 deletion
6
tests/Integration/tests/directives/youtube/expected/index.html
This file contains hidden or 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 |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| <!-- content start --> | ||
| .. youtube:: dtRKsxzjKj0 | ||
| <div class="section" id="document-title"> | ||
| <h1>Document Title</h1> | ||
|
|
||
| <iframe src="https://www.youtube-nocookie.com/embed/hdDD0SNJ-pk" width="560" height="315" title="PHP DocBlock - Adding Comments to Classes & Methods" allow="encrypted-media; picture-in-picture; web-share" allowfullscreen> | ||
| </iframe> | ||
|
|
||
| </div> | ||
| <!-- content end --> |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,2 +1,6 @@ | ||
| ============== | ||
| Document Title | ||
| ============== | ||
|
|
||
| .. youtube:: dtRKsxzjKj0 | ||
| .. youtube:: hdDD0SNJ-pk | ||
| :title: PHP DocBlock - Adding Comments to Classes & Methods |
Empty file.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.