Create generic end action to more easily create custom actions#1306
Create generic end action to more easily create custom actions#1306oiseauroch wants to merge 4 commits intodoryphore-devfrom
Conversation
|
a new custom action can now be written as : <?php
use YesWiki\Core\YesWikiAction;
class ColorAction extends YesWikiAction
{
public function run()
{
$class = $this->arguments['class'] ?? '';
$color = $this->arguments['color'] ?? (empty($class) ? 'var(--neutral-color)': 'var(--' . $class . ')' );
if ($this->check_end_elem('color')) {
return "<span class='color-elem' style='color: $color;'>";
} else {
return $this->generate_error_msg('color');
}
}
public function end(): string {
return '</span>';
}
}and use like this : {{color color="#FFFFFF"}}
my colored text
{{end elem="color"}} |
|
Hi @oiseauroch ! I think we should change all existing actions using end before merging. Also i have some minor changes to propose like coding styles (class Method should be camelCased(), we no 🦀 ) Do you plan to come to Lyon for yeswiki sprint in march? Regards |
|
Nice !
It's not a little work because all actions using end are not yet class of YesWikiAction and then should be heavily tested. Feel free to rework this PR as you want. I'm not sure about how do you want to do with error raising in checkEndElem(). I'm not sure for the sprint in March but could you remind me the date ? |
|
Current behavior
Creating a new component with body and then as a closing
{{end elem="mycustomelement" }} element require to add code in the core of yeswiki to add **customelement** intoend.php` file.Expected behavior
I would like to be ablo to add a custom element without modifying something that could be removed by update.
Proposal
We could had a default case for end element that look for a
end()fonction in the extra YesWiki action like this :