mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-08-27 05:57:04 +00:00
215 lines
6.9 KiB
Plaintext
215 lines
6.9 KiB
Plaintext
<?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>[[ -z $OBJJ_HOME ]] && echo "OBJJ_HOME wasn't set!" && exit 206
|
||
[[ ! -d "$OBJJ_HOME/Documentation" ]] && echo "Please copy the folder ‘Documentation’ to $OBJJ_HOME" && exit 206
|
||
|
||
function showUpClassPage {
|
||
cat <<-HTM
|
||
<body onload='javascript:window.location.href="tm-file://$OBJJ_HOME/Documentation/class$1"'>
|
||
</body>
|
||
HTM
|
||
exit 205
|
||
}
|
||
|
||
function showUpPage {
|
||
cat <<-HTM
|
||
<body onload='javascript:window.location.href="tm-file://$1"'>
|
||
</body>
|
||
HTM
|
||
exit 205
|
||
}
|
||
|
||
|
||
DOCHEAD=$(perl -e '
|
||
#$line_nr = defined($ENV{"TM_INPUT_START_LINE"}) ? $ENV{"TM_INPUT_START_LINE"} : 1;
|
||
$line_nr = 1;
|
||
$cur_line_nr = $ENV{"TM_LINE_NUMBER"};
|
||
$header = "";
|
||
while($cur_line_nr-->$line_nr) {$header.=<>;}
|
||
$tail = <>;
|
||
$header .= substr($tail,0,$ENV{"TM_LINE_INDEX"});
|
||
print $header;
|
||
')
|
||
|
||
# caret is inside of a class name
|
||
if [ `echo $TM_SCOPE | grep -c 'support.class.cappuccino'` -gt 0 ]; then
|
||
n=$(echo $TM_CURRENT_WORD | perl -pe 's/(.)(.)(.*)/_$1_$2_$3/;s/(?<!_)([A-Z])(?!_)/_$1/g;s/_{2,}/_/g')
|
||
showUpClassPage "$n.html"
|
||
fi
|
||
|
||
# caret is inside of a foundation class name
|
||
if [ `echo $TM_SCOPE | grep -c 'support.variable.cappuccino.foundation'` -gt 0 ]; then
|
||
[[ "$TM_CURRENT_WORD" == "CPApp" ]] && showUpClassPage "_C_P_Application.html"
|
||
fi
|
||
|
||
# caret is inside of a objj function
|
||
if [ `echo $TM_SCOPE | grep -c 'support.function.cappuccino'` -gt 0 ]; then
|
||
FILE=$(ruby -e '
|
||
require File.join(ENV["TM_SUPPORT_PATH"], "lib/ui.rb")
|
||
require File.join(ENV["TM_SUPPORT_PATH"], "lib/exit_codes.rb")
|
||
cur_word = ""
|
||
cur_word << ENV["TM_CURRENT_WORD"]
|
||
cur_word.sub!("CG", "C[GP]") if cur_word[0..1] == "CG" or cur_word[0..1] == "CP"
|
||
lg = %x{egrep -rl "C[GP]RectMake" '$OBJJ_HOME/Documentation'}
|
||
urls = lg.split(/\n/).sort
|
||
if urls.length == 1
|
||
print urls.first
|
||
else
|
||
display = urls.map{|x| x.split("/").last.sub!(".html","")}
|
||
index=TextMate::UI.menu(display)
|
||
if index != nil
|
||
print urls[index]
|
||
else
|
||
TextMate.exit_discard()
|
||
end
|
||
end
|
||
')
|
||
FUNC=$(echo -en $TM_CURRENT_WORD | perl -pe 's/^(C[PG])(.*)/C[PG]$2/')
|
||
ANKER=`cat "$FILE" | egrep -o "\"#$FUNC.*?\"" | sed -e 's/^"//;s/".*//' | head -n 1`
|
||
[[ ! -z "$ANKER" ]] && showUpPage "$FILE$ANKER"
|
||
[[ ! -z $FILE ]] && showUpPage "$FILE" && exit 206
|
||
fi
|
||
|
||
# caret is inside of a constant
|
||
if [ `echo $TM_SCOPE | grep -c 'support.constant.cappuccino'` -gt 0 ]; then
|
||
FILE=$(ruby -e '
|
||
require File.join(ENV["TM_SUPPORT_PATH"], "lib/ui.rb")
|
||
require File.join(ENV["TM_SUPPORT_PATH"], "lib/exit_codes.rb")
|
||
lg = %x{egrep -rl #{ENV["TM_CURRENT_WORD"]} '$OBJJ_HOME/Documentation'}
|
||
urls = lg.split(/\n/).sort
|
||
if urls.length == 1
|
||
print urls.first
|
||
else
|
||
display = urls.map{|x| x.split("/").last.sub!(".html","")}
|
||
index=TextMate::UI.menu(display)
|
||
if index != nil
|
||
print urls[index]
|
||
else
|
||
TextMate.exit_discard()
|
||
end
|
||
end
|
||
')
|
||
[[ ! -z $FILE ]] && showUpPage "$FILE" && exit 206
|
||
fi
|
||
|
||
# caret is inside of [method]
|
||
if [ `echo $TM_SCOPE | grep -c 'meta.bracketed.js.objj'` -gt 0 ]; then
|
||
# find []
|
||
DECL=$(echo -en "$DOCHEAD" | perl -e '
|
||
undef $/;
|
||
$header = <>;
|
||
$header=~s/\n/ /g;
|
||
@arr=split(//,$header);$c=0;
|
||
for($i=$#arr;$i>-1;$i--){$c-- if($arr[$i] eq "]");$c++ if($arr[$i] eq "[");last if $c>0;}
|
||
if($i==-1) {
|
||
print "";
|
||
} else {
|
||
print substr($header,$i+1);
|
||
}
|
||
')
|
||
|
||
# find the class for a method
|
||
CLASS=$(echo -en "$DECL" | perl -e '
|
||
undef $/;
|
||
$header = <>;
|
||
substr($header,0) =~ m/^\s*(\w+).*/;
|
||
$f = $1;
|
||
if (defined($f)) {
|
||
if($f=~m/CPApp/) {
|
||
print "CPApplication";
|
||
} else {
|
||
print $f;
|
||
}
|
||
} else {
|
||
substr($header,1) =~ m/^\s*(\w+).*/;
|
||
$f = $1;
|
||
if(defined($f)) {
|
||
if($f=~m/CPApp/) {
|
||
print "CPApplication";
|
||
} else {
|
||
print $f;
|
||
}
|
||
}
|
||
}
|
||
')
|
||
if [ ! -e "$OBJJ_HOME/Documentation/classes/$CLASS.html" ]; then
|
||
CLASS=$(echo -en "$DOCHEAD" | ruby -e '
|
||
require File.join(ENV["TM_SUPPORT_PATH"], "lib/ui.rb")
|
||
require File.join(ENV["TM_SUPPORT_PATH"], "lib/exit_codes.rb")
|
||
known_classes = []
|
||
classes = []
|
||
lg = %x{cd '$OBJJ_HOME/Documentation/classes'; egrep -rl #{ENV["TM_CURRENT_WORD"]} .}
|
||
known_classes = lg.split(/\n/).map{|x| x.sub("\.html","").sub("./","") }.sort
|
||
if known_classes.empty?
|
||
lg = %x{ls '$OBJJ_HOME/Documentation/classes'}
|
||
known_classes = lg.split(/\n/).map{|x| x.sub("\.html","").sub("./","") }.sort
|
||
end
|
||
STDIN.read().scan(/\b[_]{0,2}[NC][APS]\w+(?=[^\.])\b/) {|c| classes << c if ! classes.include?(c) && known_classes.include?(c)}
|
||
classes.sort!
|
||
if classes != known_classes
|
||
classes << "--"
|
||
classes += known_classes
|
||
end
|
||
if classes.length == 1
|
||
if classes.first != "--"
|
||
print classes.first
|
||
else
|
||
TextMate.exit_discard()
|
||
end
|
||
else
|
||
index=TextMate::UI.menu(classes)
|
||
if index != nil
|
||
print classes[index]
|
||
else
|
||
TextMate.exit_discard()
|
||
end
|
||
end
|
||
')
|
||
fi
|
||
[[ -z $CLASS ]] && exit 200
|
||
[[ ! -e "$OBJJ_HOME/Documentation/classes/$CLASS.html" ]] && echo "Nothing for '$CLASS'!" && exit 206
|
||
# tries to find only the first method for 'method1: method2: etc'
|
||
FIRSTMETHOD=$(echo -en "$DECL" | perl -e '
|
||
undef $/;$d = <>;
|
||
$d=~m/\s*(\w+):/m;
|
||
print $1;
|
||
')
|
||
METHOD=${FIRSTMETHOD:-$TM_CURRENT_WORD}
|
||
|
||
# find the correct anker within CLASS.html
|
||
ANKER=`cat "$OBJJ_HOME/Documentation/classes/$CLASS.html" | egrep -o "\"#$METHOD.*?\"" | sed -e 's/^"//;s/".*//' | head -n 1`
|
||
[[ ! -z "$ANKER" ]] && showUpClassPage "$CLASS.html$ANKER"
|
||
|
||
# check for inherited methods
|
||
ANKER=`cat "$OBJJ_HOME/Documentation/classes/$CLASS.html" | egrep -o "[^#\"]+?html#$METHOD" | head -n 1`
|
||
# echo $CLASS; echo $METHOD; echo $ANKER; exit 206
|
||
|
||
CLASS=$(echo -en "$ANKER" | perl -pe 's/(.*?)\.html.*/$1/;')
|
||
# find the correct anker within the new CLASS.html
|
||
ANKER=`cat "$OBJJ_HOME/Documentation/classes/$CLASS.html" | egrep -o "\"#$METHOD.*?\"" | sed -e 's/^"//;s/".*//' | head -n 1`
|
||
[[ ! -z "$ANKER" ]] && showUpClassPage "$CLASS.html$ANKER"
|
||
# [[ ! -z "$ANKER" ]] && showUpClassPage "$ANKER"
|
||
|
||
fi
|
||
|
||
exit 205</string>
|
||
<key>input</key>
|
||
<string>selection</string>
|
||
<key>keyEquivalent</key>
|
||
<string>^h</string>
|
||
<key>name</key>
|
||
<string>Documentation for Word</string>
|
||
<key>output</key>
|
||
<string>replaceSelectedText</string>
|
||
<key>scope</key>
|
||
<string>support.class.cappuccino, support.variable.cappuccino.foundation, meta.bracketed.js.objj, support.function.cappuccino</string>
|
||
<key>uuid</key>
|
||
<string>2D05A28A-2ED7-4A9A-9A5C-8625466BC77C</string>
|
||
</dict>
|
||
</plist>
|