Another pass at a javascript library

19 views
Skip to first unread message

khrome

unread,
May 30, 2011, 10:43:34 PM5/30/11
to jSmart
Hi Max I also took a stab at implementing a smarty library in JS (I
work on a framework that uses an augmented subset of smarty and needed
a barebones implementation). I'm extremely happy with it and using it
in production environments. Because of my focus on my own framework
(where I have nearly 100% parity between the PHP and JS environments),
it's sorely lacking in compatibility with traditional smarty templates
due to it's dependency on PHP's large function library. However, I'm
pretty sure you and I could put our heads together, work with what we
have plus some of the php.js project and we could have a nearly
complete smarty port, rather than just the macro engine (what we've
currently got).

My implementation:
https://github.com/khrome/Midas.js/blob/master/Source/Midas.Smarty.js

Interested?

Max Miroshnikov

unread,
Jun 15, 2011, 5:27:00 AM6/15/11
to jSmart
Hi, Khrome!

Sorry for my delay to answer you, I was on vacation.
Of course, I am intrested in any type of cooperation.
I hope when jsmart is fully completed and bugs fixed, using it along
with php.js will be enough to port any PHP smarty template to JS.
I didn't quite understand what you mean by "complete port", maybe you
can tell me about it

Abbey Sparrow

unread,
Jun 15, 2011, 12:40:04 PM6/15/11
to jsmartdi...@googlegroups.com
Thanks for the reply Max,

A core part of Smarty is a language remapping from html/smarty to php (which is outside the scope of both of our projects as they stand), that's why I refer to both our projects as incomplete, however I have the same vision you do that you'll be able to drop in php.js and then be able to drop in a smarty template. I do this right now, actually... in production. The trick is, though that because Smarty used their irritating eval() + regex strategy pre 3.0 there are a huge range of legal syntaxes that are supported. This is the more 'complete' version I speak of, one that is less rigid. Or one that implements native js caching. My port is missing a few macros but these are easily implementable, and it supports extension through mootools (I implement my framework as a subclass of this base smarty parser), but all the parsing logic is done, tested and had some stress put on it. But I'm sure if we put our heads together we can come up with some way to cross pollenate, even if it were just limited to a shared testing environment...

let me know what you think.

Max Miroshnikov

unread,
Jun 17, 2011, 7:24:32 AM6/17/11
to jSmart
Do you mean support for PHP code e.g. {if $ob->memberFunc() ...} or
inside {php} tags?
I think it has to be a full php parser/compiler in JS, since you can
encounter ANY php code in a template, doesn't it?
You wrote you framework has "nearly 100% parity between the PHP and JS
environments", doesn't that mean you've built such a parser?
Of course, it would be a great idea to combine this framework and a
macro engine to get a full JS smarty port.

Abbey Sparrow

unread,
Jun 17, 2011, 12:47:45 PM6/17/11
to jsmartdi...@googlegroups.com
I've built a fairly versatile parser, however... because I have control over my own macro language and I can tell the guys who work on my team "do X not Y" the syntax we've been using has been very constrained. Here are a couple of currently limited features: the for loop currently only supports 1 syntax and while expression evaluation works pretty well, I don't currently support nested boolean expressions '()', though I do have some code for that which I just need to find time to integrate. Also, I don't have a number of the core macros implemented because Smarty isn't my direct goal, but instead this other, related framework I work on called Protolus. I'm sure if I were using the library to try and run legacy smarty templates I'd be hitting a number of bugs. That's the stuff I feel like we could tackle together, whether you contributed to my project or vice versa or we worked on a test suite together for both.

-abbey

Max Miroshnikov

unread,
Jun 21, 2011, 10:25:50 AM6/21/11
to jSmart
Hi, Abbey

So, let's try it.
What's your idea how do do it the best way?

For a test suite I use a simple (and IMHO best) technique - compare
the output of Smarty to that of JS port for a number of templates and
fail if they don't match exactly.

Abbey Sparrow

unread,
Jun 21, 2011, 7:52:10 PM6/21/11
to jsmartdi...@googlegroups.com
So what should it be? Each test has a template and a JSON payload along with a copy of the last successful output?

I'm currently testing my framework ad-hoc using a hand assembled HTML harness, so I don't have much in the way of a stack... I'll construct a few simple tests for features I'm working on and commit them to my repo... I'll hit you back once that's done.

-abbey

Reply all
Reply to author
Forward
0 new messages