Archive for 2009/05:

Rack middleware showing git or svn revision


Rack is fun. Really, lots of fun. After creating middleware for showing markup errors and viewing several presentations related to Rack I was thinking about Rack’s potential. And it’s big. The result of my thinking (and a little coding) is another middleware.

When you deploy application to a demo server QA (or client) wants to know which revision is currently running. Of course you can handle it in a old-school way putting some helper into your layout(s) which will obtain revision number exec’ing “svnversion” or sth like this. It works but it’s not the most elegant solution. First, you are including code related only to demo/staging server in layouts/helpers (production server and your development box don’t need it at all). Second, you probably do this for every new project. But all ruby web frameworks now run on Rack so better solution would be to move revision-displaying code from the app itself to the middleware. So here comes RevisionInfo.

Install:

gem install sickill-rack_revision_info --source http://gems.github.com

Enable in Merb:

config/dependencies.rb:

dependency "sickill-rack_revision_info", :require_as => "rack_revision_info"

config/rack.rb (before line with run Merb::Rack::Application.new):

use Rack::RevisionInfo, :path => Merb.root

Enable in Rails:

config/environment.rb:

config.gem "sickill-rack_revision_info", :lib => "rack_revision_info", :source => "http://gems.github.com"
config.middleware.use "Rack::RevisionInfo", :path => RAILS_ROOT

Enabling this middleware for svn managed application you will get <!-- Revision 666 (2009-05-28 19:00:25 +00:00) --> appended to the end of resulting html. For git repository it will be <!-- Revision 31d0fa132584c7e9bf978443052b545c1aeca96b (2009-05-28 19:00:25 +00:00) -->. It’s commented out so in order to see it look into page source.

However if you prefer to see revision number somewhere on the page you can specify CSS selector of page element and method of injection like this:

use Rack::RevisionInfo, :path => Merb.root, :inner_html => ".footer li.revision"

Here are available injection methods:

  • :append => "div.footer" inserts revision info at the end of footer div content
    <div class="footer"><img...> Revision 666 (2009-05-28 19:00:25 +00:00)</div>
  • :prepend => "div.footer" inserts revision info at the begining of footer div
    <div class="footer">Revision 666 (2009-05-28 19:00:25 +00:00) <img...></div>
  • :after => "div.footer" inserts revision info after footer div
    <div class="footer"><img...></div>Revision 666 (2009-05-28 19:00:25 +00:00)
  • :before => "div.footer" inserts revision info before footer div
    Revision 666 (2009-05-28 19:00:25 +00:00)<div class="footer"><img...></div>
  • :inner_html => "div.footer" replaces footer div content with revision info
    <div class="footer">Revision 666 (2009-05-28 19:00:25 +00:00)</div>
  • :swap => "div.footer" replaces whole footer div with revision info
    Revision 666 (2009-05-28 19:00:25 +00:00)

If you enable injection using one of above methods you need to have Hpricot gem installed because HTML manipulation is done using it (if you don’t use injection – only comment appending – you don’t need hpricot). Specified CSS selector can be any selector supported by hpricot so you can freely use funky stuff like #main ul.footer li:last. You can also use XPath like //div/ul/li.

Sources (as usual) are available on github.com. Enjoy!

View Comments

Open File Fast 0.9.3


New version of Open File Fast has arrived.

What’s new?

  • Initial project used for search is now Main Project, and if none is selected as main then the first opened project is used
  • Ability to switch searched project directly from OFF search dialog (see screenshot below)
  • Information about project indexing is shown in dialog’s status bar
  • Fixed bug with indexing files in newly added directories
  • Improved dialog layout a little

I’ve tested this version under Netbeans 6.5 and 6.7beta and I didn’t notice any problem, however if you encounter some issue let me know.

NBM package: off-netbeans-0.9.3.nbm

View Comments

Rainbow gem updated for Ruby 1.9.1


Thanks to Chad from Spicycode my rainbow gem now supports Ruby 1.9.1 (and it’s backwards compatible with Ruby 1.8.x). It doesn’t provide any new features so there is no need for upgrade for Ruby 1.8.x users. I’ve released new version 1.0.2 at rubyforge.

View Comments

Rack middleware using HTML Tidy


Did you waste some time trying to spot the problem in html markup in your ruby web app? Are you strict validation freak? If yes, then read on.

I had several situations when something disappeared from the page or layout broke and the problem was in some missing closing tags or invalid nesting of elements. As I recently do my web development in Merb and Sinatra (this blog actually runs on Sinatra) and both of them are built on top of Rack I thought that I could write a middleware which can show me the problems in my markup.

So here it is. It uses well known Tidy tool to check for markup errors in actions output. Following code snippet shows the middleware class and its use in the simplest Sinatra app.

After running this tiny webapp and opening root url in your browser you will get following output in terminal:

It prints any warning and error messages to the console so you can easily spot any minor and major problems in the markup.

View Comments

Open File Fast featured on Netbeans website


Open File Fast has been chosen as “featured” plugin on Netbeans website. Cool! I hope number of plugin users will increase and I will get some more feedback about it.

And as for feedback, I’ve recently heard that OFF has some problems on newest versions of Netbeans (nightly builds and 6.7 beta). Last version which I’ve tested on was 6.7 M2 and then it worked. But as 6.7 final is comming (I hope Sun takeover by Oracle will not delay the release) I will investigate the problems and hopefully resolve them as soon as I will have some free time.

View Comments