Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: drnic/ruby-on-rails-tmbundle
base: master
...
head fork: vanntastic/ruby-on-rails-tmbundle
compare: master
Checking mergeability… Don’t worry, you can still create the pull request.
  • 7 commits
  • 3 files changed
  • 0 commit comments
  • 2 contributors
View
8 Commands/Make Selection in to Partial.plist
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<!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>
@@ -9,15 +9,13 @@
"${TM_RUBY:=ruby}" -- "${TM_BUNDLE_SUPPORT}/bin/create_partial_from_selection.rb"
</string>
<key>fallbackInput</key>
- <string>line</string>
+ <string>scope</string>
<key>input</key>
<string>selection</string>
- <key>keyEquivalent</key>
- <string>^H</string>
<key>name</key>
<string>Create Partial From Selection</string>
<key>output</key>
- <string>replaceSelectedText</string>
+ <string>showAsTooltip</string>
<key>scope</key>
<string>source.ruby.rails, text.html.ruby, text.haml</string>
<key>uuid</key>
View
92 Support/bin/create_partial_from_selection.rb
@@ -18,86 +18,24 @@
end
# If text is selected, create a partial out of it
-if TextMate.selected_text
- ext = ".html.#{current_file.extension}"
- partial_name = TextMate::UI.request_string(
- :title => "Create a partial from the selected text",
- :default => "partial",
- :prompt => "Name of the new partial: (omit the _ and #{ext})",
- :button1 => 'Create'
- )
+ext = ".html.#{current_file.extension}"
- if partial_name
- path = current_file.dirname
- partial = File.join(path, "_#{partial_name}#{ext}")
+partial_name = TextMate.selected_text || TextMate.current_word
+partial_name.gsub(/[^a-z0-9]+/i, '_')
- # Create the partial file
- if File.exist?(partial)
- unless TextMate::UI.request_confirmation(
- :button1 => "Overwrite",
- :button2 => "Cancel",
- :title => "The partial file already exists.",
- :prompt => "Do you want to overwrite it?"
- )
- TextMate.exit_discard
- end
- end
-
- # determine and strip identing of the partial
- selected_text = TextMate.selected_text + "" # somehow .clone did not work
- identing = selected_text.split("\n").first.to_s.match(/^(\s+)/) ? $1 : ""
- selected_text.gsub!(/^#{identing}/, "")
-
- file = File.open(partial, "w") { |f| f.write(selected_text) }
- TextMate.rescan_project
+if partial_name
+ path = current_file.dirname
+ partial = File.join(path, "_#{partial_name}#{ext}")
- # Return the new render :partial line
- if current_file.extension == "haml"
- print "#{identing}= render :partial => '#{partial_name}'\n"
- else
- print "#{identing}<%= render :partial => '#{partial_name}' %>\n"
- end
- else
+ # Go to the partial if it already exists
+ if File.exist?(partial)
+ TextMate.open partial
TextMate.exit_discard
end
+
+ file = File.open(partial, "w")
+ TextMate.rescan_project
+ TextMate.open partial
else
- # Otherwise, toggle inline partials if they exist
-
- text = ""
- partial_block_re =
- /<!--\s*\[\[\s*Partial\s'(.+?)'\sBegin\s*\]\]\s*-->\n(.+)<!--\s*\[\[\s*Partial\s'\1'\sEnd\s*\]\]\s*-->\n/m
-
- # Inline partials exist?
- if current_file.buffer =~ partial_block_re
- text = current_file.buffer.text
- while text =~ partial_block_re
- partial_name, partial_text = $1, $2
- File.open(partial_name, "w") { |f| f.write $2 }
- text.sub! partial_block_re, ''
- end
- else
- # See if there are any render :partial statements to expand
- current_file.buffer.lines.each_with_index do |line, i|
- text << line
- if line =~ /render[\s\(].*:partial\s*=>\s*['"](.+?)['"]/
- partial_name = $1
- modules = current_file.modules + [current_file.controller_name]
-
- # Check for absolute path to partial file
- if partial_name.include?('/')
- pieces = partial_name.split('/')
- partial_name = pieces.pop
- modules = pieces
- end
-
- partial = File.join(current_file.rails_root, 'app', 'views', modules, "_#{partial_name}.html.erb")
-
- text << "<!-- [[ Partial '#{partial}' Begin ]] -->\n"
- text << IO.read(partial).gsub("\r\n", "\n")
- text << "<!-- [[ Partial '#{partial}' End ]] -->\n"
- end
- end
- end
- print text
- TextMate.exit_replace_document
-end
+ TextMate.exit_discard
+end
View
2  Support/lib/rails/command_go_to_file.rb
@@ -31,7 +31,7 @@ def self.on_current_line
case TextMate.current_line
# Example: render :partial => 'account/login'
- when /render[\s\(].*:partial\s*=>\s*['"](.+?)['"]/
+ when /render[\s\(].*[:partial\s*=>]?\s*['"](.+?)['"]/
partial_name = $1
modules = current_file.modules + [current_file.controller_name]

No commit comments for this range

Something went wrong with that request. Please try again.