What's been happening?

March 21st, 2008

Posted at 10:59pm by Stan

I just uploaded a new copy of jQuery templates with a fix for $.fn.text() and $.fn.html(), I was not passing the options object in correctly (silly mistake) and thanks to Chris Jaure, if you were using either of these methods to simply return a value they now work correctly as well.

jQuery Templates available at: http://stanlemon.net/files/jquery.template.js

March 20th, 2008

Posted at 12:27pm by Stan

As I continue to get feedback on the jQuery Templates plugin I've ported from Ext I'm trying to implement the suggestions I've received. Subsequently, I've uploaded another round (or two) of changes. The changes I've made are:

  • Moved the $template object to $.template.instance, so that the object can be access from the jQuery object and extended easily - what was I thinking before??
  • Renamed the "re" property to "regx", and this is now an object containing several different regular expression options (jsp, jtemplates and ext for starters).
  • You can now change the standard regular expression by setting $.template.regx.standard = $.template.regx.myregexp;
  • Templates can utilize custom regular expressions on a per-template basis, ie. var t = $.template("<div>...</div>", { regx: 'ext' });
  • In addition to the methods that use domManip() I've updated html() and text() to handle receiving jQuery Templates as well.

I hope to add some kind of callback to the plugin as well, so that you can specify a method to be called after a template has been created or applied. I'm still thinking this through and will post more once I implement it.

March 12th, 2008

Posted at 11:43pm by Stan

I've done some more work on my jQuery Templates proposal. First, by request from some on the jQuery lists I've removed the usage of the $.ui namespace, although it really functioned completely independent of jQuery.UI. Second, I've added a modification to override the jQuery domManip() method, which is a method called by other methods like insertBefore() and append() and handle DOM manipulation within the jQuery core. Now, you can pass any of the manipulation methods your jQuery Template object and as a second parameter the object of properties for replacement. This changes the syntax to:

var t = $.template('
Hello ${name}, how are you ${question}? I am ${me:substr(0,10)}
'); $(selector).append( t , { name: 'Stan', question: 'feeling', me: 'doing quite well myself, thank you very much!' });

I'm going to resubmit my proposal to jquery-en and jquery-ui for consideration and review. If you're interested in looking at the code, it's available at:
http://stanlemon.net/files/jquery.template.js

February 22nd, 2008

Posted at 10:48am by Stan

Some conversation at work arose about templating in jQuery. The honest answer to anyone inquiring about this is that jQuery lacks any real good solution for simple macro-based templating. I was directed to Ext, which has a Template library in it that does exactly this. Subsequently, I've proposed to the UI folk a port of Ext.Template. For the most part the port is direct, the apply() and compile() methods are virtually identical to Ext.Template, though they use some jQuery functions instead of Ext.Core functions. The constructor is very different, and the designation of compiling is via a jQuery-style options object passed to the template constructor. I've tried to follow the jQuery.UI API as best as I know. I've changed the formatter usage in Ext.Template, as it depends on Ext.util.Format which isn't available in jQuery. All in all, this functionality does not seem like it's necessary so I changed it to use what I'm calling "helpers". These helpers provide the variable:method() syntax like in Ext.Template but allows the designer to customize what functions are available in a jQuery-style way.

Updated 03/12/2008: Anyhow, the code for my port and proposal is available here:
http://stanlemon.net/files/jquery.template.js

Powered by BlogSCL3 0.2.0alpha