forked from textmate/ruby.tmbundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new documentation lookup command (Mavericks)
The implementation has changed so that it is now possible to use “back” to go back to previous page, it also auto-links things that look like method symbols. Presently though it does not auto-link methods listed in the includes, class, and instance method sections. Also, it shows the markdown output from ri pretty much as-is. It uses the version of ri included with OS X 10.9 (Mavericks) so the command is only made available to people on 10.9.
- Loading branch information
Showing
6 changed files
with
118 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?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>#!/bin/bash | ||
echo "<meta content='0;URL=file://$("${TM_BUNDLE_SUPPORT}/bin/ri_lookup" "${TM_SELECTED_TEXT:-$TM_CURRENT_WORD}")' http-equiv='Refresh'>" | ||
</string> | ||
<key>hideFromUser</key> | ||
<true/> | ||
<key>input</key> | ||
<string>none</string> | ||
<key>inputFormat</key> | ||
<string>text</string> | ||
<key>name</key> | ||
<string>Documentation for Word / Selection</string> | ||
<key>outputCaret</key> | ||
<string>afterOutput</string> | ||
<key>outputFormat</key> | ||
<string>html</string> | ||
<key>outputLocation</key> | ||
<string>newWindow</string> | ||
<key>scope</key> | ||
<string>source.ruby & attr.os-version.10.9</string> | ||
<key>semanticClass</key> | ||
<string>lookup.define.ruby</string> | ||
<key>uuid</key> | ||
<string>FE882491-07FA-4497-B675-97FCF2FC3BF5</string> | ||
<key>version</key> | ||
<integer>2</integer> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?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>content</key> | ||
<string>lookup.define.ruby</string> | ||
<key>keyEquivalent</key> | ||
<string>^h</string> | ||
<key>name</key> | ||
<string>Documentation for Word / Selection</string> | ||
<key>scope</key> | ||
<string>source.ruby</string> | ||
<key>uuid</key> | ||
<string>D5660BB2-C554-4694-9E0F-F20CDB6B9EA0</string> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
|
||
PHRASE=$1 | ||
|
||
DST=$(mktemp "${TMPDIR:-/tmp}/tm_ruby_ri_XXXXXX").html | ||
"$TM_BUNDLE_SUPPORT/bin/ri_to_html" &>"$DST" "$PHRASE" | ||
echo -n "$DST" | ||
|
||
{ sleep 300; rm "$DST"; rm "${DST%.html}"; } &>/dev/null & |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -wKU | ||
require "#{ENV['TM_SUPPORT_PATH']}/lib/tm/htmloutput.rb" | ||
require "shellwords" | ||
|
||
RI_EXE = '/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ri' | ||
|
||
def make_link(text, term) | ||
"<a href='javascript:lookup("#{term.shellescape}")' title='Lookup ‘#{term}’'>#{text}</a>" | ||
end | ||
|
||
phrase = *ARGV | ||
page = %x{ #{RI_EXE} --no-pager -f markdown #{phrase.shellescape} 2>&1 } | ||
|
||
page.gsub!(/&/, '&') | ||
page.gsub!(/</, '<') | ||
page.gsub!(/\b([A-Z][A-Za-z]+)(\.|::|#)([\w_]+\b[!?]?)/) do | ||
make_link($1, $1) + $2 + make_link($3, $&) | ||
end | ||
|
||
STDOUT << [0xFEFF].pack("U*") # Output UTF-8 ByteOrderMark since this is the only way I have been able to make WebKit show the file as UTF-8. It ignores the <meta> tag and it also ignores the com.apple.TextEncoding extended attribute. | ||
|
||
TextMate::HTMLOutput.show(:title => "Documentation for “#{phrase}”", :sub_title => `#{RI_EXE} --version`) do |io| | ||
io << '<script type="text/javascript">function lookup (phrase) { window.location="file://" + TextMate.system(\'"$TM_BUNDLE_SUPPORT/bin/ri_lookup" \' + phrase, null).outputString }</script>' << "\n" | ||
|
||
in_pre, whitespace = false, "" | ||
page.each_line do |line| | ||
if line =~ /^(#+) (.+)/ | ||
if in_pre | ||
io << "</pre>" | ||
in_pre = false | ||
end | ||
io << "<h#{$1.size}>#$2</h#{$1.size}>\n" | ||
elsif line =~ /^---$/ | ||
if in_pre | ||
io << "</pre>" | ||
in_pre = false | ||
end | ||
io << "<hr>\n" | ||
elsif line =~ /^\s*$/ | ||
whitespace << line | ||
else | ||
if in_pre | ||
io << whitespace | ||
else | ||
io << "<pre>\n" | ||
in_pre = true | ||
end | ||
io << line | ||
whitespace = "" | ||
end | ||
end | ||
|
||
io << "</pre>" if in_pre | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters