[TxMt] Opening Ruby Headers

Juan Falgueras jfalgueras at uma.es
Sun Aug 24 15:16:43 UTC 2008



	I have extended my old C/C++ headers opener to Ruby.  I have  
associate it to Shift-Cmd-D  as in the classic MPW ;)

The scope:
source.ruby,text.html.ruby, source.ruby.rails.embedded.html,  
meta.rails.helper, meta.rails.unit_test, source.js, source.css,  
source.yaml, meta.rails.controller, meta.rails.functional_test,  
text.haml

and

-------------- next part --------------
A non-text attachment was scrubbed...
Name: pastedGraphic.png
Type: image/png
Size: 11562 bytes
Desc: not available
URL: <http://lists.macromates.com/textmate/attachments/20080824/f95d12a2/attachment.png>
-------------- next part --------------





#!/usr/bin/env perl

$cmd = 'ruby -e \'p $LOAD_PATH.join(":")\'';
$paths = `$cmd` . $ENV{'RUBYPATH'} . $ENV{'RUBY'};

$line=$ENV{'TM_CURRENT_LINE'};
$header=$ENV{'TM_SELECTED_TEXT'};

if ($header =~ /^\s*$/) {
   $line =~ /\s*(require|require_gem)\s*["'](.*?)["']/;
   $header = $2;
}

# local?
$t = $ENV{'TM_DIRECTORY'};
if (-f "$t/$header.rb" ) {
   print "$t/$header";
   system("mate", "-r", "$t/$header");
   exit 0;
}

@incs = split(/:/, $paths);

foreach $t (@incs) {
   if (-f "$t/$header.rb") {
     print "$t/$header.rb";
     system("mate", "-r", "$t/$header.rb");
     exit 0;
   }
}
print "$header.rb HEADER NOT FOUND";
exit 1;


Hope this serve someone.

- jf





More information about the textmate mailing list