Download the PHP package pre/phpx without Composer
On this page you can find all versions of the php package pre/phpx. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package phpx
Phpx
Documentation can be found at preprocess.io.
Motivation
I wanted to write a custom compiler, and this syntax appeals to me. It's not a replacement for Javascript, or even a very good implementation. But, I like it. That's all that counts.
If you want to write component-based code, without writing Javascript; then this might work for you.
Getting started
- Clone the repository
- Install the Compoer dependencies
- Run the tests or execute the example scripts
This should work on PHP 7.2 (where it was developed and tested). Make an issue if it's not working on 7.2 or if you'd like to see things added.
What does it render?
The goal was to decouple the compiler from the renderers. Once the Pre\Phpx\Html renderer moves out, you'll need to import it into your project or create a custom render
function. The Pre\Phpx\Html render
function looks like this:
This means you can define your own namespaced functions and classes, and use them in the Pre\Phpx\Html render
function, like:
If you'd prefer to have your components automatically prefixed, define your own render
function, You can extend the Pre\Phpx\Html render
function:
You can define components as functions or classes:
Since you can define a custom render function, you can decide what your components are allowed to return. HTML-in-PHP syntax is converted to the following form:
You decide what your components return and what your render
function does. The Pre\Phpx\Html render
function outputs strings of HTML, and expects components rendered by it to return strings (so that they can be concatenated in an array of children).
Returning
null
will also work.
Roadmap
- [ ] Support HTML tag warnings and rewriting
- [ ] Move HTML renderer to its own library
- [ ] Set up StyleCI and Travis
- [ ] Write more tests
- [ ] Experiment with other renderers
- [ ] Document like it's 1999