bitclust-core 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. checksums.yaml +7 -0
  2. data/ChangeLog +7 -0
  3. data/Gemfile +1 -0
  4. data/bitclust.gemspec +1 -0
  5. data/data/bitclust/template.offline/class +1 -1
  6. data/lib/bitclust/crossrubyutils.rb +2 -2
  7. data/lib/bitclust/methodentry.rb +1 -2
  8. data/lib/bitclust/progress_bar.rb +7 -0
  9. data/lib/bitclust/rdcompiler.rb +1 -1
  10. data/lib/bitclust/runner.rb +46 -32
  11. data/lib/bitclust/searcher.rb +14 -13
  12. data/lib/bitclust/silent_progress_bar.rb +17 -0
  13. data/lib/bitclust/subcommand.rb +27 -0
  14. data/lib/bitclust/subcommands/ancestors_command.rb +145 -0
  15. data/lib/bitclust/subcommands/chm_command.rb +268 -0
  16. data/lib/bitclust/subcommands/classes_command.rb +73 -0
  17. data/lib/bitclust/subcommands/extract_command.rb +55 -0
  18. data/lib/bitclust/subcommands/htmlfile_command.rb +105 -0
  19. data/lib/bitclust/subcommands/init_command.rb +29 -30
  20. data/lib/bitclust/subcommands/list_command.rb +39 -41
  21. data/lib/bitclust/subcommands/lookup_command.rb +71 -73
  22. data/lib/bitclust/subcommands/methods_command.rb +159 -0
  23. data/lib/bitclust/subcommands/preproc_command.rb +35 -0
  24. data/lib/bitclust/subcommands/property_command.rb +47 -48
  25. data/lib/bitclust/subcommands/query_command.rb +12 -18
  26. data/lib/bitclust/subcommands/server_command.rb +180 -182
  27. data/lib/bitclust/subcommands/setup_command.rb +85 -89
  28. data/lib/bitclust/subcommands/statichtml_command.rb +276 -0
  29. data/lib/bitclust/subcommands/update_command.rb +39 -41
  30. data/lib/bitclust/version.rb +1 -1
  31. data/test/test_bitclust.rb +1 -1
  32. data/test/test_rdcompiler.rb +1 -1
  33. data/test/test_runner.rb +7 -14
  34. metadata +120 -114
@@ -8,116 +8,112 @@ require 'yaml'
8
8
  require 'bitclust'
9
9
  require 'bitclust/subcommand'
10
10
 
11
- module BitClust::Subcommands
12
- class SetupCommand < BitClust::Subcommand
11
+ module BitClust
12
+ module Subcommands
13
+ class SetupCommand < Subcommand
13
14
 
14
- REPOSITORY_PATH = "http://jp.rubyist.net/svn/rurema/doctree/trunk"
15
+ REPOSITORY_PATH = "http://jp.rubyist.net/svn/rurema/doctree/trunk"
15
16
 
16
- def initialize
17
- @prepare = nil
18
- @cleanup = nil
19
- @versions = ["1.8.7", "1.9.3", "2.0.0"]
20
- @parser = OptionParser.new {|opt|
21
- opt.banner = "Usage: #{File.basename($0, '.*')} setup [options]"
22
- opt.on('--prepare', 'Prepare config file and checkout repository. Do not create database.') {
17
+ def initialize
18
+ super
19
+ @prepare = nil
20
+ @cleanup = nil
21
+ @versions = ["1.8.7", "1.9.3", "2.0.0"]
22
+ @parser.banner = "Usage: #{File.basename($0, '.*')} setup [options]"
23
+ @parser.on('--prepare', 'Prepare config file and checkout repository. Do not create database.') {
23
24
  @prepare = true
24
25
  }
25
- opt.on('--cleanup', 'Cleanup datebase before create database.') {
26
+ @parser.on('--cleanup', 'Cleanup datebase before create database.') {
26
27
  @cleanup = true
27
28
  }
28
- opt.on('--versions=V1,V2,...', "Specify versions. [#{@versions.join(',')}]") {|versions|
29
+ @parser.on('--versions=V1,V2,...', "Specify versions. [#{@versions.join(',')}]") {|versions|
29
30
  @versions = versions.split(",")
30
31
  }
31
- opt.on('--help', 'Prints this message and quit.') {
32
- puts opt.help
33
- exit 0
34
- }
35
- }
36
- end
32
+ end
37
33
 
38
- def exec(db, argv)
39
- prepare
40
- return if @prepare
41
- @config[:versions].each do |version|
42
- puts "Generating database for Ruby#{version}..."
43
- prefix = "#{@config[:database_prefix]}-#{version}"
44
- FileUtils.rm_rf(prefix) if @cleanup
45
- init_argv = ["version=#{version}", "encoding=#{@config[:encoding]}"]
46
- db = BitClust::MethodDatabase.new(prefix)
47
- InitCommand.new.exec(db, init_argv)
48
- update_method_database(prefix, ["--stdlibtree=#{@config[:stdlibtree]}"])
49
- argv = Pathname(@config[:capi_src]).children.select(&:file?).map{|v| v.realpath.to_s }
50
- update_function_database(prefix, argv)
34
+ def exec(argv, options)
35
+ prepare
36
+ return if @prepare
37
+ @config[:versions].each do |version|
38
+ puts "Generating database for Ruby#{version}..."
39
+ prefix = "#{@config[:database_prefix]}-#{version}"
40
+ FileUtils.rm_rf(prefix) if @cleanup
41
+ init_argv = ["version=#{version}", "encoding=#{@config[:encoding]}"]
42
+ init_options = { :prefix => prefix }
43
+ InitCommand.new.exec(init_argv, init_options)
44
+ update_method_database(prefix, ["--stdlibtree=#{@config[:stdlibtree]}"])
45
+ update_argv = Pathname(@config[:capi_src]).children.select(&:file?).map{|v| v.realpath.to_s }
46
+ update_function_database(prefix, update_argv)
47
+ end
51
48
  end
52
- end
53
49
 
54
- private
50
+ private
55
51
 
56
- def prepare
57
- home_directory = Pathname(ENV["HOME"])
58
- config_dir = home_directory + ".bitclust"
59
- config_dir.mkpath
60
- config_path = config_dir + "config"
61
- rubydoc_dir = config_dir + "rubydoc"
62
- @config = {
63
- :database_prefix => (config_dir + "db").to_s,
64
- :encoding => "utf-8",
65
- :versions => @versions,
66
- :default_version => @versions.max,
67
- :stdlibtree => (rubydoc_dir + "refm/api/src").to_s,
68
- :capi_src => (rubydoc_dir + "refm/capi/src/").to_s,
69
- :baseurl => "http://localhost:10080",
70
- :port => "10080",
71
- :pid_file => "/tmp/bitclust.pid",
72
- }
73
- if config_path.exist?
74
- @config = YAML.load_file(config_path)
75
- unless @config[:versions].sort == @versions.sort
76
- print("overwrite config file? > [y/N]")
77
- if /\Ay\z/i =~ $stdin.gets.chomp
78
- @config[:versions] = @versions
79
- @config[:default_version] = @versions.max
80
- generate_config(config_path, @config)
52
+ def prepare
53
+ home_directory = Pathname(ENV["HOME"])
54
+ config_dir = home_directory + ".bitclust"
55
+ config_dir.mkpath
56
+ config_path = config_dir + "config"
57
+ rubydoc_dir = config_dir + "rubydoc"
58
+ @config = {
59
+ :database_prefix => (config_dir + "db").to_s,
60
+ :encoding => "utf-8",
61
+ :versions => @versions,
62
+ :default_version => @versions.max,
63
+ :stdlibtree => (rubydoc_dir + "refm/api/src").to_s,
64
+ :capi_src => (rubydoc_dir + "refm/capi/src/").to_s,
65
+ :baseurl => "http://localhost:10080",
66
+ :port => "10080",
67
+ :pid_file => "/tmp/bitclust.pid",
68
+ }
69
+ if config_path.exist?
70
+ @config = YAML.load_file(config_path)
71
+ unless @config[:versions].sort == @versions.sort
72
+ print("overwrite config file? > [y/N]")
73
+ if /\Ay\z/i =~ $stdin.gets.chomp
74
+ @config[:versions] = @versions
75
+ @config[:default_version] = @versions.max
76
+ generate_config(config_path, @config)
77
+ end
81
78
  end
79
+ else
80
+ generate_config(config_path, @config)
82
81
  end
83
- else
84
- generate_config(config_path, @config)
82
+ checkout(rubydoc_dir)
85
83
  end
86
- checkout(rubydoc_dir)
87
- end
88
84
 
89
- def generate_config(path, config)
90
- path.open("w+", 0644) do |file|
91
- file.puts config.to_yaml
85
+ def generate_config(path, config)
86
+ path.open("w+", 0644) do |file|
87
+ file.puts config.to_yaml
88
+ end
92
89
  end
93
- end
94
90
 
95
- def checkout(rubydoc_dir)
96
- case RUBY_PLATFORM
97
- when /mswin(?!ce)|mingw|cygwin|bccwin/
98
- cmd = "svn help > NUL 2> NUL"
99
- else
100
- cmd = "svn help > /dev/null 2> /dev/null"
101
- end
102
- unless system(cmd)
103
- warn "svn command is not found. Please install Subversion."
104
- exit 1
91
+ def checkout(rubydoc_dir)
92
+ unless system("svn", "co", REPOSITORY_PATH, rubydoc_dir.to_s)
93
+ warn "svn command failed. Please install Subversion or check your PATH."
94
+ exit 1
95
+ end
105
96
  end
106
- system("svn", "co", REPOSITORY_PATH, rubydoc_dir.to_s)
107
- end
108
97
 
109
- def update_method_database(prefix, argv)
110
- db = BitClust::MethodDatabase.new(prefix)
111
- cmd = UpdateCommand.new
112
- cmd.parse(argv)
113
- cmd.exec(db, argv)
114
- end
98
+ def update_method_database(prefix, argv)
99
+ options = {
100
+ :prefix => prefix,
101
+ :capi => false,
102
+ }
103
+ cmd = UpdateCommand.new
104
+ cmd.parse(argv)
105
+ cmd.exec(argv, options)
106
+ end
115
107
 
116
- def update_function_database(prefix, argv)
117
- db = BitClust::FunctionDatabase.new(prefix)
118
- cmd = UpdateCommand.new
119
- cmd.parse(argv)
120
- cmd.exec(db, argv)
108
+ def update_function_database(prefix, argv)
109
+ options = {
110
+ :prefix => prefix,
111
+ :capi => true,
112
+ }
113
+ cmd = UpdateCommand.new
114
+ cmd.parse(argv)
115
+ cmd.exec(argv, options)
116
+ end
121
117
  end
122
118
  end
123
119
  end
@@ -0,0 +1,276 @@
1
+ # Copyright (c) 2006-2007 Minero Aoki
2
+ #
3
+ # This program is free software.
4
+ # You can distribute/modify this program under the Ruby License.
5
+ #
6
+
7
+ require 'fileutils'
8
+
9
+ require 'bitclust'
10
+ require 'bitclust/subcommand'
11
+ require 'bitclust/progress_bar'
12
+ require 'bitclust/silent_progress_bar'
13
+
14
+ module BitClust
15
+ module Subcommands
16
+ class StatichtmlCommand < Subcommand
17
+ class URLMapperEx < URLMapper
18
+ def library_url(name)
19
+ if name == '/'
20
+ $bitclust_html_base + "/library/index.html"
21
+ else
22
+ $bitclust_html_base + "/library/#{encodename_package(name)}.html"
23
+ end
24
+ end
25
+
26
+ def class_url(name)
27
+ $bitclust_html_base + "/class/#{encodename_package(name)}.html"
28
+ end
29
+
30
+ def method_url(spec)
31
+ cname, tmark, mname = *split_method_spec(spec)
32
+ $bitclust_html_base +
33
+ "/method/#{encodename_package(cname)}/#{typemark2char(tmark)}/#{encodename_package(mname)}.html"
34
+ end
35
+
36
+ def function_url(name)
37
+ $bitclust_html_base + "/function/#{name.empty? ? 'index' : name}.html"
38
+ end
39
+
40
+ def document_url(name)
41
+ $bitclust_html_base + "/doc/#{encodename_package(name)}.html"
42
+ end
43
+
44
+ def css_url
45
+ $bitclust_html_base + "/" + @css_url
46
+ end
47
+
48
+ def favicon_url
49
+ $bitclust_html_base + "/" + @favicon_url
50
+ end
51
+
52
+ def library_index_url
53
+ $bitclust_html_base + "/library/index.html"
54
+ end
55
+
56
+ def function_index_url
57
+ $bitclust_html_base + "/function/index.html"
58
+ end
59
+
60
+ def encodename_package(str)
61
+ if $fs_casesensitive
62
+ NameUtils.encodename_url(str)
63
+ else
64
+ NameUtils.encodename_fs(str)
65
+ end
66
+ end
67
+ end
68
+
69
+ def initialize
70
+ if Object.const_defined?(:Encoding)
71
+ Encoding.default_external = 'utf-8'
72
+ end
73
+ super
74
+ @verbose = true
75
+ @catalogdir = nil
76
+ @templatedir = srcdir_root + "data/bitclust/template.offline"
77
+ @themedir = srcdir_root + "theme/default"
78
+ @parser.banner = "Usage: #{File.basename($0, '.*')} statichtml [options]"
79
+ @parser.on('-o', '--outputdir=PATH', 'Output directory') do |path|
80
+ begin
81
+ @outputdir = Pathname.new(path).realpath
82
+ rescue Errno::ENOENT
83
+ FileUtils.mkdir_p(path, :verbose => @verbose)
84
+ retry
85
+ end
86
+ end
87
+ @parser.on('--catalog=PATH', 'Catalog directory') do |path|
88
+ @catalogdir = Pathname.new(path).realpath
89
+ end
90
+ @parser.on('--templatedir=PATH', 'Template directory') do |path|
91
+ @templatedir = Pathname.new(path).realpath
92
+ end
93
+ @parser.on('--themedir=PATH', 'Theme directory') do |path|
94
+ @themedir = Pathname.new(path).realpath
95
+ end
96
+ @parser.on('--fs-casesensitive', 'Filesystem is case-sensitive') do
97
+ $fs_casesensitive = true
98
+ end
99
+ @parser.on('--[no-]quiet', 'Be quiet') do |quiet|
100
+ @verbose = !quiet
101
+ end
102
+ end
103
+
104
+ def exec(argv, options)
105
+ create_manager_config
106
+
107
+ prefix = options[:prefix]
108
+ db = MethodDatabase.new(prefix.to_s)
109
+ fdb = FunctionDatabase.new(prefix.to_s)
110
+ manager = ScreenManager.new(@manager_config)
111
+
112
+ db.transaction do
113
+ methods = {}
114
+ db.methods.each_with_index do |entry, i|
115
+ entry.names.each do |name|
116
+ method_name = entry.klass.name + entry.typemark + name
117
+ (methods[method_name] ||= []) << entry
118
+ end
119
+ end
120
+
121
+ entries = db.docs + db.libraries.sort + db.classes.sort
122
+ create_html_entries("entries", entries, manager, db)
123
+ create_html_methods("methods", methods, manager, db)
124
+ end
125
+
126
+ fdb.transaction do
127
+ functions = {}
128
+ create_html_entries("capi", fdb.functions, manager, fdb)
129
+ end
130
+
131
+ $bitclust_html_base = '..'
132
+ create_file(@outputdir + 'library/index.html',
133
+ manager.library_index_screen(db.libraries.sort, {:database => db}).body,
134
+ :verbose => @verbose)
135
+ create_file(@outputdir + 'class/index.html',
136
+ manager.class_index_screen(db.classes.sort, {:database => db}).body,
137
+ :verbose => @verbose)
138
+ create_file(@outputdir + 'function/index.html',
139
+ manager.function_index_screen(fdb.functions.sort, { :database => fdb }).body,
140
+ :verbose => @verbose)
141
+ create_index_html(@outputdir)
142
+ FileUtils.cp(@manager_config[:themedir] + @manager_config[:css_url],
143
+ @outputdir.to_s, {:verbose => @verbose, :preserve => true})
144
+ FileUtils.cp(@manager_config[:themedir] + @manager_config[:favicon_url],
145
+ @outputdir.to_s, {:verbose => @verbose, :preserve => true})
146
+ Dir.mktmpdir do |tmpdir|
147
+ FileUtils.cp_r(@manager_config[:themedir] + 'images', tmpdir,
148
+ {:verbose => @verbose, :preserve => true})
149
+ Dir.glob(File.join(tmpdir, 'images', '/**/.svn')).each do |d|
150
+ FileUtils.rm_r(d, {:verbose => @verbose})
151
+ end
152
+ FileUtils.cp_r(File.join(tmpdir, 'images'), @outputdir.to_s,
153
+ {:verbose => @verbose, :preserve => true})
154
+ end
155
+ end
156
+
157
+ private
158
+
159
+ def create_manager_config
160
+ @manager_config = {
161
+ :catalogdir => @catalogdir,
162
+ :suffix => '.html',
163
+ :templatedir => @templatedir,
164
+ :themedir => @themedir,
165
+ :css_url => 'style.css',
166
+ :favicon_url => 'rurema.png',
167
+ :cgi_url => '',
168
+ :tochm_mode => true
169
+ }
170
+ @manager_config[:urlmapper] = URLMapperEx.new(@manager_config)
171
+ end
172
+
173
+ def create_html_entries(title, entries, manager, db)
174
+ original_title = title.dup
175
+ if @verbose
176
+ progressbar = ProgressBar.new(title, entries.size)
177
+ else
178
+ progressbar = SilentProgressBar.new(title, entries.size)
179
+ end
180
+ entries.each do |entry|
181
+ create_html_file(entry, manager, @outputdir, db)
182
+ progressbar.title.replace([entry].flatten.first.name)
183
+ progressbar.inc
184
+ end
185
+ progressbar.title.replace(original_title)
186
+ progressbar.finish
187
+ end
188
+
189
+ def create_html_methods(title, methods, manager, db)
190
+ original_title = title.dup
191
+ if @verbose
192
+ progressbar = ProgressBar.new(title, methods.size)
193
+ else
194
+ progressbar = SilentProgressBar.new(title, methods.size)
195
+ end
196
+ methods.each do |method_name, method_entries|
197
+ create_html_method_file(method_name, method_entries, manager, @outputdir, db)
198
+ progressbar.title.replace(method_name)
199
+ progressbar.inc
200
+ end
201
+ progressbar.title.replace(original_title)
202
+ progressbar.finish
203
+ end
204
+
205
+ def create_index_html(outputdir)
206
+ path = outputdir + 'index.html'
207
+ File.open(path, 'w'){|io|
208
+ io.write <<HERE
209
+ <meta http-equiv="refresh" content="0; URL=doc/index.html">
210
+ <a href="doc/index.html">Go</a>
211
+ HERE
212
+ }
213
+ end
214
+
215
+ def create_html_file(entry, manager, outputdir, db)
216
+ e = entry.is_a?(Array) ? entry.sort.first : entry
217
+ case e.type_id
218
+ when :library, :class, :doc
219
+ $bitclust_html_base = '..'
220
+ path = outputdir + e.type_id.to_s + (encodename_package(e.name) + '.html')
221
+ create_html_file_p(entry, manager, path, db)
222
+ path.relative_path_from(outputdir).to_s
223
+ when :function
224
+ create_html_function_file(entry, manager, outputdir, db)
225
+ else
226
+ raise
227
+ end
228
+ e.unload
229
+ end
230
+
231
+ def create_html_method_file(method_name, entries, manager, outputdir, db)
232
+ path = nil
233
+ $bitclust_html_base = '../../..'
234
+ e = entries.sort.first
235
+ name = method_name.sub(e.klass.name + e.typemark, "")
236
+ path = outputdir + e.type_id.to_s + encodename_package(e.klass.name) +
237
+ e.typechar + (encodename_package(name) + '.html')
238
+ create_html_file_p(entries, manager, path, db)
239
+ path.relative_path_from(outputdir).to_s
240
+ end
241
+
242
+ def create_html_function_file(entry, manager, outputdir, db)
243
+ path = nil
244
+ $bitclust_html_base = '..'
245
+ path = outputdir + entry.type_id.to_s + (entry.name + '.html')
246
+ create_html_file_p(entry, manager, path, db)
247
+ path.relative_path_from(outputdir).to_s
248
+ end
249
+
250
+ def create_html_file_p(entry, manager, path, db)
251
+ FileUtils.mkdir_p(path.dirname) unless path.dirname.directory?
252
+ html = manager.entry_screen(entry, {:database => db}).body
253
+ path.open('w') do |f|
254
+ f.write(html)
255
+ end
256
+ end
257
+
258
+ def create_file(path, str, options = {})
259
+ verbose = options[:verbose]
260
+ $stderr.print("creating #{path} ...") if verbose
261
+ path.open('w') do |f|
262
+ f.write(str)
263
+ end
264
+ $stderr.puts(" done.") if verbose
265
+ end
266
+
267
+ def encodename_package(str)
268
+ if $fs_casesensitive
269
+ NameUtils.encodename_url(str)
270
+ else
271
+ NameUtils.encodename_fs(str)
272
+ end
273
+ end
274
+ end
275
+ end
276
+ end