Skip to content

Commit

Permalink
command to generate namespaced rake/sake task based on target file's …
Browse files Browse the repository at this point in the history
…path within project
  • Loading branch information
drnic committed Aug 19, 2008
1 parent 10a9479 commit 0b048e7
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 3 deletions.
64 changes: 64 additions & 0 deletions Commands/Rake:Sake task using file path.tmCommand
@@ -0,0 +1,64 @@
<?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 -w
unless ENV["TM_FILEPATH"]
puts &lt;&lt;-SIMPLE_SNIPPET
# NOTE: if you save this file first it will create a
# namespaced rake/sake task based on the file's
# path within the project
task ${1::${2:task_name}} do
$0
end
SIMPLE_SNIPPET
exit
end
def indent_str
"\t" * @indent
end
relative_filepath = ENV["TM_FILEPATH"].
gsub(ENV["TM_PROJECT_DIRECTORY"], '').
gsub(/^\/?/,'').
gsub(/\.[sr]ake$/, '')
task_name, *reverse_namespaces = relative_filepath.split(/[\/\\]/).reverse
namespaces = reverse_namespaces.reverse
@indent = 0
namespaces.each do |namespace|
puts "#{indent_str}namespace '#{namespace}' do"
@indent += 1
end
puts &lt;&lt;-TASK_SNIPPET
#{indent_str}${2:desc "${1:This task ...}"
#{indent_str}}task :#{task_name} do
#{indent_str} $0
#{indent_str}end
TASK_SNIPPET
reverse_namespaces.each_with_index do |namespace, index|
@indent -= 1
puts "#{indent_str}end"
end</string>
<key>fallbackInput</key>
<string>none</string>
<key>input</key>
<string>selection</string>
<key>name</key>
<string>Rake/Sake task using file path</string>
<key>output</key>
<string>insertAsSnippet</string>
<key>scope</key>
<string>source.ruby</string>
<key>tabTrigger</key>
<string>task</string>
<key>uuid</key>
<string>E07FF68B-C87D-4332-8477-D026929FDADA</string>
</dict>
</plist>
6 changes: 3 additions & 3 deletions Syntaxes/Sake and Rake (Ruby).tmLanguage
Expand Up @@ -9,9 +9,9 @@
<string>Rakefile</string>
</array>
<key>keyEquivalent</key>
<string>^~S</string>
<string>^~R</string>
<key>name</key>
<string>Sake and Rake (Ruby)</string>
<string>Rake and Sake (Ruby)</string>
<key>patterns</key>
<array>
<dict>
Expand All @@ -20,7 +20,7 @@
</dict>
</array>
<key>scopeName</key>
<string>source.ruby.sake</string>
<string>source.ruby.rake</string>
<key>uuid</key>
<string>0940DEE0-8222-4734-BF72-B7AB83F8E36D</string>
</dict>
Expand Down
3 changes: 3 additions & 0 deletions info.plist
Expand Up @@ -66,6 +66,7 @@
<string>803A6BDF-D74A-4B69-AFF0-98B824AB478D</string>
<string>2765038A-1CFC-4BBD-B19C-6EB2B400D528</string>
<string>6A819296-4AFF-4CD2-AF37-DE2705AF1A1A</string>
<string>228CAB3A-E221-4727-B430-31E94F76C9D3</string>
</array>
<key>submenus</key>
<dict>
Expand Down Expand Up @@ -326,6 +327,7 @@
<string>F686E1AD-B03D-45A6-BD51-6E3FD1298FE0</string>
<string>CB81DA55-F3BC-4BFB-B0C5-29F0EE6F8081</string>
<string>FE9A8EDA-C243-4068-8F38-A615B82D08C9</string>
<string>E07FF68B-C87D-4332-8477-D026929FDADA</string>
</array>
<key>name</key>
<string>Rake</string>
Expand Down Expand Up @@ -457,6 +459,7 @@
<string>97054C4D-E4A3-45B1-9C00-B82DBCB30CAD</string>
<string>6519CB08-8326-4B77-A251-54722FFBFC1F</string>
<string>47D203ED-EB9B-4653-A07B-A897800CEB76</string>
<string>E07FF68B-C87D-4332-8477-D026929FDADA</string>
<string>7990EE60-C850-4779-A8C0-7FD2C853B99B</string>
<string>121B334B-2AA6-4E9A-A8B8-BF93B627982B</string>
<string>58FDEA60-10AF-4C49-AA09-29B77030DB25</string>
Expand Down

0 comments on commit 0b048e7

Please sign in to comment.