docs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #!/usr/bin/env bash
  2. source "$rvm_scripts_path/base"
  3. source "$rvm_scripts_path/functions/gemset"
  4. rvm_docs_ruby_string="$(__rvm_env_string)"
  5. rvm_docs_ruby_string="${rvm_docs_ruby_string%%${rvm_gemset_seperator:-"@"}*}"
  6. if [[ "$rvm_docs_ruby_string" == "system" || -z "$rvm_docs_ruby_string" ]]
  7. then
  8. rvm_error "Currently 'rvm docs ...' does not work with non-rvm rubies."
  9. exit 1
  10. fi
  11. install_ruby_source()
  12. {
  13. [[ -d "${rvm_src_path}/$rvm_docs_ruby_string" ]] || (
  14. action="fetch"
  15. rubies_string="$rvm_docs_ruby_string"
  16. source "$rvm_scripts_path"/manage
  17. ) || {
  18. rvm_error "'rvm docs ...' requires ruby sources to be available but fetching failed, run \`rvm reinstall $rvm_docs_ruby_string --disable-binary\`"
  19. exit 2
  20. }
  21. }
  22. rvm_docs_type="${rvm_docs_type:-rdoc}"
  23. # Ensure we have the doc directories.
  24. [[ -d "${rvm_docs_path:-"$rvm_path/docs"}" ]] ||
  25. mkdir -p "${rvm_docs_path:-"$rvm_path/docs"}/rdoc" "${rvm_docs_path:-"$rvm_path/docs"}/yard"
  26. open_docs()
  27. {
  28. if [[ -s "${rvm_docs_path:-"$rvm_path/docs"}/$rvm_docs_ruby_string/$rvm_docs_type/index.html" ]]
  29. then
  30. if
  31. [[ "${DESKTOP_SESSION}" == "gnome" ]] && builtin command -v gnome-open >/dev/null
  32. then
  33. gnome-open "${rvm_docs_path:-"$rvm_path/docs"}/$rvm_docs_ruby_string/$rvm_docs_type/index.html" &>/dev/null
  34. elif
  35. [[ -n "${XDG_SESSION_COOKIE}" || -n "${XDG_SESSION_ID}" ]] && builtin command -v xdg-open >/dev/null
  36. then
  37. xdg-open "${rvm_docs_path:-"$rvm_path/docs"}/$rvm_docs_ruby_string/$rvm_docs_type/index.html" &>/dev/null
  38. elif
  39. builtin command -v open >/dev/null
  40. then
  41. open "${rvm_docs_path:-"$rvm_path/docs"}/$rvm_docs_ruby_string/$rvm_docs_type/index.html"
  42. else
  43. 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 :) )"
  44. fi
  45. else
  46. rvm_error "$rvm_docs_type docs are missing, perhaps run 'rvm docs generate' first?"
  47. fi
  48. }
  49. run_rdoc()
  50. {
  51. update_rdoc
  52. if rdoc -V --help >/dev/null 2>&1
  53. then rdoc -V "$@" || return $?
  54. else rdoc "$@" || return $?
  55. fi
  56. }
  57. generate_ri()
  58. {
  59. install_ruby_source
  60. (
  61. __rvm_cd "${rvm_src_path}/$rvm_docs_ruby_string/"
  62. __rvm_log_command "generate_ri" "Generating ri documentation" run_rdoc -a --ri-site
  63. )
  64. }
  65. generate_rdoc()
  66. {
  67. install_ruby_source
  68. (
  69. __rvm_cd "${rvm_src_path}/$rvm_docs_ruby_string/"
  70. if
  71. gem list | __rvm_grep ^hanna >/dev/null 2>&1
  72. then
  73. __rvm_log_command "generate_hanna" "Generating hanna documentation" \
  74. hanna -o "${rvm_docs_path:-"$rvm_path/docs"}/$rvm_docs_ruby_string/$rvm_docs_type" --inline-source --line-numbers --fmt=html
  75. else
  76. __rvm_log_command "generate_rdoc" "Generating rdoc documentation" \
  77. run_rdoc -a -o "${rvm_docs_path:-"$rvm_path/docs"}/$rvm_docs_ruby_string/$rvm_docs_type"
  78. fi
  79. )
  80. }
  81. generate_gems()
  82. {
  83. __rvm_log_command "generate_gems" "Generating gems documentation" \command \gem rdoc --all --ri
  84. }
  85. update_rdoc()
  86. {
  87. if
  88. (( rdoc_installed == 0 ))
  89. then
  90. rdoc_installed=1
  91. gem_install rdoc
  92. fi
  93. }
  94. install_rdoc_data()
  95. {
  96. __rvm_use ${rvm_docs_ruby_string%%@*}@global
  97. update_rdoc
  98. gem list rdoc-data | __rvm_grep "^rdoc" || gem install rdoc-data
  99. rdoc-data --install
  100. }
  101. generate_docs()
  102. {
  103. case "${rvm_docs_ruby_string}" in
  104. (*1.8.7*|*1.9.2*|*1.9.3*|*2.0.0*|jruby*|rbx*)
  105. __rvm_log_command install_rdoc_data "Installing rdoc-data" \
  106. install_rdoc_data || return $?
  107. ;;
  108. (*)
  109. generate_ri
  110. generate_rdoc
  111. ;;
  112. esac
  113. generate_gems
  114. }
  115. args=($*)
  116. action="${args[0]}"
  117. args=($(echo ${args[@]:1})) # Strip trailing / leading / extra spacing.
  118. rdoc_installed=0
  119. case "$action" in
  120. rdoc_data) install_rdoc_data ;;
  121. generate) generate_docs ;;
  122. generate-ri) generate_ri ;;
  123. generate-rdoc) generate_rdoc ;;
  124. generate-gems) generate_gems ;;
  125. open) open_docs ;;
  126. help) rvm_help docs ;;
  127. *)
  128. rvm_help docs
  129. exit 1
  130. ;;
  131. esac