Showing posts with label fluent expressions. Show all posts
Showing posts with label fluent expressions. Show all posts

Monday, July 19, 2010

PHP to javascript fluent expressions

There are many times in Voltron views where I need to make a jquery/javascript call, initially I compromised and created the UI::ScriptSnippet in which I would put the typical "$(document).ready(function(){})" type deal in place. This was becoming increasingly more obnoxious particularly when the rest of the view code was so clean. So I give you the JSCallBuilder:


UI::JSCall('object')->method(array('a' => 'b'));
// renders to object.method({'a': 'b'});

UI::JSReady('object')->method(array('a' => 'b'));
//renders to <\script type="text/javascript">$(document).ready(function(){ object.method({'a', 'b'}) });<\/script>
*/note the escaped script tags for bloggers sake? */


The source to make this happens is relatively trivial: http://code.google.com/p/phpviewadapter/source/browse/trunk/UI/JSCallBuilder.php