-
-
Notifications
You must be signed in to change notification settings - Fork 364
[TwigComponent] new twig_component tag and slot #873
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
Closed
WebMamba
wants to merge
13
commits into
symfony:2.x
from
WebMamba:matheo/twig_component_slot_approach
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
33ef6ae
[TwigComponent] new twig_component tag and slot
WebMamba bfa351d
apply fixer
WebMamba 18a7cd7
add return type
WebMamba 30d48af
add tests and some fix
WebMamba 4ebc9d8
add thanks @giorgiopogliani
WebMamba ac7589f
fix
WebMamba e573059
add more test
c74271b
mixing slots and blocks
WebMamba 71ae7ad
small fix on test
WebMamba c6312ae
add slots variables
WebMamba fdeb357
use ComponentAttribute instead of AttributeBag
WebMamba e3eab50
remove twig_component tag and move slot logic into component tag
WebMamba 315ec1b
add slot varialble
WebMamba 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
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
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,69 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\UX\TwigComponent\Twig; | ||
|
||
use Symfony\UX\TwigComponent\ComponentAttributes; | ||
|
||
/** | ||
* thanks to @giorgiopogliani! | ||
* This file is inspired by: https://github.com/giorgiopogliani/twig-components. | ||
* | ||
* @author Mathéo Daninos <matheo.daninos@gmail.com> | ||
* | ||
* @internal | ||
*/ | ||
class ComponentSlot | ||
{ | ||
public ComponentAttributes $attributes; | ||
|
||
protected string $contents; | ||
|
||
public function __construct(string $contents = '', array $attributes = []) | ||
{ | ||
$this->contents = $contents; | ||
|
||
$this->withAttributes($attributes); | ||
} | ||
|
||
public function withAttributes(array $attributes): self | ||
{ | ||
$this->attributes = new ComponentAttributes($attributes); | ||
|
||
return $this; | ||
} | ||
|
||
public function withContext(array $contexts): void | ||
{ | ||
$content = $this->contents; | ||
|
||
foreach ($contexts as $key => $value) { | ||
$content = str_replace("<slot_value name=\"$key\"/>", $value, $content); | ||
} | ||
|
||
$this->contents = $content; | ||
} | ||
|
||
public function toHtml(): string | ||
{ | ||
return $this->contents; | ||
} | ||
|
||
public function isEmpty(): bool | ||
{ | ||
return '' === $this->contents; | ||
} | ||
|
||
public function __toString() | ||
{ | ||
return $this->toHtml(); | ||
} | ||
} |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You want to return null here now instead of an exception? Is that for the Antonio’ anonymous components?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes exactly! If we don't find a corresponding component then we try to render it as anonymous
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about the ability to distinguish attributes from properties for anon components as discussed here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I missed your comment. If you look at the test I used |default to reproduce the behavior we discussed. But maybe I can add this tag in a follow-up PR if this one gets merged.