Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
noniq committed Aug 27, 2015
2 parents 1181de3 + 6c5431d commit ff2ba96
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
17 changes: 13 additions & 4 deletions Commands/Convert Ruby hash to 1_9 syntax.tmCommand
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,19 @@
<key>command</key>
<string>#!/usr/bin/env ruby18
print case str = STDIN.read
when /=&gt;/; str.gsub(/:(\w+)[\s]+=&gt;[\s]+/, '\1: ')
when /(\w+):/; str.gsub(/(\w+):(\s*(?:"(?:\\"|[^"])*"|'(?:\\'|[^'])*'|\w+\([^)]*\)|[^,]+))/, ":\\1 =&gt;\\2")
else; str
def toggle_ruby_hash_syntax(str)
case str
when /\=&gt;/
str.gsub!(/:(\w+)\s+=&gt;\s+/, '\1: ')
when /(\w+):/
str.gsub!(/(\w+):(\s*(?:"(?:\\"|[^"])*"|'(?:\\'|[^'])*'|\w+\([^)]*\)|[^,]+))/, ":\\1 =&gt;\\2")
else
str
end
end
while str = $stdin.gets
print toggle_ruby_hash_syntax(str)
end
</string>
<key>fallbackInput</key>
Expand Down
26 changes: 19 additions & 7 deletions Commands/Toggle String:Symbol.tmCommand
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,24 @@
<key>command</key>
<string>#!/usr/bin/env ruby18
print case str = STDIN.read
# Handle standard quotes
when /\A["'](\w+)["']\z/ then ":" + $1
when /\A:(\w+)\z/ then '"' + $1 + '"'
# Default case
else str
require ENV['TM_SUPPORT_PATH'] + '/lib/exit_codes'
def toggle_string_symbol(str)
case str
# "string" =&gt; :symbol
when /("|')(\w+)\1/
str.gsub!(/("|')(\w+)\1/, ':\2')
# :symbol =&gt; "string"
when /:(\w+)/
str.gsub!(/:(\w+)/, '"\1"')
# initial case (no changes)
else
str
end
end
while str = $stdin.gets
print toggle_string_symbol(str)
end
</string>
<key>fallbackInput</key>
Expand All @@ -28,7 +40,7 @@ end
<key>output</key>
<string>replaceSelectedText</string>
<key>scope</key>
<string>source.ruby string.quoted, source.ruby constant.other.symbol.ruby</string>
<string>source.ruby string.quoted, source.ruby constant.other.symbol</string>
<key>uuid</key>
<string>B297E4B8-A8FF-49CE-B9C4-6D4911724D43</string>
</dict>
Expand Down

0 comments on commit ff2ba96

Please sign in to comment.