Blog
An exploration of the art and
craft of software development
YUI 4 Rails - Release 0.0.1
Posted by Marty Haught on Friday, February 08, 2008Tonight I just pushed out the first release of the YUI 4 Rails plugin, version 0.0.1, built on YUI version 2.4.1. It’s not full featured but it does work and it seemed best to get it out there so at least some can use it. Specifically, the Active Warehouse trunk can use the datatable widget for sortable reports. However, it is possible to just use the plugin on its own.
Installation
First, you’ll want to get the plugin from RubyForge. You can either install it via the plugin command:
script/plugin install svn://rubyforge.org/var/svn/yui4rails/trunk/
Or manually download the tar.gz/zip file and extract it into your RAILS_APP/vendor/plugins directory.
YUI Resources
If you’re not familiar with YUI then I recommend you visit their developer site. In this plugin we decided to reference the resources (javascript/stylesheets/images) locally on our server. So the next step of getting up and running is to copy the resources into your Rails app. Use this rake command in the plugin ROOT:
rake initialize_yui
You should then find a lot of resources copied to the
Adding to pages
We have a convenience include helper for you to use in your templates. You pass in an array of component names as symbols such as:
<%= include_yui :datatable, :charts %>
It will pull in the necessary javascript and stylesheet resources for those components.
Datatable
Our initial build of the widget wrappers was motivated for the sortable reports for Active Warehouse. It is still possible to use what’s in YUI4Rails as it stands, it’s just not as convenient as it could be. Part of that is the datatable widget is not simple. Below is the sample code that you’ll need to use:
data_table = Yui4Rails::Widgets::DataTable.new("your_table_id", column_definitions, data_rows, footer_row = "")
data_table.render
After constructing the component, you then need to render it via the render method as above.
Charts
Charts works essentially the same way:
chart = Yui4Rails::Widgets::Chart.new("yui_chart_id", yui_column_definitions, yui_data_rows)
chart.render
What’s next
In the short term, I’ll probably make sure all the specs cover the existing code. I did get a few written but didn’t want to delay the release any longer getting full testing in the plugin. It would be nice to get that coverage.
Additionally, I would like to make both Charts and Datatable be easier to use standalone. There are many other great components in the YUI library that would be great to wrap. Long term, we could enhance the plug-in to have all the existing prototype/scriptaculous helpers ported to YUI. I’m not sure if I’ll have the time to do all that but it might be something others could pick up. As always, contributions on the plugin are welcome. I never envisioned it would be a 1-2 person project.
blog comments powered by Disqus