Permalink
Browse files

Simple draggable for ruby files into ruby files: creates a require st…

…atement based on common known , else uses a relative path
  • Loading branch information...
1 parent 5bc4b98 commit 09c5032e2bf845d85148f538917d43696a4f729e @drnic drnic committed Jun 3, 2008
Showing with 42 additions and 0 deletions.
  1. +41 −0 DragCommands/Require Rails File.tmDragCommand
  2. +1 −0 info.plist
View
41 DragCommands/Require Rails File.tmDragCommand
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>beforeRunningCommand</key>
+ <string>nop</string>
+ <key>command</key>
+ <string>#!/usr/bin/env ruby
+
+file_path = ENV['TM_DROPPED_FILE'].gsub(/\.rb$/, '')
+full_file_path = File.expand_path(file_path)
+relative_path = nil
+known_load_path = %w[app/controllers app/models app/helpers app config lib]
+known_load_path.each do |path|
+ if full_file_path =~ %r{^#{File.join(ENV['TM_PROJECT_DIRECTORY'], path)}/(.*)}
+ relative_path = $1
+ break
+ end
+end
+if relative_path
+ puts "require '#{relative_path}'"
+else
+ puts "require File.dirname(__FILE__) + '/#{file_path}'"
+end
+</string>
+ <key>draggedFileExtensions</key>
+ <array>
+ <string>rb</string>
+ </array>
+ <key>input</key>
+ <string>selection</string>
+ <key>name</key>
+ <string>Require Rails File</string>
+ <key>output</key>
+ <string>insertAsSnippet</string>
+ <key>scope</key>
+ <string>source.ruby.rails</string>
+ <key>uuid</key>
+ <string>56151E60-589F-4CE7-8062-3E087732E2F1</string>
+</dict>
+</plist>
View
1 info.plist
@@ -844,6 +844,7 @@
<string>D54FBDED-5481-4CC7-B75F-66465A499882</string>
<string>87EF33FE-E918-11DC-A399-00112475D960</string>
<string>C0FD2646-E924-11DC-A399-00112475D960</string>
+ <string>56151E60-589F-4CE7-8062-3E087732E2F1</string>
</array>
<key>uuid</key>
<string>467A60E0-6227-11D9-BFB1-000D93589AF6</string>

0 comments on commit 09c5032

Please sign in to comment.