Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
can convert full objc method signature in clipboard into an inline in…
…vocation via '.m'
  • Loading branch information
drnic committed Dec 29, 2008
1 parent ddca603 commit ddb4df8
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 13 deletions.
29 changes: 29 additions & 0 deletions Commands/Method call (use signature in clipboard) copy.tmCommand
@@ -0,0 +1,29 @@
<?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>export RUBYLIB="$TM_BUNDLE_SUPPORT/RakeMate${RUBYLIB:+:$RUBYLIB}"
export TM_RUBY=$(which "${TM_RUBY:-macruby}")
export TM_RAKE=$(which "${TM_RAKE:-macrake}")
"${TM_RUBY}" -- "$TM_BUNDLE_SUPPORT/bin/paste_objc_headers.rb" method_call
</string>
<key>fallbackInput</key>
<string>none</string>
<key>input</key>
<string>selection</string>
<key>name</key>
<string>Method call (use signature in clipboard) copy</string>
<key>output</key>
<string>insertAsSnippet</string>
<key>scope</key>
<string>source.ruby.mac</string>
<key>tabTrigger</key>
<string>.m</string>
<key>uuid</key>
<string>78EA9EFF-8142-4169-BF6B-024DDF71D5DF</string>
</dict>
</plist>
Expand Up @@ -16,7 +16,7 @@ export TM_RAKE=$(which "${TM_RAKE:-macrake}")
<key>input</key>
<string>selection</string>
<key>name</key>
<string>New method (can use signature in clipboard)</string>
<string>New method (use signature in clipboard)</string>
<key>output</key>
<string>insertAsSnippet</string>
<key>scope</key>
Expand Down
26 changes: 16 additions & 10 deletions Support/bin/paste_objc_headers.rb
Expand Up @@ -26,9 +26,19 @@ def to_method_call(signature, options = {})
end
end

def to_method_call_from_full_signature(signature, options)
def to_method_definition(signature, options = {})
tab_stops = options[:tab_stops]
class_method = (signature =~ /^\+/)
macruby_signature = to_method_call(signature, options)
<<-METHOD.gsub(/^ /, '')
def #{class_method ? 'self.' : ''}#{macruby_signature}
\t#{tab_stops ? '$0' : ''}
end
METHOD
end

def to_method_call_from_full_signature(signature, options)
tab_stops = options[:tab_stops]
signature.gsub!(/[+-]\s+/, '') # remove prefix +/-
signature.gsub!(/\([^)]+\)/, ' ') # remove data types, e.g. (NSString *),(void),(int)
signature_parts = signature.strip.split(/\s+/)
Expand Down Expand Up @@ -64,15 +74,11 @@ def compose_arguments(signature_parts, tab_stops)

if __FILE__ == $0
signature = `pbpaste`.strip
output_signature = PasteObjcHeader.new.to_method_call(signature, :tab_stops => true)
output_type = ARGV.shift
snippet = case output_type.to_sym
when :method_declaration
<<-SNIPPET.gsub(/^ /, '')
def #{output_signature}
\t$0
end
SNIPPET
print snippet = case output_type.to_sym
when :method_call
"." + PasteObjcHeader.new.to_method_call(signature, :tab_stops => true)
when :method_declaration
PasteObjcHeader.new.to_method_definition(signature, :tab_stops => true)
end
print snippet
end
8 changes: 6 additions & 2 deletions Support/test/test_paste_objc_headers.rb
Expand Up @@ -48,11 +48,15 @@ class TestPasteObjcHeaders < Test::Unit::TestCase
end

should "convert to method definition without tab stops" do

output = @converter.to_method_definition(@signature)
expected = "def speechSynthesizer(sender, willSpeakWord: wordToSpeak, ofString: text)\n\t\nend\n"
assert_equal(expected, output)
end

should "convert to method definition with tab stops" do

output = @converter.to_method_definition(@signature, :tab_stops => true)
expected = "def speechSynthesizer(${1:sender}, willSpeakWord: ${2:wordToSpeak}, ofString: ${3:text})\n\t$0\nend\n"
assert_equal(expected, output)
end
end

Expand Down
1 change: 1 addition & 0 deletions info.plist
Expand Up @@ -46,6 +46,7 @@
<array>
<string>2B513604-00DE-4EA9-9216-5DE83E832B4D</string>
<string>67669B2F-ECB7-4322-89F8-69190DD12C7C</string>
<string>78EA9EFF-8142-4169-BF6B-024DDF71D5DF</string>
<string>85DD4522-0311-4FA2-B26F-800FE1BCFD94</string>
<string>441917AF-9555-481D-99CD-251D2C557E39</string>
<string>F04D47B8-E673-4442-BA52-F65D775C0673</string>
Expand Down

0 comments on commit ddb4df8

Please sign in to comment.