gjerokrsteski / pimf-framework

Micro framework for PHP that emphasises minimalism and simplicity
pimf-framework.de
MIT License
43 stars 16 forks source link

Added adapter for Transphporm template engine #27

Closed garrettw closed 7 years ago

garrettw commented 7 years ago

Level-2/Transphporm is my favorite templating engine, so I made an adapter for Pimf so that I could use them together. Please note that the underlying API is slightly different from Twig and Haanga. Here is an example of the API using code from the Twig/Haanga app templates.

$view = new View('blog.xml', [
    'tss' => 'hello.tss',
    'data' => [    // the 'data' param is optional; depends on whether your TSS file requires it
        'blog_title'   => 'Welcome to PIMF Twig bundle',
        'blog_content' => 'Hello '.join(' ', (array)$firstname).'!!!',
        'blog_footer'  => 'Please type at the URL "/hello/Barry" and see what happens!',
    ]
]);

Here is the content of hello.tss. Of course, this is a very simplified example and Transphporm is capable of much more.

title, header h1 { content: data(blog_title); }
h2 { content: data(blog_content); }
footer p strong { content: data(blog_footer); }

And finally, here is the content of blog.xml just to show what's going on.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>This title will be replaced by Transphporm.</title>
</head>
<body>
  <header>
      <h1>You will never see this blog title text</h1>
  </header>
  <h2>Here is some lorem ipsum text for the blog content.</h2>
  <footer>
        <p>
          <strong>Some footer text just to test it with.</strong>
        </p>
  </footer>
</body>
</html>
gjerokrsteski commented 7 years ago

Hey sounds good. If there is a great need for Transphorm, why not. I will check that out and if all is fine, i will create a new pimf-Transphorm bundle. OK?

gjerokrsteski commented 7 years ago

Review: please register the Transphporm class for autoloading at autoload.core.phpfile.

garrettw commented 7 years ago

Done.

If there is a great need for Transphorm, why not.

I'm sure there's not a great need; a lot of people know and use Twig. However, you have included an engine called Haanga which is not widely known, and it caters to a niche audience that is comfortable with Django templating syntax. So I thought adding Transphporm would be useful because it caters to developers who (1) dislike popular engines, like Twig, that mix logic with markup and (2) are comfortable with using CSS syntax to transform HTML.

My philosophy about adding template engines is that we should include the most popular ones (to make it easier for developers coming from other frameworks), and then we should also include some that are not well known but that either (1) use improved design principles compared to the popular ones or (2) satisfy the needs of a special niche better than the popular ones. Haanga would fall under (2), and Transphporm probably falls mostly under (1) and a bit under (2).

Once you create a bundle for it, I would be happy to get it fully working for you. Or if you prefer, I can go ahead and create the bundle under my own account and then you could either link to it or fork it.

gjerokrsteski commented 7 years ago

Thank you for taking time and writing that great argumettaion. I have similar opinion to Transphporm. And yes, please go ahead and create the bundle under your own account.

Before that I would like to release pimf v1.10.1 inluding all your improvements:

  1. Or should I wait til all improvements from issue #23 are made?
  2. The support of Transphporm will be released shortlty after v1.10.1 with the v1.11.0 version, OK?
garrettw commented 7 years ago

I would say do not wait for #23 to be completed, because the changes listed there WILL break backward compatibility and therefore it will have to start out as v2.0-alpha. So you can release the other fixes now if you want.

gjerokrsteski commented 7 years ago

Now there is PIMF v1.11.0-alpha awaylable that includes support of Transphporm template engine. Please create a bundle and give me a feedback if all is fine. After that i will release v1.11.0 and will write a blog posts to promote the release.

garrettw commented 7 years ago

Ok. I will let you know after I am able to test it successfully.