voloko-sdoc 0.1.10 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :minor: 1
3
- :patch: 10
2
+ :minor: 2
3
+ :patch: 0
4
4
  :major: 0
data/lib/sdoc.rb CHANGED
@@ -10,12 +10,14 @@ end
10
10
  require "sdoc/generator/shtml"
11
11
  require "sdoc/c_parser_fix"
12
12
 
13
- class RDoc::Options
14
- alias_method :rdoc_initialize, :initialize
13
+ unless defined? SDOC_FIXED_RDOC_OPTIONS
14
+ SDOC_FIXED_RDOC_OPTIONS = 1
15
+ class RDoc::Options
16
+ alias_method :rdoc_initialize, :initialize
15
17
 
16
- def initialize
17
- rdoc_initialize
18
- @generator = RDoc::Generator::SHtml
18
+ def initialize
19
+ rdoc_initialize
20
+ @generator = RDoc::Generator::SHtml
21
+ end
19
22
  end
20
23
  end
21
-
@@ -17,6 +17,7 @@ require 'rdoc/generator'
17
17
  require 'rdoc/generator/markup'
18
18
 
19
19
  require 'sdoc/github'
20
+ require 'sdoc/templatable'
20
21
 
21
22
  class RDoc::ClassModule
22
23
  def with_documentation?
@@ -28,6 +29,7 @@ class RDoc::Generator::SHtml
28
29
  RDoc::RDoc.add_generator( self )
29
30
  include ERB::Util
30
31
  include SDoc::GitHub
32
+ include SDoc::Templatable
31
33
 
32
34
  GENERATOR_DIRS = [File.join('sdoc', 'generator'), File.join('rdoc', 'generator')]
33
35
 
@@ -50,6 +52,16 @@ class RDoc::Generator::SHtml
50
52
  self.new(options)
51
53
  end
52
54
 
55
+ def self.template_dir template
56
+ $LOAD_PATH.map do |path|
57
+ GENERATOR_DIRS.map do |dir|
58
+ File.join path, dir, 'template', template
59
+ end
60
+ end.flatten.find do |dir|
61
+ File.directory? dir
62
+ end
63
+ end
64
+
53
65
  def initialize(options)
54
66
  @options = options
55
67
  @options.diagram = false
@@ -57,18 +69,12 @@ class RDoc::Generator::SHtml
57
69
 
58
70
  template = @options.template || 'shtml'
59
71
 
60
- template_dir = $LOAD_PATH.map do |path|
61
- GENERATOR_DIRS.map do |dir|
62
- File.join path, dir, 'template', template
63
- end
64
- end.flatten.find do |dir|
65
- File.directory? dir
66
- end
72
+ templ_dir = self.class.template_dir template
67
73
 
68
74
  raise RDoc::Error, "could not find template #{template.inspect}" unless
69
- template_dir
75
+ templ_dir
70
76
 
71
- @template_dir = Pathname.new File.expand_path(template_dir)
77
+ @template_dir = Pathname.new File.expand_path(templ_dir)
72
78
  @basedir = Pathname.pwd.expand_path
73
79
  end
74
80
 
@@ -108,7 +114,7 @@ class RDoc::Generator::SHtml
108
114
  topclasses = @classes.select {|klass| !(RDoc::ClassModule === klass.parent) }
109
115
  tree = generate_class_tree_level topclasses
110
116
  debug_msg " writing class tree to %s" % TREE_FILE
111
- File.open(TREE_FILE, "w") do |f|
117
+ File.open(TREE_FILE, "w", 0644) do |f|
112
118
  f.write('var tree = '); f.write(tree.to_json)
113
119
  end unless $dryrun
114
120
  end
@@ -147,7 +153,7 @@ class RDoc::Generator::SHtml
147
153
  data = {
148
154
  :index => index
149
155
  }
150
- File.open(SEARCH_INDEX_FILE, "w") do |f|
156
+ File.open(SEARCH_INDEX_FILE, "w", 0644) do |f|
151
157
  f.write('var search_data = '); f.write(data.to_json)
152
158
  end unless $dryrun
153
159
  end
@@ -206,7 +212,7 @@ class RDoc::Generator::SHtml
206
212
  end
207
213
 
208
214
  list.each do |method|
209
- index[:searchIndex].push( search_string(method.name) )
215
+ index[:searchIndex].push( search_string(method.name) + '()' )
210
216
  index[:longSearchIndex].push( search_string(method.parent.name) )
211
217
  index[:info].push([
212
218
  method.name,
@@ -254,7 +260,11 @@ class RDoc::Generator::SHtml
254
260
  debug_msg "Generating index file in #@outputdir"
255
261
  templatefile = @template_dir + 'index.rhtml'
256
262
  outfile = @outputdir + 'index.html'
257
- index_path = @files.first.path
263
+ if @options.main_page && index_path = @files.find { |f| f.full_name == @options.main_page }
264
+ index_path = index_path.path
265
+ else
266
+ index_path = @files.first.path
267
+ end
258
268
 
259
269
  self.render_template( templatefile, binding(), outfile )
260
270
  end
@@ -293,48 +303,6 @@ class RDoc::Generator::SHtml
293
303
  def copy_resources
294
304
  resoureces_path = @template_dir + RESOURCES_DIR
295
305
  debug_msg "Copying #{resoureces_path}/** to #{@outputdir}/**"
296
- FileUtils.cp_r resoureces_path.to_s, @outputdir.to_s unless $dryrun
306
+ FileUtils.cp_r resoureces_path.to_s, @outputdir.to_s, :preserve => true unless $dryrun
297
307
  end
298
-
299
- ### Load and render the erb template in the given +templatefile+ within the
300
- ### specified +context+ (a Binding object) and return output
301
- ### Both +templatefile+ and +outfile+ should be Pathname-like objects.
302
- def eval_template(templatefile, context)
303
- template_src = templatefile.read
304
- template = ERB.new( template_src, nil, '<>' )
305
- template.filename = templatefile.to_s
306
-
307
- begin
308
- template.result( context )
309
- rescue NoMethodError => err
310
- raise RDoc::Error, "Error while evaluating %s: %s (at %p)" % [
311
- templatefile.to_s,
312
- err.message,
313
- eval( "_erbout[-50,50]", context )
314
- ], err.backtrace
315
- end
316
- end
317
-
318
- ### Load and render the erb template with the given +template_name+ within
319
- ### current context. Adds all +local_assigns+ to context
320
- def include_template(template_name, local_assigns = {})
321
- source = local_assigns.keys.map { |key| "#{key} = local_assigns[:#{key}];" }.join
322
- eval("#{source};templatefile = @template_dir + template_name;eval_template(templatefile, binding)")
323
- end
324
-
325
- ### Load and render the erb template in the given +templatefile+ within the
326
- ### specified +context+ (a Binding object) and write it out to +outfile+.
327
- ### Both +templatefile+ and +outfile+ should be Pathname-like objects.
328
- def render_template( templatefile, context, outfile )
329
- output = eval_template(templatefile, context)
330
- unless $dryrun
331
- outfile.dirname.mkpath
332
- outfile.open( 'w', 0644 ) do |ofh|
333
- ofh.print( output )
334
- end
335
- else
336
- debug_msg " would have written %d bytes to %s" %
337
- [ output.length, outfile ]
338
- end
339
- end
340
308
  end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html
2
+ PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
3
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+ <head>
6
+ <meta http-equiv="Content-Type" content="text/html; charset=%charset%"/>
7
+
8
+ <title><%= @title %></title>
9
+ </head>
10
+ <frameset cols="300,*" frameborder="1" border="1" bordercolor="#666666" framespacing="1">
11
+ <frame src="panel/index.html" title="Search" name="panel" />
12
+ <frame src="<%= index_path %>" name="docwin" />
13
+ </frameset>
14
+ </html>
File without changes
File without changes
File without changes
File without changes
@@ -166,7 +166,7 @@ Searchdoc.Searcher.prototype = new function() {
166
166
 
167
167
  /* ----- Utilities ------ */
168
168
  function splitQuery(query) {
169
- return jQuery.grep(query.split(/\s+/), function(string) { return !!string });
169
+ return jQuery.grep(query.split(/(\s+|\(\)?)/), function(string) { return string.match(/\S/) });
170
170
  }
171
171
 
172
172
  function buildRegexps(queries) {
@@ -506,7 +506,7 @@ Searchdoc.Tree.prototype = $.extend({}, Searchdoc.Navigation, new function() {
506
506
  this.move = function(isDown) {
507
507
  if (!this.$current) {
508
508
  this.select(this.$list.find('li:first'));
509
- return;
509
+ return true;
510
510
  }
511
511
  var next = this.$current[0];
512
512
  if (isDown) {
@@ -526,6 +526,7 @@ Searchdoc.Tree.prototype = $.extend({}, Searchdoc.Navigation, new function() {
526
526
  scrollIntoView(next, this.$element[0]);
527
527
  this.$current = $(next);
528
528
  }
529
+ return true;
529
530
  }
530
531
 
531
532
  function toggleVis($li, show) {
data/lib/sdoc/github.rb CHANGED
@@ -54,8 +54,8 @@ module SDoc::GitHub
54
54
 
55
55
  def in_dir(dir)
56
56
  pwd = Dir.pwd
57
- Dir.chdir dir
58
57
  begin
58
+ Dir.chdir dir
59
59
  return yield
60
60
  ensure
61
61
  Dir.chdir pwd
data/lib/sdoc/merge.rb CHANGED
@@ -3,25 +3,34 @@ require 'pathname'
3
3
  require 'fileutils'
4
4
  require 'json'
5
5
 
6
+ require 'sdoc/templatable'
7
+
6
8
  class SDoc::Merge
9
+ include SDoc::Templatable
7
10
 
8
11
  FLAG_FILE = "created.rid"
9
12
 
10
13
  def initialize()
11
14
  @names = []
12
15
  @op_dir = 'doc'
16
+ @title = ''
13
17
  @directories = []
18
+ template_dir = RDoc::Generator::SHtml.template_dir('merge')
19
+ @template_dir = Pathname.new File.expand_path(template_dir)
14
20
  end
15
21
 
16
22
  def merge(options)
17
23
  parse_options options
18
24
 
25
+ @outputdir = Pathname.new( @op_dir )
26
+
19
27
  check_directories
20
28
  setup_output_dir
21
29
  setup_names
22
30
  copy_files
23
- merge_tree
24
31
  merge_search_index
32
+ merge_tree
33
+ generate_index_file
25
34
  end
26
35
 
27
36
  def parse_options(options)
@@ -35,6 +44,10 @@ class SDoc::Merge
35
44
  opt.on("-o", "--op [DIRECTORY]", "Set the output directory") do |v|
36
45
  @op_dir = v
37
46
  end
47
+
48
+ opt.on("-t", "--title [TITLE]", "Set the title of merged file") do |v|
49
+ @title = v
50
+ end
38
51
  end
39
52
  opts.parse! options
40
53
  @directories = options.dup
@@ -49,7 +62,7 @@ class SDoc::Merge
49
62
  subtree = JSON.parse data
50
63
  item = [
51
64
  name,
52
- '',
65
+ @indexes[name]["index"]["info"][0][2],
53
66
  '',
54
67
  append_path(subtree, name)
55
68
  ]
@@ -58,7 +71,7 @@ class SDoc::Merge
58
71
 
59
72
  dst = File.join @op_dir, RDoc::Generator::SHtml::TREE_FILE
60
73
  FileUtils.mkdir_p File.dirname(dst)
61
- File.open(dst, "w") do |f|
74
+ File.open(dst, "w", 0644) do |f|
62
75
  f.write('var tree = '); f.write(tree.to_json)
63
76
  end
64
77
  end
@@ -73,11 +86,13 @@ class SDoc::Merge
73
86
 
74
87
  def merge_search_index
75
88
  items = []
89
+ @indexes = {}
76
90
  @directories.each_with_index do |dir, i|
77
91
  name = @names[i]
78
92
  filename = File.join dir, RDoc::Generator::SHtml::SEARCH_INDEX_FILE
79
93
  data = open(filename).read.sub(/var search_data =\s*/, '')
80
94
  subindex = JSON.parse data
95
+ @indexes[name] = subindex
81
96
 
82
97
  searchIndex = subindex["index"]["searchIndex"]
83
98
  longSearchIndex = subindex["index"]["longSearchIndex"]
@@ -92,15 +107,8 @@ class SDoc::Merge
92
107
  end
93
108
  end
94
109
  items.sort! do |a, b|
95
- a[:info][5] == b[:info][5] ? # type (class/method/file)
96
- (a[:info][0] == b[:info][0] ? # or name
97
- (a[:info][6] == b[:info][6] ? # or doc part
98
- a[:info][1] <=> b[:info][1] : # or namespace
99
- a[:info][6] <=> b[:info][6]
100
- ) :
101
- a[:info][0] <=> b[:info][0]
102
- ) :
103
- a[:info][5] <=> b[:info][5]
110
+ # type (class/method/file) or name or doc part or namespace
111
+ [a[:info][5], a[:info][0], a[:info][6], a[:info][1]] <=> [b[:info][5], b[:info][0], b[:info][6], b[:info][1]]
104
112
  end
105
113
 
106
114
  index = {
@@ -115,13 +123,21 @@ class SDoc::Merge
115
123
 
116
124
  dst = File.join @op_dir, RDoc::Generator::SHtml::SEARCH_INDEX_FILE
117
125
  FileUtils.mkdir_p File.dirname(dst)
118
- File.open(dst, "w") do |f|
126
+ File.open(dst, "w", 0644) do |f|
119
127
  f.write('var search_data = '); f.write(search_data.to_json)
120
128
  end
121
129
  end
122
130
 
131
+ def generate_index_file
132
+ templatefile = @template_dir + 'index.rhtml'
133
+ outfile = @outputdir + 'index.html'
134
+ index_path = @indexes[@names.first]["index"]["info"][0][2]
135
+
136
+ render_template templatefile, binding(), outfile
137
+ end
138
+
123
139
  def setup_names
124
- unless @names.size
140
+ unless @names.size > 0
125
141
  @directories.each do |dir|
126
142
  name = File.basename dir
127
143
  name = File.basename File.dirname(dir) if name == 'doc'
@@ -138,7 +154,7 @@ class SDoc::Merge
138
154
 
139
155
  Dir.new(dir).each do |item|
140
156
  if File.directory?(File.join(dir, item)) && item != '.' && item != '..' && item != index_dir
141
- FileUtils.cp_r File.join(dir, item), File.join(@op_dir, name, item)
157
+ FileUtils.cp_r File.join(dir, item), File.join(@op_dir, name, item), :preserve => true
142
158
  end
143
159
  end
144
160
  end
@@ -146,7 +162,7 @@ class SDoc::Merge
146
162
  dir = @directories.first
147
163
  Dir.new(dir).each do |item|
148
164
  if item != '.' && item != '..' && item != RDoc::Generator::SHtml::FILE_DIR && item != RDoc::Generator::SHtml::CLASS_DIR
149
- FileUtils.cp_r File.join(dir, item), @op_dir
165
+ FileUtils.cp_r File.join(dir, item), @op_dir, :preserve => true
150
166
  end
151
167
  end
152
168
  end
@@ -168,10 +184,6 @@ class SDoc::Merge
168
184
  end
169
185
  end
170
186
 
171
- def update_output_dir(op_dir, time)
172
- File.open(File.join @op_dir, FLAG_FILE, "w") { |f| f.puts time.rfc2822 }
173
- end
174
-
175
187
  ##
176
188
  # Report an error message and exit
177
189
 
@@ -0,0 +1,45 @@
1
+ require "sdoc"
2
+
3
+ module SDoc::Templatable
4
+ ### Load and render the erb template in the given +templatefile+ within the
5
+ ### specified +context+ (a Binding object) and return output
6
+ ### Both +templatefile+ and +outfile+ should be Pathname-like objects.
7
+ def eval_template(templatefile, context)
8
+ template_src = templatefile.read
9
+ template = ERB.new( template_src, nil, '<>' )
10
+ template.filename = templatefile.to_s
11
+
12
+ begin
13
+ template.result( context )
14
+ rescue NoMethodError => err
15
+ raise RDoc::Error, "Error while evaluating %s: %s (at %p)" % [
16
+ templatefile.to_s,
17
+ err.message,
18
+ eval( "_erbout[-50,50]", context )
19
+ ], err.backtrace
20
+ end
21
+ end
22
+
23
+ ### Load and render the erb template with the given +template_name+ within
24
+ ### current context. Adds all +local_assigns+ to context
25
+ def include_template(template_name, local_assigns = {})
26
+ source = local_assigns.keys.map { |key| "#{key} = local_assigns[:#{key}];" }.join
27
+ eval("#{source};templatefile = @template_dir + template_name;eval_template(templatefile, binding)")
28
+ end
29
+
30
+ ### Load and render the erb template in the given +templatefile+ within the
31
+ ### specified +context+ (a Binding object) and write it out to +outfile+.
32
+ ### Both +templatefile+ and +outfile+ should be Pathname-like objects.
33
+ def render_template( templatefile, context, outfile )
34
+ output = eval_template(templatefile, context)
35
+ unless $dryrun
36
+ outfile.dirname.mkpath
37
+ outfile.open( 'w', 0644 ) do |file|
38
+ file.print( output )
39
+ end
40
+ else
41
+ debug_msg " would have written %d bytes to %s" %
42
+ [ output.length, outfile ]
43
+ end
44
+ end
45
+ 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.1.10
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Volodya Kolesnikov
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-02 00:00:00 -07:00
12
+ date: 2009-04-03 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -51,6 +51,8 @@ files:
51
51
  - lib/sdoc/generator
52
52
  - lib/sdoc/generator/shtml.rb
53
53
  - lib/sdoc/generator/template
54
+ - lib/sdoc/generator/template/merge
55
+ - lib/sdoc/generator/template/merge/index.rhtml
54
56
  - lib/sdoc/generator/template/shtml
55
57
  - lib/sdoc/generator/template/shtml/_context.rhtml
56
58
  - lib/sdoc/generator/template/shtml/class.rhtml
@@ -73,6 +75,7 @@ files:
73
75
  - lib/sdoc/generator/template/shtml/resources/panel/index.html
74
76
  - lib/sdoc/github.rb
75
77
  - lib/sdoc/merge.rb
78
+ - lib/sdoc/templatable.rb
76
79
  - lib/sdoc.rb
77
80
  - README
78
81
  - LICENSE