source: extensions/gsdl-video/trunk/installed/cmdline/lib/ruby/1.8/rdoc/ri/ri_paths.rb@ 18425

Last change on this file since 18425 was 18425, checked in by davidb, 15 years ago

Video extension to Greenstone

File size: 2.4 KB
Line 
1module RI
2
3 # Encapsulate all the strangeness to do with finding out
4 # where to find RDoc files
5 #
6 # We basically deal with three directories:
7 #
8 # 1. The 'system' documentation directory, which holds
9 # the documentation distributed with Ruby, and which
10 # is managed by the Ruby install process
11 # 2. The 'site' directory, which contains site-wide
12 # documentation added locally.
13 # 3. The 'user' documentation directory, stored under the
14 # user's own home directory.
15 #
16 # There's contention about all this, but for now:
17 #
18 # system:: $datadir/ri/<ver>/system/...
19 # site:: $datadir/ri/<ver>/site/...
20 # user:: ~/.rdoc
21
22 module Paths
23
24 #:stopdoc:
25 require 'rbconfig'
26
27 DOC_DIR = "doc/rdoc"
28
29 version = Config::CONFIG['ruby_version']
30
31 base = File.join(Config::CONFIG['datadir'], "ri", version)
32 SYSDIR = File.join(base, "system")
33 SITEDIR = File.join(base, "site")
34 homedir = ENV['HOME'] || ENV['USERPROFILE'] || ENV['HOMEPATH']
35
36 if homedir
37 HOMEDIR = File.join(homedir, ".rdoc")
38 else
39 HOMEDIR = nil
40 end
41
42 # This is the search path for 'ri'
43 PATH = [ SYSDIR, SITEDIR, HOMEDIR ].find_all {|p| p && File.directory?(p)}
44
45 begin
46 require 'rubygems'
47 GEMDIRS = Dir["#{Gem.path}/doc/*/ri"]
48 GEMDIRS.each { |path| RI::Paths::PATH << path }
49 rescue LoadError
50 GEMDIRS = nil
51 end
52
53 # Returns the selected documentation directories as an Array, or PATH if no
54 # overriding directories were given.
55
56 def self.path(use_system, use_site, use_home, use_gems, *extra_dirs)
57 path = raw_path(use_system, use_site, use_home, use_gems, *extra_dirs)
58 return path.select { |path| File.directory? path }
59 end
60
61 # Returns the selected documentation directories including nonexistent
62 # directories. Used to print out what paths were searched if no ri was
63 # found.
64
65 def self.raw_path(use_system, use_site, use_home, use_gems, *extra_dirs)
66 return PATH unless use_system or use_site or use_home or use_gems or
67 not extra_dirs.empty?
68
69 path = []
70 path << extra_dirs unless extra_dirs.empty?
71 path << RI::Paths::SYSDIR if use_system
72 path << RI::Paths::SITEDIR if use_site
73 path << RI::Paths::HOMEDIR if use_home
74 path << RI::Paths::GEMDIRS if use_gems
75
76 return path.flatten.compact
77 end
78
79 end
80end
Note: See TracBrowser for help on using the repository browser.