Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsShowcase → Transphporm - A different kind of template engine
Transphporm - A different kind of template engine
2016-01-06, 4:37 PM #1
This isn't at all JK related but I thought I'd post it anyway!

I wrote a template engine for PHP... Yes these are a dime a dozen but this is different. Rather than mixing concerns like this


Code:
<h1>{{title}}</h1>
<p>{{subtitle}}</p>
{{if %isAdmin%}}
<div>conditionally show this</div>
{{/if}}


Transphporm separates the logic from the markup by using a CSS style syntax. The template looks like this:


Code:
<h1>A title</h1>
<p>sub title</p>
<div>conditionally show this</p>


And allows using CSS like syntax, providing the content and logic:

Code:
h1 {content: "My Title"}
p {content: "My Subtitle" }
div:data[isAdmin=false] {display: none}


It does a lot more than this, check it out over on github :)

https://github.com/Level-2/Transphporm
TheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWho
SaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTh
eJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSa
ysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJ
k
WhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSays
N
iTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkW
2016-01-06, 11:44 PM #2
Sounds perfect for Massassi 2.0. Thanks for volunteering.
? :)
2016-01-07, 11:15 AM #3
This is nice. Is it possible to add html as content? Or is it always escaped?
Sorry for the lousy German
2016-01-07, 11:20 AM #4
Originally posted by Mentat:
Sounds perfect for Massassi 2.0. Thanks for volunteering.

Oh hell no, Massassi 2.0 will be a Perl6 project.
And when the moment is right, I'm gonna fly a kite.
2016-01-07, 12:28 PM #5
Originally posted by Impi:
This is nice. Is it possible to add html as content? Or is it always escaped?


With the caveat that it currently has to be valid XML (so <img /> instead of <img>) you can use:

Code:
div {content: "<strong>bold text</strong>"; format: html}


The content can be stored in external data and not just a hardcoded string, e.g.


Code:
div {content: data(htmlcode); format: html; }
TheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWho
SaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTh
eJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSa
ysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJ
k
WhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSays
N
iTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkW
2016-01-07, 7:19 PM #6
How do you access nested data elements?
And when the moment is right, I'm gonna fly a kite.
2016-01-08, 5:53 AM #7
Originally posted by gbk:
How do you access nested data elements?


You can either use a dot or square brackets, they're interchangeable like javascript:

Code:
data(foo[bar]);
data(foo.bar);


You can also bind a specific variable to an element and it's available in child nodes directly:

Code:
div {bind: data(foo);}
span {content: data(bar); }


Which will read foo[bar] from the supplied data. This is really useful for re-populating form fields. For example:


Code:
echo $template->output(['formdata' => $_POST])->body;


You can then write a reusable TSS file that can be used to populate any form with a data set:

Code:
form {bind: data(formdata);
/* Set the input's value attribute 

input:attr(value) {content: data(attr(name); }


This works by reading the input's `name` attribute using `attr(name)` and passing the result of that to the `data()` function which is then looked up in the supplied array.

What this allows is a reusable TSS:

Code:
input[type="text"]:attr(value) {content: data(attr(name); }
textarea {content: data(attr(name));


Which can then be used in any other TSS file using:

Code:
@import 'form.tss';
form {bind: data(formdata); }


and doesn't require the form data to be stored in a specific key in the $data array.
TheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWho
SaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTh
eJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSa
ysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJ
k
WhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSays
N
iTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkW
2016-01-08, 9:31 AM #8
Originally posted by gbk:
Oh hell no, Massassi 2.0 will be a Perl6 project.

Sounds perfect for Massassi 2.0. Thanks for volunteering.
? :)
2016-01-10, 7:16 AM #9
Well, if any of it can unpack an archive and level pack (like GOBs for JK) to give a level submission reviewer an easier time to see all resources so no secret questionable content gets through... ;)
Edward's Cognative Hazards

↑ Up to the top!