Publising Rails Plug-ins with Rake

Problem: The Ruby on Rails plug-in installer's RecursiveHTTPFetcher makes certain assumptions about web servers that does not hold true from server to server. For example, it assumes:

  • The web server has "file browsing" enabled
  • All links to plug-in files are relative
  • Folder links end with a forward slash

RubyForge web server is an example of where these assupmtions don’t hold true. As a result, you can not simply copy your files to a web server and expect Rails HTTP plugin installer to just work.

Solution: Rails Plug-in Package Task

RailsPluginPackageTask is a Rake task designed to automate the publishing of Ruby on Rails plug-ins. It helps fill the gap by conforming to the Rails plug-in script's assumptions. Following the Rake package task conventions, it defines the "rails_plugin" task that recurses through your package_files, generates compliant index.html for each folder (that contains a file), and creates a directory structure that you can publish as a set for your plugin.

Example

The following example uses the Rake::RailsPluginPackageTask to create the package. It then uses the Rake::SshDirPublisher to publish the plugin directory to RubyForge.

RUBY:
  1. Rake::RailsPluginPackageTask.new(ProjectInfo[:name], ProjectInfo[:version]) do |p|
  2. p.package_files = PluginPackageFiles
  3. p.plugin_files = FileList["rails_plugin/**/*"]
  4. p.extra_links = {"Project page"=>ProjectInfo[:homepage],
  5. "Author: #{ProjectInfo[:author_name]}"=>ProjectInfo[:author_link]}
  6. p.verbose = true
  7. end
  8. task :rails_plugin=>:clobber
  9.  
  10. desc "Publish Ruby on Rails plug-in on RubyForge"
  11. task :release_plugin=>:rails_plugin do |task|
  12. pub = Rake::SshDirPublisher.new("#{RubyForgeConfig[:user_name]}@rubyforge.org",
  13. "/var/www/gforge-projects/#{RubyForgeConfig[:unix_name]}",
  14. "pkg/rails_plugin")
  15. pub.upload()
  16. end

You can download the ZIP package for this task and place it in your gems or project folder. For a complete working example, checkout ROXML from CVS.

Note: This release has only been tested on Linux. If it doesn't work on your OS, please let me know.

Jul 03 2006 11:05 am | rails and ruby |

2 Responses to “Publising Rails Plug-ins with Rake”

  1. on 14 Sep 2006 at 6:14 pm sean

    Wondering if ROXML project is active considering that there are no responses to questions posted there.

    Apologies for dropping a note here.

  2. on 16 Sep 2006 at 7:23 pm mandhro

    Sean, I didn’t see the comments until today. Is there a bug you need fixed or feature missing? I have enabled Tracker on ROXML RubyForge project. I will try to accomodate change requests later this week. One of the things on my list is to add xml_text with xml_attribute.

Leave a Reply