« RESFEST was excellent | Main | RESFEST LinkDump »

Javascript Syndication Template

Inspired by a look at XML::RSS::JavaScript by Ed Summers, I decided to crank out an MT template to do the same thing.
Here are the short steps, more details (probably it's own page) to follow:
1) Create a new template file. I call mine "Javascript Syndication." Name the output file rss.js
2) Create a new MT plugin (I called mine mt-rss-javascript-encode.pl) in your MT plugins directory. The code should look like this:
package MT::Plugin::FormatForJavascript;
use MT::Template::Context;

MT::Template::Context->add_global_filter(js_encode => sub {
    (my $s = shift) =~ s/'/\\\'/g;
    return $s;
});

1;

That should just about do it. Then, to use it, give someone the following snippet of JS:
<script Language="JavaScript" src="rss.js" />
Here is an example: Sorry. The embedded script in an entry was freaking out my RSS feeds. You can see the results in the "Recent Code Changes" section on the side of the screen.

Comments

Glad to see you got some use out of XML::RSS::JavaScript. I like your recursive example :) Does the MT::Plugin::FormatForJavascript have to use XML::RSS::JavaScript at all, or is it independent somehow? I guess I need to learn more about how MT plugins work. If you get a URL for this on your site, I'd like to mention it in the documentation. Hell, if you think it would be easy to distribute it would be cool to add the code to the distribution too.

well, this is more inspired by XML::RSS::JavaScript than anything else. It doesn't rely on X::R::J. And I lifted the JS/CSS from it, which I need to attribute. Now if only I could find a repository for cool MT templates....