rmorse / babel-plugin-jsx-template-vars

A Babel transform for rendering a template version of your React / Preact app. Useful for generating a pre-render for SSR.
MIT License
10 stars 0 forks source link

Add support for generating valid PHP and custom languages #6

Open rmorse opened 2 years ago

rmorse commented 2 years ago

It would be a good idea to skip handlebars altogether - *but still support handlebars for those that need it - I imagine there will be a bunch of nuances we might not be able to work around in many languages so handlebars is a good fallback.

So instead of adding handlebars tags, we can add PHP code instead, which means we would need save the output to a .php file.

This will be done by defining a "language".

At this point, it would also be good to allow for custom languages too - so we can support many more languages out of the box, as well as well as allow for custom esacaping functions...

Probably at 90% completion with the PHP implementation:

https://user-images.githubusercontent.com/853547/169329421-7a87a56e-3f5b-4166-8fea-e40d98096c74.mp4

The only issue with this is that the opening / closing PHP tags are getting html encoded... but we could just swap them back when we save the html output to a PHP file...

TODO: We still have handlebars tags in the list type variables (inside the loops)...

rmorse commented 2 years ago

This is pretty much finished in v0.0.5... however we have the encoding issue with the opening and closing PHP tags remaining...

I think we should not use PHP tags but instead placeholders like:

||open_tag|| and ||close_tag||

Would be good to add in v0.0.6...

Then it should be trivial to replace these when saving the output to a PHP file.