The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
TextMate and Keyref, the TextMate shortcut reference PDF generator

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Chris McGrath

Posts: 20
Nickname: octopod
Registered: Mar, 2006

Chris McGrath is a Ruby and Ruby On Rails developer
TextMate and Keyref, the TextMate shortcut reference PDF generator Posted: Mar 18, 2006 1:03 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Chris McGrath.
Original Post: TextMate and Keyref, the TextMate shortcut reference PDF generator
Feed Title: Octoblog
Feed URL: http://feeds.feedburner.com/octoblog
Feed Description: Occasional blogging from octopod
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Chris McGrath
Latest Posts From Octoblog

Advertisement

Switching

So I’m well behind on this one, having had a Mac since June and going a whole six months without switching. I couldn’t help it, I was (and still am) really comfortable in Vim and if it integrated better with OS X i’d still be there. TextMate is a very nice editor, it integrates incredibly well with OS X and has a great bunch of Ruby and Rails shortcuts (among others). I’m getting more comfortable with it every day, though of course I still miss certain things about Vim.

The problem with switching is, of course, you don’t know what the editor can do and what all the shortcut keys are straight away. TextMate provides a list of them if you want, but that’s not very handy when you’re in the middle of an editing session. I used to have this problem in Vim until I discovered the Vim quick reference card, so I wanted something similar for TextMate.

Making a TextMate PDF reference card

The list TextMate shows is a HTML table, and when you copy and paste somewhere it turns in to something like a tab separated value file. Hmm… My thoughts turned to Ruby, and I reckoned with a little scripting I should be able to scrape the HTML and turn it into a PDF. I’ve noticed Austin Ziegler’s PDF::Writer before, but haven’t had a chance to use it, so here was the perfect opportunity.

After installation, I had a look through the documentation and the demo files and saw the Ruby language and Ruby library quick reference cards. These were written by Ryan Davis, aka zenspider, who wrote another quick reference I find invaluable, available here (in HTML form). Peering at the code, the first thing that jumped out was the:

require 'pdf/quickef'
It turns out PDF::Writer includes code to generate three column quick reference cards, making my life very much easier! One scraper and some glue to hook it into PDF:QuickRef later, I had a PDF version of my TextMate shortcuts to make a printed reference card with.

Turning it into a Rails app – Keyref

I had been trying to think of a nice simple app I could write to get back into Rails after my trip. and thought that if I found making a PDF useful perhaps other people would too. So Keyref was born. Not only would it be something straightforward enough to write, but it would allow me to check out SwitchTower and set up my process of deploying an app from scratch to my VPS.

I had fun coding up the app, I found a simple design on oswd I liked and started from there. After a bit of a detour through a totally Ajax interface, considering writing a proper parser for the HTML and seeing if PDF::Writer would do UTF-8 characters1 and use an external font2, it ended up in the form it is now.

You can paste the key shortcuts into a form in the app, it parses (ok, scrapes) them and presents you with a list of available bundles from which you can pick eight to be on your card. This uses some Prototype / script.aculo.us magic to enable you to drag and drop between the lists and re-order the bundles you want printed.

I limited it to eight as PDF::Writer can use a lot of memory as it tries to find the best layout for the card and I didn’t want to kill my 96Mb VPS. Multiple requests at the same time would also be a problem, so I decided to store the parsed data in the database and generate the PDFs one at a time. A really cut down version of the prag progs order system if you like. I’ll write about the generator and mailer part of the system at a later date.

Keyref is up and running, TextMate users feel free to give it a go and let me know what you think.

1 It won’t, yet, the PDF spec only uses UTF16-BE which PDF:Writer supports (just about) and I couldn’t do what I wanted to do

2 I got this working, but the letter spacing was all wrong.

Read: TextMate and Keyref, the TextMate shortcut reference PDF generator

Topic: #ruby-lang Previous Topic   Next Topic Topic: Robot Co-op Hardware

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use