voloko-sdoc 0.0.5 → 0.1.1

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 (29) hide show
  1. data/README +1 -1
  2. data/bin/sdoc +0 -1
  3. data/bin/sdoc-merge +12 -0
  4. data/lib/sdoc.rb +15 -7
  5. data/lib/sdoc/generator/shtml.rb +671 -0
  6. data/lib/sdoc/generator/template/shtml/_context.rhtml +163 -0
  7. data/lib/sdoc/generator/template/shtml/class.rhtml +46 -0
  8. data/lib/sdoc/generator/template/shtml/file.rhtml +37 -0
  9. data/lib/sdoc/generator/template/shtml/index.rhtml +14 -0
  10. data/lib/sdoc/generator/template/shtml/resources/css/main.css +191 -0
  11. data/lib/sdoc/{generators/template/shtml/resources/css/master-frameset.css → generator/template/shtml/resources/css/panel.css} +83 -2
  12. data/lib/sdoc/{generators → generator}/template/shtml/resources/css/reset.css +0 -0
  13. data/lib/sdoc/{generators → generator}/template/shtml/resources/i/arrows.png +0 -0
  14. data/lib/sdoc/{generators → generator}/template/shtml/resources/i/results_bg.png +0 -0
  15. data/lib/sdoc/{generators → generator}/template/shtml/resources/i/tree_bg.png +0 -0
  16. data/lib/sdoc/{generators → generator}/template/shtml/resources/js/jquery-1.3.2.min.js +0 -0
  17. data/lib/sdoc/generator/template/shtml/resources/js/main.js +34 -0
  18. data/lib/sdoc/generator/template/shtml/resources/js/searchdoc.js +600 -0
  19. data/lib/sdoc/{generators/template/shtml/resources/panel.html → generator/template/shtml/resources/panel/index.html} +6 -6
  20. data/lib/sdoc/github.rb +64 -0
  21. data/lib/sdoc/merge.rb +166 -0
  22. metadata +117 -19
  23. data/lib/sdoc/code_objects.rb +0 -17
  24. data/lib/sdoc/generators/shtml_generator.rb +0 -354
  25. data/lib/sdoc/generators/template/shtml/resources/js/searchdoc.js +0 -595
  26. data/lib/sdoc/generators/template/shtml/shtml.rb +0 -615
  27. data/lib/sdoc/options.rb +0 -61
  28. data/test/options_test.rb +0 -33
  29. data/test/sdoc_test.rb +0 -7
@@ -5,12 +5,12 @@
5
5
  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
6
6
  <head>
7
7
  <title>layout</title>
8
- <link rel="stylesheet" href="css/reset.css" type="text/css" media="screen" title="no title" charset="utf-8" />
9
- <link rel="stylesheet" href="css/master-frameset.css" type="text/css" media="screen" title="no title" charset="utf-8" />
10
- <script src="index.js" type="text/javascript" charset="utf-8"></script>
8
+ <link rel="stylesheet" href="../css/reset.css" type="text/css" media="screen" charset="utf-8" />
9
+ <link rel="stylesheet" href="../css/panel.css" type="text/css" media="screen" charset="utf-8" />
10
+ <script src="search_index.js" type="text/javascript" charset="utf-8"></script>
11
11
  <script src="tree.js" type="text/javascript" charset="utf-8"></script>
12
- <script src="js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
13
- <script src="js/searchdoc.js" type="text/javascript" charset="utf-8"></script>
12
+ <script src="../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
13
+ <script src="../js/searchdoc.js" type="text/javascript" charset="utf-8"></script>
14
14
  <script type="text/javascript" charset="utf-8">
15
15
  function placeholder() {
16
16
  if (jQuery.browser.safari) return;
@@ -32,7 +32,7 @@
32
32
  }
33
33
  $(function() {
34
34
  placeholder();
35
- new Searchdoc.Panel($('#panel'), data, tree, top.frames[1]);
35
+ new Searchdoc.Panel($('#panel'), search_data, tree, top.frames[1]);
36
36
  $('#search').focus();
37
37
  })
38
38
  </script>
@@ -0,0 +1,64 @@
1
+ module SDoc::GitHub
2
+ def github_url(path)
3
+ unless @github_url_cache.has_key? path
4
+ @github_url_cache[path] = false
5
+ file = RDoc::TopLevel.find_file_named(path)
6
+ if file
7
+ base_url = repository_url(path)
8
+ if base_url
9
+ sha1 = commit_sha1(path)
10
+ if sha1
11
+ relative_url = path_relative_to_repository(path)
12
+ @github_url_cache[path] = "#{base_url}#{sha1}#{relative_url}"
13
+ end
14
+ end
15
+ end
16
+ end
17
+ @github_url_cache[path]
18
+ end
19
+
20
+ protected
21
+
22
+ def commit_sha1(path)
23
+ name = File.basename(path)
24
+ s = in_dir(File.join(basedir, File.dirname(path))) do
25
+ `git log -1 --pretty=format:"commit %H" #{name}`
26
+ end
27
+ m = s.match(/commit\s+(\S+)/)
28
+ m ? m[1] : false
29
+ end
30
+
31
+ def repository_url(path)
32
+ s = in_dir(File.join(basedir, File.dirname(path))) do
33
+ `git config --get remote.origin.url`
34
+ end
35
+ m = s.match(%r{github.com[/:](.*)\.git$})
36
+ m ? "http://github.com/#{m[1]}/blob/" : false
37
+ end
38
+
39
+ def path_relative_to_repository(path)
40
+ absolute_path = File.join(basedir, path)
41
+ root = path_to_git_dir(File.dirname(absolute_path))
42
+ absolute_path[root.size..absolute_path.size]
43
+ end
44
+
45
+ def path_to_git_dir(path)
46
+ while !path.empty? && path != '.'
47
+ if (File.exists? File.join(path, '.git'))
48
+ return path
49
+ end
50
+ path = File.dirname(path)
51
+ end
52
+ ''
53
+ end
54
+
55
+ def in_dir(dir)
56
+ pwd = Dir.pwd
57
+ Dir.chdir dir
58
+ begin
59
+ return yield
60
+ ensure
61
+ Dir.chdir pwd
62
+ end
63
+ end
64
+ end
data/lib/sdoc/merge.rb ADDED
@@ -0,0 +1,166 @@
1
+ require 'optparse'
2
+ require 'pathname'
3
+ require 'fileutils'
4
+ require 'json'
5
+
6
+ class SDoc::Merge
7
+
8
+ FLAG_FILE = "created.rid"
9
+
10
+ def initialize()
11
+ @names = []
12
+ @op_dir = 'doc'
13
+ @directories = []
14
+ end
15
+
16
+ def merge(options)
17
+ parse_options options
18
+
19
+ check_directories
20
+ setup_output_dir
21
+ setup_names
22
+ copy_files
23
+ merge_tree
24
+ merge_search_index
25
+ end
26
+
27
+ def parse_options(options)
28
+ opts = OptionParser.new do |opt|
29
+ opt.banner = "Usage: sdoc-merge [options] directories"
30
+
31
+ opt.on("-n", "--names [NAMES]", "Names of merged repositories. Comma separated") do |v|
32
+ @names = v.split(',').map{|name| name.strip }
33
+ end
34
+
35
+ opt.on("-o", "--op [DIRECTORY]", "Set the output directory") do |v|
36
+ @op_dir = v
37
+ end
38
+ end
39
+ opts.parse! options
40
+ @directories = options.dup
41
+ end
42
+
43
+ def merge_tree
44
+ tree = []
45
+ @directories.each_with_index do |dir, i|
46
+ name = @names[i]
47
+ filename = File.join dir, RDoc::Generator::SHtml::TREE_FILE
48
+ data = open(filename).read.sub(/var tree =\s*/, '')
49
+ subtree = JSON.parse data
50
+ item = [
51
+ name,
52
+ '',
53
+ '',
54
+ subtree
55
+ ]
56
+ tree << item
57
+ end
58
+
59
+ dst = File.join @op_dir, RDoc::Generator::SHtml::TREE_FILE
60
+ FileUtils.mkdir_p File.dirname(dst)
61
+ File.open(dst, "w") do |f|
62
+ f.write('var tree = '); f.write(tree.to_json)
63
+ end
64
+ end
65
+
66
+ def merge_search_index
67
+ items = []
68
+ @directories.each_with_index do |dir, i|
69
+ name = @names[i]
70
+ filename = File.join dir, RDoc::Generator::SHtml::SEARCH_INDEX_FILE
71
+ data = open(filename).read.sub(/var search_data =\s*/, '')
72
+ subindex = JSON.parse data
73
+
74
+ searchIndex = subindex["index"]["searchIndex"]
75
+ longSearchIndex = subindex["index"]["longSearchIndex"]
76
+ subindex["index"]["info"].each_with_index do |info, j|
77
+ info[2] = name + '/' + info[2]
78
+ info[6] = i
79
+ items << {
80
+ :info => info,
81
+ :searchIndex => searchIndex[j],
82
+ :longSearchIndex => longSearchIndex[j]
83
+ }
84
+ end
85
+ end
86
+ items.sort! do |a, b|
87
+ a[:info][5] == b[:info][5] ? a[:info][0] <=> b[:info][0] : a[:info][5] <=> b[:info][5]
88
+ end
89
+
90
+ index = {
91
+ :searchIndex => items.map{|item| item[:searchIndex]},
92
+ :longSearchIndex => items.map{|item| item[:longSearchIndex]},
93
+ :info => items.map{|item| item[:info]}
94
+ }
95
+ search_data = {
96
+ :index => index,
97
+ :badges => @names
98
+ }
99
+
100
+ dst = File.join @op_dir, RDoc::Generator::SHtml::SEARCH_INDEX_FILE
101
+ FileUtils.mkdir_p File.dirname(dst)
102
+ File.open(dst, "w") do |f|
103
+ f.write('var search_data = '); f.write(search_data.to_json)
104
+ end
105
+ end
106
+
107
+ def setup_names
108
+ unless @names.size
109
+ @directories.each do |dir|
110
+ name = File.basename dir
111
+ name = File.basename File.dirname(dir) if name == 'doc'
112
+ @names << name
113
+ end
114
+ end
115
+ end
116
+
117
+ def copy_files
118
+ @directories.each_with_index do |dir, i|
119
+ name = @names[i]
120
+ index_dir = File.dirname(RDoc::Generator::SHtml::TREE_FILE)
121
+ FileUtils.mkdir_p(File.join @op_dir, name)
122
+
123
+ Dir.new(dir).each do |item|
124
+ if File.directory?(File.join(dir, item)) && item != '.' && item != '..' && item != index_dir
125
+ FileUtils.cp_r File.join(dir, item), File.join(@op_dir, name, item)
126
+ end
127
+ end
128
+ end
129
+
130
+ dir = @directories.first
131
+ Dir.new(dir).each do |item|
132
+ if item != '.' && item != '..' && item != RDoc::Generator::SHtml::FILE_DIR && item != RDoc::Generator::SHtml::CLASS_DIR
133
+ FileUtils.cp_r File.join(dir, item), @op_dir
134
+ end
135
+ end
136
+ end
137
+
138
+ def setup_output_dir
139
+ if File.exists? @op_dir
140
+ error "#{@op_dir} allready exists"
141
+ end
142
+ FileUtils.mkdir_p @op_dir
143
+ end
144
+
145
+ def check_directories
146
+ @directories.each do |dir|
147
+ unless File.exists?(File.join dir, FLAG_FILE) &&
148
+ File.exists?(File.join dir, RDoc::Generator::SHtml::TREE_FILE) &&
149
+ File.exists?(File.join dir, RDoc::Generator::SHtml::SEARCH_INDEX_FILE)
150
+ error "#{dir} does not seem to be an sdoc directory"
151
+ end
152
+ end
153
+ end
154
+
155
+ def update_output_dir(op_dir, time)
156
+ File.open(File.join @op_dir, FLAG_FILE, "w") { |f| f.puts time.rfc2822 }
157
+ end
158
+
159
+ ##
160
+ # Report an error message and exit
161
+
162
+ def error(msg)
163
+ raise RDoc::Error, msg
164
+ end
165
+
166
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: voloko-sdoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Kolesnikov
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-21 00:00:00 -07:00
12
+ date: 2009-03-26 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -26,28 +26,127 @@ description:
26
26
  email: voloko@gmail.com
27
27
  executables:
28
28
  - sdoc
29
+ - sdoc-merge
29
30
  extensions: []
30
31
 
31
32
  extra_rdoc_files:
32
33
  - README
33
34
  files:
34
- - lib/sdoc/code_objects.rb
35
- - lib/sdoc/generators/shtml_generator.rb
36
- - lib/sdoc/generators/template/shtml/resources/css/master-frameset.css
37
- - lib/sdoc/generators/template/shtml/resources/css/reset.css
38
- - lib/sdoc/generators/template/shtml/resources/i/arrows.png
39
- - lib/sdoc/generators/template/shtml/resources/i/results_bg.png
40
- - lib/sdoc/generators/template/shtml/resources/i/tree_bg.png
41
- - lib/sdoc/generators/template/shtml/resources/js/jquery-1.3.2.min.js
42
- - lib/sdoc/generators/template/shtml/resources/js/searchdoc.js
43
- - lib/sdoc/generators/template/shtml/resources/panel.html
44
- - lib/sdoc/generators/template/shtml/shtml.rb
45
- - lib/sdoc/options.rb
35
+ - lib/sdoc/generator/shtml.rb
36
+ - lib/sdoc/generator/template/shtml/_context.rhtml
37
+ - lib/sdoc/generator/template/shtml/class.rhtml
38
+ - lib/sdoc/generator/template/shtml/file.rhtml
39
+ - lib/sdoc/generator/template/shtml/index.rhtml
40
+ - lib/sdoc/generator/template/shtml/resources/css/main.css
41
+ - lib/sdoc/generator/template/shtml/resources/css/panel.css
42
+ - lib/sdoc/generator/template/shtml/resources/css/reset.css
43
+ - lib/sdoc/generator/template/shtml/resources/i/arrows.png
44
+ - lib/sdoc/generator/template/shtml/resources/i/results_bg.png
45
+ - lib/sdoc/generator/template/shtml/resources/i/tree_bg.png
46
+ - lib/sdoc/generator/template/shtml/resources/js/jquery-1.3.2.min.js
47
+ - lib/sdoc/generator/template/shtml/resources/js/main.js
48
+ - lib/sdoc/generator/template/shtml/resources/js/searchdoc.js
49
+ - lib/sdoc/generator/template/shtml/resources/panel/index.html
50
+ - lib/sdoc/github.rb
51
+ - lib/sdoc/merge.rb
46
52
  - lib/sdoc.rb
47
- - bin/sdoc
53
+ - rdoc/bin/rdoc
54
+ - rdoc/bin/ri
55
+ - rdoc/History.txt
56
+ - rdoc/lib/rdoc/alias.rb
57
+ - rdoc/lib/rdoc/anon_class.rb
58
+ - rdoc/lib/rdoc/any_method.rb
59
+ - rdoc/lib/rdoc/attr.rb
60
+ - rdoc/lib/rdoc/cache.rb
61
+ - rdoc/lib/rdoc/class_module.rb
62
+ - rdoc/lib/rdoc/code_object.rb
63
+ - rdoc/lib/rdoc/code_objects.rb
64
+ - rdoc/lib/rdoc/constant.rb
65
+ - rdoc/lib/rdoc/context.rb
66
+ - rdoc/lib/rdoc/diagram.rb
67
+ - rdoc/lib/rdoc/dot.rb
68
+ - rdoc/lib/rdoc/generator/darkfish.rb
69
+ - rdoc/lib/rdoc/generator/markup.rb
70
+ - rdoc/lib/rdoc/generator/ri.rb
71
+ - rdoc/lib/rdoc/generator/template/darkfish/classpage.rhtml
72
+ - rdoc/lib/rdoc/generator/template/darkfish/filepage.rhtml
73
+ - rdoc/lib/rdoc/generator/template/darkfish/images/brick.png
74
+ - rdoc/lib/rdoc/generator/template/darkfish/images/brick_link.png
75
+ - rdoc/lib/rdoc/generator/template/darkfish/images/bug.png
76
+ - rdoc/lib/rdoc/generator/template/darkfish/images/bullet_black.png
77
+ - rdoc/lib/rdoc/generator/template/darkfish/images/bullet_toggle_minus.png
78
+ - rdoc/lib/rdoc/generator/template/darkfish/images/bullet_toggle_plus.png
79
+ - rdoc/lib/rdoc/generator/template/darkfish/images/date.png
80
+ - rdoc/lib/rdoc/generator/template/darkfish/images/find.png
81
+ - rdoc/lib/rdoc/generator/template/darkfish/images/loadingAnimation.gif
82
+ - rdoc/lib/rdoc/generator/template/darkfish/images/macFFBgHack.png
83
+ - rdoc/lib/rdoc/generator/template/darkfish/images/package.png
84
+ - rdoc/lib/rdoc/generator/template/darkfish/images/page_green.png
85
+ - rdoc/lib/rdoc/generator/template/darkfish/images/page_white_text.png
86
+ - rdoc/lib/rdoc/generator/template/darkfish/images/page_white_width.png
87
+ - rdoc/lib/rdoc/generator/template/darkfish/images/plugin.png
88
+ - rdoc/lib/rdoc/generator/template/darkfish/images/ruby.png
89
+ - rdoc/lib/rdoc/generator/template/darkfish/images/tag_green.png
90
+ - rdoc/lib/rdoc/generator/template/darkfish/images/wrench.png
91
+ - rdoc/lib/rdoc/generator/template/darkfish/images/wrench_orange.png
92
+ - rdoc/lib/rdoc/generator/template/darkfish/images/zoom.png
93
+ - rdoc/lib/rdoc/generator/template/darkfish/index.rhtml
94
+ - rdoc/lib/rdoc/generator/template/darkfish/js/darkfish.js
95
+ - rdoc/lib/rdoc/generator/template/darkfish/js/jquery.js
96
+ - rdoc/lib/rdoc/generator/template/darkfish/js/quicksearch.js
97
+ - rdoc/lib/rdoc/generator/template/darkfish/js/thickbox-compressed.js
98
+ - rdoc/lib/rdoc/generator/template/darkfish/rdoc.css
99
+ - rdoc/lib/rdoc/generator.rb
100
+ - rdoc/lib/rdoc/ghost_method.rb
101
+ - rdoc/lib/rdoc/include.rb
102
+ - rdoc/lib/rdoc/known_classes.rb
103
+ - rdoc/lib/rdoc/markup/attribute_manager.rb
104
+ - rdoc/lib/rdoc/markup/formatter.rb
105
+ - rdoc/lib/rdoc/markup/fragments.rb
106
+ - rdoc/lib/rdoc/markup/inline.rb
107
+ - rdoc/lib/rdoc/markup/lines.rb
108
+ - rdoc/lib/rdoc/markup/preprocess.rb
109
+ - rdoc/lib/rdoc/markup/to_flow.rb
110
+ - rdoc/lib/rdoc/markup/to_html.rb
111
+ - rdoc/lib/rdoc/markup/to_html_crossref.rb
112
+ - rdoc/lib/rdoc/markup/to_latex.rb
113
+ - rdoc/lib/rdoc/markup/to_test.rb
114
+ - rdoc/lib/rdoc/markup/to_texinfo.rb
115
+ - rdoc/lib/rdoc/markup.rb
116
+ - rdoc/lib/rdoc/meta_method.rb
117
+ - rdoc/lib/rdoc/normal_class.rb
118
+ - rdoc/lib/rdoc/normal_module.rb
119
+ - rdoc/lib/rdoc/options.rb
120
+ - rdoc/lib/rdoc/parser/c.rb
121
+ - rdoc/lib/rdoc/parser/perl.rb
122
+ - rdoc/lib/rdoc/parser/ruby.rb
123
+ - rdoc/lib/rdoc/parser/simple.rb
124
+ - rdoc/lib/rdoc/parser.rb
125
+ - rdoc/lib/rdoc/rdoc.rb
126
+ - rdoc/lib/rdoc/require.rb
127
+ - rdoc/lib/rdoc/ri/cache.rb
128
+ - rdoc/lib/rdoc/ri/descriptions.rb
129
+ - rdoc/lib/rdoc/ri/display.rb
130
+ - rdoc/lib/rdoc/ri/driver.rb
131
+ - rdoc/lib/rdoc/ri/formatter.rb
132
+ - rdoc/lib/rdoc/ri/paths.rb
133
+ - rdoc/lib/rdoc/ri/reader.rb
134
+ - rdoc/lib/rdoc/ri/util.rb
135
+ - rdoc/lib/rdoc/ri/writer.rb
136
+ - rdoc/lib/rdoc/ri.rb
137
+ - rdoc/lib/rdoc/single_class.rb
138
+ - rdoc/lib/rdoc/stats.rb
139
+ - rdoc/lib/rdoc/task.rb
140
+ - rdoc/lib/rdoc/tokenstream.rb
141
+ - rdoc/lib/rdoc/top_level.rb
142
+ - rdoc/lib/rdoc.rb
143
+ - rdoc/Manifest.txt
144
+ - rdoc/Rakefile
145
+ - rdoc/README.txt
146
+ - rdoc/RI.txt
48
147
  - README
49
148
  has_rdoc: true
50
- homepage: http://voloko.ru/sdoc/rails
149
+ homepage: http://railsapi.com
51
150
  post_install_message:
52
151
  rdoc_options: []
53
152
 
@@ -72,6 +171,5 @@ rubygems_version: 1.2.0
72
171
  signing_key:
73
172
  specification_version: 2
74
173
  summary: RDoc extensions for searchable html generations
75
- test_files:
76
- - test/options_test.rb
77
- - test/sdoc_test.rb
174
+ test_files: []
175
+
@@ -1,17 +0,0 @@
1
- require "rdoc/code_objects"
2
-
3
- module RDoc
4
- class TopLevel
5
- attr_accessor :file_expanded_path
6
-
7
- def initialize(file_name)
8
- super()
9
- @name = "TopLevel"
10
- @file_relative_name = file_name
11
- @file_absolute_name = file_name
12
- @file_expanded_path = File.expand_path(file_name)
13
- @file_stat = File.stat(file_name)
14
- @diagram = nil
15
- end
16
- end
17
- end
@@ -1,354 +0,0 @@
1
- require 'rubygems'
2
- require 'json'
3
- require 'fileutils'
4
- require 'rdoc/generators/html_generator'
5
-
6
-
7
- module Generators
8
- # SOURCE_DIR = 'source'
9
-
10
- module MarkUp
11
- def snippetize(str)
12
- if str =~ /^(?>\s*)[^\#]/
13
- content = str
14
- else
15
- content = str.gsub(/^\s*(#+)\s*/, '')
16
- end
17
- content.sub(/^(.{0,100}).*$/m, "\\1").gsub(/\r?\n/m, ' ')
18
- end
19
- end
20
-
21
- module CollectMethods
22
- def collect_methods
23
- list = @context.method_list
24
- unless @options.show_all
25
- list = list.find_all {|m| m.visibility == :public || m.visibility == :protected || m.force_documentation }
26
- end
27
- @methods = list.collect {|m| SHtmlMethod.new(m, self, @options) }
28
- end
29
- end
30
-
31
- #####################################################################
32
-
33
- class SHtmlClass < HtmlClass
34
- include CollectMethods
35
-
36
- attr_accessor :children
37
-
38
- def initialize(context, html_file, prefix, options)
39
- super(context, html_file, prefix, options)
40
- @children = []
41
- end
42
-
43
- def params
44
- @context.superclass ? " < #{@context.superclass}" : ''
45
- end
46
-
47
- def snippet
48
- @snippet ||= snippetize(@context.comment)
49
- end
50
-
51
- def namespace
52
- @context.parent ? @context.parent.name : ''
53
- end
54
-
55
- def title
56
- @context.name
57
- end
58
-
59
- def content?
60
- document_self || children.any?{ |c| c.content? }
61
- end
62
-
63
- def path_if_available
64
- document_self ? path : ''
65
- end
66
-
67
- def github_url
68
- @html_file.github_url
69
- end
70
- end
71
-
72
- #####################################################################
73
-
74
- class SHtmlFile < HtmlFile
75
- include CollectMethods
76
-
77
- attr_accessor :github_url
78
-
79
- def initialize(context, options, file_dir)
80
- super(context, options, file_dir)
81
- @github_url = SHTMLGenerator.github_url(@context.file_relative_name, @options) if (@options.github_url)
82
- end
83
-
84
- def params
85
- ''
86
- end
87
-
88
- def snippet
89
- @snippet ||= snippetize(@context.comment)
90
- end
91
-
92
- def namespace
93
- @context.file_absolute_name
94
- end
95
-
96
- def title
97
- File.basename(namespace)
98
- end
99
-
100
- def value_hash
101
- super
102
- @values["github_url"] = github_url if (@options.github_url)
103
- @values
104
- end
105
-
106
- def absolute_path
107
- @context.file_expanded_path
108
- end
109
-
110
- end
111
-
112
- #####################################################################
113
-
114
- class SHtmlMethod < HtmlMethod
115
- def snippet
116
- @snippet ||= snippetize(@context.comment)
117
- end
118
-
119
- def namespace
120
- @html_class.name
121
- end
122
-
123
- def title
124
- name
125
- end
126
-
127
- def github_url
128
- if @source_code =~ /File\s(\S+), line (\d+)/
129
- file = $1
130
- line = $2.to_i
131
- end
132
- url = SHTMLGenerator.github_url(file, @options)
133
- unless line.nil? || url.nil?
134
- url + "#L#{line}"
135
- else
136
- ''
137
- end
138
- end
139
- end
140
-
141
- #####################################################################
142
-
143
- class SHTMLGenerator < HTMLGenerator
144
-
145
- @@github_url_cache = {}
146
-
147
- def self.github_url(file_relative_name, options)
148
- unless @@github_url_cache.has_key? file_relative_name
149
- file = AllReferences[file_relative_name]
150
- if file.nil?
151
- return nil
152
- end
153
- path = file.absolute_path
154
- name = File.basename(file_relative_name)
155
-
156
- pwd = Dir.pwd
157
- Dir.chdir(File.dirname(path))
158
- s = `git log -1 --pretty=format:"commit %H" #{name}`
159
- Dir.chdir(pwd)
160
-
161
- m = s.match(/commit\s+(\S+)/)
162
- if m
163
- repository_path = path_relative_to_repository(path)
164
- @@github_url_cache[file_relative_name] = "#{options.github_url}/blob/#{m[1]}#{repository_path}"
165
- end
166
- end
167
- @@github_url_cache[file_relative_name]
168
- end
169
-
170
- def self.path_relative_to_repository(path)
171
- root = find_git_dir(path)
172
- path[root.size..path.size]
173
- end
174
-
175
- def self.find_git_dir(path)
176
- while !path.empty? && path != '.'
177
- if (File.exists? File.join(path, '.git'))
178
- return path
179
- end
180
- path = File.dirname(path)
181
- end
182
- ''
183
- end
184
-
185
-
186
- def SHTMLGenerator.for(options)
187
- AllReferences::reset
188
- HtmlMethod::reset
189
-
190
- SHTMLGenerator.new(options)
191
- end
192
-
193
- def load_html_template
194
- template = @options.template
195
- unless template =~ %r{/|\\}
196
- template = File.join("sdoc/generators/template",
197
- @options.generator.key, template)
198
- end
199
- require template
200
- extend RDoc::Page
201
- rescue LoadError
202
- $stderr.puts "Could not find HTML template '#{template}'"
203
- exit 99
204
- end
205
-
206
- def generate_html
207
- # the individual descriptions for files and classes
208
- gen_into(@files)
209
- gen_into(@classes)
210
- gen_search_index
211
- gen_tree_index
212
- gen_main_index
213
- copy_resources
214
-
215
- # this method is defined in the template file
216
- write_extra_pages if defined? write_extra_pages
217
- end
218
-
219
- def build_indices
220
- @toplevels.each do |toplevel|
221
- @files << SHtmlFile.new(toplevel, @options, FILE_DIR)
222
- end
223
- @topclasses = []
224
- RDoc::TopLevel.all_classes_and_modules.each do |cls|
225
- @topclasses << build_class_list(cls, @files[0], CLASS_DIR)
226
- end
227
- end
228
-
229
- def build_class_list(from, html_file, class_dir)
230
- klass = SHtmlClass.new(from, html_file, class_dir, @options)
231
- @classes << klass
232
- from.each_classmodule do |mod|
233
- klass.children << build_class_list(mod, html_file, class_dir)
234
- end
235
- klass
236
- end
237
-
238
- def copy_resources
239
- FileUtils.cp_r RDoc::Page::RESOURCES_PATH, '.'
240
- end
241
-
242
- def search_string(string)
243
- string.downcase.gsub(/\s/,'')
244
- end
245
-
246
- def gen_tree_index
247
- tree = gen_tree_level @topclasses
248
- File.open('tree.yaml', 'w') { |f| f.write(tree.to_yaml) }
249
- File.open('tree.js', "w") do |f|
250
- f.write('var tree = '); f.write(tree.to_json)
251
- end
252
- end
253
-
254
- def gen_tree_level(classes)
255
- tree = []
256
- classes.select{|c| c.content? }.sort.each do |item|
257
- item = [item.title, item.namespace, item.path_if_available, item.params, item.snippet, gen_tree_level(item.children)]
258
- tree << item
259
- end
260
- tree
261
- end
262
-
263
- def gen_search_index
264
- entries = HtmlMethod.all_methods.sort
265
- entries += @classes.sort
266
- entries += @files.sort
267
- entries = entries.select { |f| f.document_self }
268
-
269
- result = {
270
- :searchIndex => [],
271
- :longSearchIndex => [],
272
- :info => []
273
- }
274
-
275
- entries.each_with_index do |item, index|
276
- result[:searchIndex].push( search_string(item.title) )
277
- result[:longSearchIndex].push( search_string(item.namespace) )
278
- result[:info].push([item.title, item.namespace, item.path, item.params, item.snippet])
279
- end
280
-
281
- File.open('index.js', "w") do |f|
282
- f.write('var data = '); f.write(result.to_json)
283
- end
284
- File.open('index.yaml', 'w') { |f| f.write(result.to_yaml) }
285
- end
286
-
287
- end
288
-
289
- class ContextUser
290
- def build_method_detail_list(section)
291
- outer = []
292
-
293
- methods = @methods.sort
294
- for singleton in [true, false]
295
- for vis in [ :public, :protected, :private ]
296
- res = []
297
- methods.each do |m|
298
- if m.section == section and
299
- m.document_self and
300
- m.visibility == vis and
301
- m.singleton == singleton
302
- row = {}
303
- if m.call_seq
304
- row["callseq"] = m.call_seq.gsub(/->/, '&rarr;')
305
- else
306
- row["name"] = CGI.escapeHTML(m.name)
307
- row["params"] = m.params
308
- end
309
- desc = m.description.strip
310
- row["m_desc"] = desc unless desc.empty?
311
- row["aref"] = m.aref
312
- row["visibility"] = m.visibility.to_s
313
-
314
- alias_names = []
315
- m.aliases.each do |other|
316
- if other.viewer # won't be if the alias is private
317
- alias_names << {
318
- 'name' => other.name,
319
- 'aref' => other.viewer.as_href(path)
320
- }
321
- end
322
- end
323
- unless alias_names.empty?
324
- row["aka"] = alias_names
325
- end
326
-
327
- if @options.inline_source
328
- code = m.source_code
329
- row["sourcecode"] = code if code
330
- row["github_url"] = m.github_url if @options.github_url
331
- else
332
- code = m.src_url
333
- if code
334
- row["codeurl"] = code
335
- row["imgurl"] = m.img_url
336
- row["github_url"] = m.github_url if @options.github_url
337
- end
338
- end
339
- res << row
340
- end
341
- end
342
- if res.size > 0
343
- outer << {
344
- "type" => vis.to_s.capitalize,
345
- "category" => singleton ? "Class" : "Instance",
346
- "methods" => res
347
- }
348
- end
349
- end
350
- end
351
- outer
352
- end
353
- end
354
- end