Loading twitter status...

After spending a good week trying to get around the non-safeness of class variables when threads are concerned, I finally got a release of my new plugin to share with you all! I haven’t done a whole lot of testing, but it does seem to work. So, if you have any bugs or suggestions, don’t hesitate to pass them on to tehdnite at gmail and I’ll see what I can do about them.

First things first, a brief introduction. Ajaxyxml is a mephisto plugin that makes it easy to fetch any (at least I’m pretty certain it should parse any) XML file from the internet and aggregate the contents into whatever form you want on your blog. The difference between this and the other plugins that parse XML data is that this works via teh Ajax. Instead of needing to flush your cache to update that small section of your blog that has dynamic content on it, it’s fetched on the fly. If you want to jump right in, go ahead and read the README file and get started. For those of you using the latest stable release of Mephisto (0.7.3), you’ll need to grab the 0.1 version, anyone using the most up to date mephisto from SVN can use either 0.1 or the latest trunk.

To install for ‘Edge Mephisto’...
script/plugin install -x http://svn.dnite.org/mephisto_ajaxyxml/trunk
Or if your using 0.7.3…
script/plugin install http://svn.dnite.org/mephisto_ajaxyxml/tags/0.1
Also, if you using the 0.1 release, you will need to add the following line to your config/routes.rb file ABOVE the Mephisto::Routing route…
AjaxyXml.connect_with map

You should be all set to use the plugin now. Restart mephisto to load up the plugin. Using the plugin is easy but requires 2 steps. First, you’ll want to create a partial file. Let’s use twitter as an example for this. Go to your admin interface for mephisto and select Design and New Template. We’ll add the following code.

<p>My current Twitter Status: {{ xml.text }}<br />
It was set on {{ xml.created_at }}</p>

Now let’s name it. This plugin needs it to be named a certain way. It must start with _ajaxy_ and end with the name of the element you wish to be updated on the template your going to be using this tag on. Let’s call it _ajaxy_twitter_status. Click Create Template and verify that it exists on the right. Mephisto should have appended a .liquid to the end.

Last thing we have to do is add the code to our layout. Open up layout.liquid and add the following. (Also, if you don’t have prototype load up already, make sure you add {{ 'mephisto/prototype' | javascript }} somewhere inside the HEAD of your layout)
<div id="twitter_status">Loading Twitter Status</div>
{% ajaxyxml url: 'http://twitter.com/statuses/user_timeline/swemoney.xml', element: 'twitter_status', quantity: '1' %}

This will add a DIV that will say ‘Loading Twitter Status’ and an Ajax request right under it. As soon the Ajax request gets back, the twitter_status DIV will get updated. The only big ‘weird’ thing I found with this release is that the tag is really picky about line breaks. Just make sure there are NO line breaks in the {% ajaxyxml %} tag at all./ You can put the ajaxyxml liquid tag anywhere on your page as long as it lands after the element you wish to update with it. I like to throw mine at the bottom of the page.

That’s about it. I tried to make this introduction article as non-technical as possible, so for those of you who thought this was all obvious, I apologize. If you have any comments, suggestions, complaints, or whatever don’t be afraid to leave some comments! Enjoy!

UPDATE : I added some support for mootools, read about it here,

7 Comments

This is the plugin of my dreams! Unfortunately, it seems like I’m missing something, is there another dependency? I keep getting a missing template error for /ajaxyxml/index.jx.erb. everything else appears to be working.

Thanks for releasing this!

@nicholas: I actually haven’t tested the plugin w/ edge rails, so I might have to work on that a little bit. The problem with edge right now is that it feels to me that they haven’t locked down what template files will be called in the future. You can try and be simple and just rename the mephisto_ajaxyxml/views/ajaxyxml/index.rjs to index.js.erb and see if that fixes things. Not sure if it will though.

Heyhey. I obviously need ot have prototype loaded to use this, which is totally cool, but I spent a long time a few months ago writing up all my jscript effects to use mootools. I would rather not load both prototype and mootools if I could help it, if for no other reason to save load time. But its an absolutely awesome concept, and if you ever make it mootools compatible I will totally use it! :D

Hey guys, dont quite follow what this does, anyone got an example they could show me please?

Thanks

@pete: This plugin lets you add an easy ajax request to your mephisto blog that will grab some XML data in the background after the rest of your page loads. It’s not quite as ‘real time’ as I would like it but I’ll have to figure out what caching mephisto is doing that’s preventing real time updates.

I’m trying to use this plugin (0.1) with latest stable Mephisto (0.7.3) and rails (1.2.3)

And I’m getting the following error:

/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:249:in `load_missing_constant’: Expected /home/www/blog.princelaw.com/public/../config/../vendor/plugins/0.1/lib/plugin.rb to define Plugin (LoadError)

In case anyone is as foolish as me, and trying to install Edge Mephisto and Edge Rails at the same time, this line 2 in ajaxyxml_controller.rb should be changed to :self.view_paths = Mephisto::Plugin.view_paths[:ajaxyxml]

Leave a Comment

back to top

micro theme by seaofclouds, edited by me, and powered with Mephisto