/
docs
executable file
·120 lines (93 loc) · 3.67 KB
/
docs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/env bash
rvm_base_except="selector"
source "$rvm_scripts_path/base"
rvm_docs_ruby_string="$(__rvm_env_string)"
rvm_docs_ruby_string="${rvm_docs_ruby_string%%${rvm_gemset_seperator:-"@"}*}"
if [[ "$rvm_docs_ruby_string" == "system" || -z "$rvm_docs_ruby_string" ]]
then
rvm_error "Currently 'rvm docs ...' does not work with non-rvm rubies."
exit 1
fi
[[ -d "${rvm_src_path}/$rvm_docs_ruby_string" ]] || (
action="fetch"
rubies_string="$rvm_docs_ruby_string"
source "$rvm_scripts_path"/manage
) || {
rvm_error "'rvm docs ...' requires ruby sources to be available but fetching failed, run \`rvm reinstall $rvm_docs_ruby_string --disable-binary\`"
exit 2
}
rvm_docs_type="${rvm_docs_type:-rdoc}"
# Ensure we have the doc directories.
[[ -d "${rvm_docs_path:-"$rvm_path/docs"}" ]] ||
mkdir -p "${rvm_docs_path:-"$rvm_path/docs"}/rdoc" "${rvm_docs_path:-"$rvm_path/docs"}/yard"
usage()
{
printf "%b" "
Usage:
rvm docs {open,generate,generate-ri,generate-rdoc}
"
return 0
}
open_docs()
{
if [[ -s "${rvm_docs_path:-"$rvm_path/docs"}/$rvm_docs_ruby_string/$rvm_docs_type/index.html" ]]
then
if
[[ "${DESKTOP_SESSION}" == "gnome" ]] && builtin command -v gnome-open >/dev/null
then
gnome-open "${rvm_docs_path:-"$rvm_path/docs"}/$rvm_docs_ruby_string/$rvm_docs_type/index.html" &>/dev/null
elif
[[ -n "${XDG_SESSION_COOKIE}" || -n "${XDG_SESSION_ID}" ]] && builtin command -v xdg-open >/dev/null
then
xdg-open "${rvm_docs_path:-"$rvm_path/docs"}/$rvm_docs_ruby_string/$rvm_docs_type/index.html" &>/dev/null
elif
builtin command -v open >/dev/null
then
open "${rvm_docs_path:-"$rvm_path/docs"}/$rvm_docs_ruby_string/$rvm_docs_type/index.html"
else
rvm_error "None of open, xdg-open or gnome-open were found, in order to open the docs one of these two are required. \n(OR you can let me know how else to open the html in your browser from comand line on your OS :) )"
fi
else
rvm_error "$rvm_docs_type docs are missing, perhaps run 'rvm docs generate' first?"
fi
}
generate_ri()
{
# Generate ri docs
(
chpwd_functions="" builtin cd "${rvm_src_path}/$rvm_docs_ruby_string/"
rvm_log "Generating ri documentation, be aware that this could take a *long* time, and depends heavily on your system resources..."
rvm_log "( Errors will be logged to ${rvm_log_path}/$rvm_docs_ruby_string/docs.log )"
rdoc -a --ri-site > /dev/null 2>> ${rvm_log_path}/$rvm_docs_ruby_string/docs.log
)
}
generate_rdoc()
{
(
chpwd_functions="" builtin cd "${rvm_src_path}/$rvm_docs_ruby_string/"
__rvm_rm_rf "${rvm_docs_path:-"$rvm_path/docs"}/$rvm_docs_ruby_string/$rvm_docs_type/"
rvm_log "Generating rdoc documentation, be aware that this could take a *long* time, and depends heavily on your system resources..."
rvm_log "( Errors will be logged to ${rvm_log_path}/$rvm_docs_ruby_string/docs.log )"
if gem list | GREP_OPTIONS="" \grep ^hanna >/dev/null 2>&1
then
hanna -o "${rvm_docs_path:-"$rvm_path/docs"}/$rvm_docs_ruby_string/$rvm_docs_type" --inline-source --line-numbers --fmt=html > /dev/null 2>> "${rvm_log_path}/$rvm_docs_ruby_string/docs.log"
else
rdoc -a -o "${rvm_docs_path:-"$rvm_path/docs"}/$rvm_docs_ruby_string/$rvm_docs_type" > /dev/null 2>> "${rvm_log_path}/$rvm_docs_ruby_string/docs.log"
fi
)
}
args=($*)
action="${args[0]}"
args=($(echo ${args[@]:1})) # Strip trailing / leading / extra spacing.
case "$action" in
generate)
generate_ri
generate_rdoc
;;
open) open_docs ;;
generate-ri) generate_ri ;;
generate-rdoc) generate_rdoc ;;
help) usage ;;
*) usage ; exit 1 ;;
esac
exit $?