Share Your Code in Color

This tip if for anyone who ever shows their code to someone else for the sake of sharing, comments or criticisms or working on projects together. In the TextMate bundle you have a few options to take the code of your current document and export to an html file or even directly to the web. Let’s explore a few of these options.

Paste Document Online

This is a pretty neat tool in my opinion. If you have a section of your code selected this action will focus just on the selection. If you have nothing selected the entire document will be parsed. When running this action you’ll be given a few options. You can open straight in the browser, copy to clipboard, or send a link directly to a buddy in your iChat window.

Wait a second, now. A link? I didn’t make a file so what link is sent? Well there’s a pretty nifty site created by Josh Goebel called Pastie. The code you are choosing to ’share’ is sent to Pastie and a unique page is created with your code ready to view. What’s really nice is anyone viewing that page can choose the color scheme (or theme) that they would like to see. You do have the option of keeping this link private but if you do not choose it your code will appear here along with many other’s.

Create HTML

There are two more functions, Create HTML From Selection & Create HTML From Selection With Line Numbers, which allow you to put the code where you want it as opposed to the Pastie app. Doing this will create a new document with all the CSS needed to color your code and every bit is wrapped in <pre> tags so the formatting is still there. Personally I never use Create HTML From Selection because I highly prefer line numbers when working. The most helpful part is having someone else reviewing your code and being able to say “Look at line 158″ as opposed to “see down where you’re selecting the users from the database”.

Create CSS From Current Theme

I never use this one. It does exactly what it says. Respective to the theme in TextMate you are running this will create a new document with classes ready to be used in your HTML. The reason I never use it is because the single file with styles in the head gets the job done in fewer steps. So far I’ve only done this type of sharing on a temporary basis. Should I need to put some code on the web to stay for a while I may use this to save an external style sheet for neatness.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati

About the Author

Name: Erik

All tips by Erik

Erik is a husband, father, web developer and musician working in Savannah, Georgia. He loves the smell of TextMate in the morning! You can catch him around Twitter @ErikReagan

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments
Leave a comment