Skip to content
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

Add support for custom renderers #164

Open
wants to merge 5 commits into
base: 1.x
Choose a base branch
from

Conversation

WendellAdriel
Copy link
Contributor

@WendellAdriel WendellAdriel commented Feb 2, 2023

I saw that Termwind has some default renderers for some elements:

  • TableRenderer
  • PreRenderer
  • CodeRenderer

The purpose of this PR is to allow users to register Custom Renderers if they want. This can be a nice addition for developers that want to create plugins, so they can create their own custom renderers.

The general idea is to have a new contract Renderer that must be implemented for all renderers and the actual render will be done by the new class ElementRenderer that can be used to register new renderers and to use the registered renderers to render the content.

I'm marking this as a Draft because I still need to know if this is something that you want to have in the project and if so I can work on modifying anything that's not "compatible" with what you're thinking for the project.

If this is not something you want in the project feel free to decline this, but if you think this can work, I'll be happy to work on any changes needed to have this merged. 😉 💪🏼 🔥

src/Html/ElementRenderer.php Outdated Show resolved Hide resolved
src/Html/ElementRenderer.php Outdated Show resolved Hide resolved
@WendellAdriel
Copy link
Contributor Author

Thanks for the review @jdreesen!
I made the changes you pointed out and also added a new test case to test that when registering an invalid renderer an exception is thrown! 💪🏼

@WendellAdriel WendellAdriel changed the title [WIP] - Add support for custom renderers Add support for custom renderers Feb 3, 2023
@WendellAdriel WendellAdriel marked this pull request as ready for review February 3, 2023 10:15
@WendellAdriel
Copy link
Contributor Author

@xiCO2k @nunomaduro I think the PR is now looking good for a final review

@WendellAdriel
Copy link
Contributor Author

I didn't add in the PR but if you think it could be something useful I can create a function registerRenderer that can be imported and used like the style function that will wrap the register method from the ElementRenderer class so I can mark the ElementRenderer as an internal class.

@WendellAdriel
Copy link
Contributor Author

I didn't add in the PR but if you think it could be something useful I can create a function registerRenderer that can be imported and used like the style function that will wrap the register method from the ElementRenderer class so I can mark the ElementRenderer as an internal class.

I added the registerRenderer function now, marked the ElementRenderer class as internal and updated the test suite to use the registerRenderer function.

@nunomaduro nunomaduro changed the base branch from master to 1.x October 10, 2023 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants