mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Namespace RDoc::DOT. Clean up formatting of RDoc::Diagrams.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14928 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
4b93d732e4
commit
9ad5f854e7
3 changed files with 83 additions and 74 deletions
|
@ -1,3 +1,9 @@
|
|||
Mon Jan 7 16:06:09 2008
|
||||
|
||||
* lib/rdoc/dot.rb: Namespace under RDoc.
|
||||
|
||||
* lib/rdoc/diagram.rb: Clean up formatting.
|
||||
|
||||
Mon Jan 7 15:51:35 2008 Eric Hodel <drbrain@segment7.net>
|
||||
|
||||
* lib/rdoc/options.rb: Convert to OptionParser, clean up -h output,
|
||||
|
|
|
@ -30,8 +30,9 @@ module RDoc
|
|||
|
||||
DOT_PATH = "dot"
|
||||
|
||||
# Pass in the set of top level objects. The method also creates
|
||||
# the subdirectory to hold the images
|
||||
##
|
||||
# Pass in the set of top level objects. The method also creates the
|
||||
# subdirectory to hold the images
|
||||
|
||||
def initialize(info, options)
|
||||
@info = info
|
||||
|
@ -41,9 +42,10 @@ module RDoc
|
|||
@diagram_cache = {}
|
||||
end
|
||||
|
||||
# Draw the diagrams. We traverse the files, drawing a diagram for
|
||||
# each. We also traverse each top-level class and module in that
|
||||
# file drawing a diagram for these too.
|
||||
##
|
||||
# Draw the diagrams. We traverse the files, drawing a diagram for each. We
|
||||
# also traverse each top-level class and module in that file drawing a
|
||||
# diagram for these too.
|
||||
|
||||
def draw
|
||||
unless @options.quiet
|
||||
|
@ -56,25 +58,25 @@ module RDoc
|
|||
@local_names = find_names(i)
|
||||
@global_names = []
|
||||
@global_graph = graph = DOT::Digraph.new('name' => 'TopLevel',
|
||||
'fontname' => FONT,
|
||||
'fontsize' => '8',
|
||||
'bgcolor' => 'lightcyan1',
|
||||
'compound' => 'true')
|
||||
|
||||
'fontname' => FONT,
|
||||
'fontsize' => '8',
|
||||
'bgcolor' => 'lightcyan1',
|
||||
'compound' => 'true')
|
||||
|
||||
# it's a little hack %) i'm too lazy to create a separate class
|
||||
# for default node
|
||||
graph << DOT::Node.new('name' => 'node',
|
||||
'fontname' => FONT,
|
||||
'color' => 'black',
|
||||
'fontsize' => 8)
|
||||
|
||||
'fontname' => FONT,
|
||||
'color' => 'black',
|
||||
'fontsize' => 8)
|
||||
|
||||
i.modules.each do |mod|
|
||||
draw_module(mod, graph, true, i.file_relative_name)
|
||||
end
|
||||
add_classes(i, graph, i.file_relative_name)
|
||||
|
||||
i.diagram = convert_to_png("f_#{file_count}", graph)
|
||||
|
||||
|
||||
# now go through and document each top level class and
|
||||
# module independently
|
||||
i.modules.each_with_index do |mod, count|
|
||||
|
@ -83,26 +85,24 @@ module RDoc
|
|||
@global_names = []
|
||||
|
||||
@global_graph = graph = DOT::Digraph.new('name' => 'TopLevel',
|
||||
'fontname' => FONT,
|
||||
'fontsize' => '8',
|
||||
'bgcolor' => 'lightcyan1',
|
||||
'compound' => 'true')
|
||||
'fontname' => FONT,
|
||||
'fontsize' => '8',
|
||||
'bgcolor' => 'lightcyan1',
|
||||
'compound' => 'true')
|
||||
|
||||
graph << DOT::Node.new('name' => 'node',
|
||||
'fontname' => FONT,
|
||||
'color' => 'black',
|
||||
'fontsize' => 8)
|
||||
'fontname' => FONT,
|
||||
'color' => 'black',
|
||||
'fontsize' => 8)
|
||||
draw_module(mod, graph, true)
|
||||
mod.diagram = convert_to_png("m_#{file_count}_#{count}",
|
||||
graph)
|
||||
mod.diagram = convert_to_png("m_#{file_count}_#{count}",
|
||||
graph)
|
||||
end
|
||||
end
|
||||
$stderr.puts unless @options.quiet
|
||||
end
|
||||
|
||||
#######
|
||||
private
|
||||
#######
|
||||
|
||||
def find_names(mod)
|
||||
return [mod.full_name] + mod.classes.collect{|cl| cl.full_name} +
|
||||
|
@ -128,13 +128,13 @@ module RDoc
|
|||
@counter += 1
|
||||
url = mod.http_url("classes")
|
||||
m = DOT::Subgraph.new('name' => "cluster_#{mod.full_name.gsub( /:/,'_' )}",
|
||||
'label' => mod.name,
|
||||
'fontname' => FONT,
|
||||
'color' => 'blue',
|
||||
'style' => 'filled',
|
||||
'URL' => %{"#{url}"},
|
||||
'fillcolor' => toplevel ? 'palegreen1' : 'palegreen3')
|
||||
|
||||
'label' => mod.name,
|
||||
'fontname' => FONT,
|
||||
'color' => 'blue',
|
||||
'style' => 'filled',
|
||||
'URL' => %{"#{url}"},
|
||||
'fillcolor' => toplevel ? 'palegreen1' : 'palegreen3')
|
||||
|
||||
@done_modules[mod.full_name] = m
|
||||
add_classes(mod, m, file)
|
||||
graph << m
|
||||
|
@ -144,22 +144,22 @@ module RDoc
|
|||
m_full_name = find_full_name(inc.name, mod)
|
||||
if @local_names.include?(m_full_name)
|
||||
@global_graph << DOT::Edge.new('from' => "#{m_full_name.gsub( /:/,'_' )}",
|
||||
'to' => "#{mod.full_name.gsub( /:/,'_' )}",
|
||||
'ltail' => "cluster_#{m_full_name.gsub( /:/,'_' )}",
|
||||
'lhead' => "cluster_#{mod.full_name.gsub( /:/,'_' )}")
|
||||
'to' => "#{mod.full_name.gsub( /:/,'_' )}",
|
||||
'ltail' => "cluster_#{m_full_name.gsub( /:/,'_' )}",
|
||||
'lhead' => "cluster_#{mod.full_name.gsub( /:/,'_' )}")
|
||||
else
|
||||
unless @global_names.include?(m_full_name)
|
||||
path = m_full_name.split("::")
|
||||
url = File.join('classes', *path) + ".html"
|
||||
@global_graph << DOT::Node.new('name' => "#{m_full_name.gsub( /:/,'_' )}",
|
||||
'shape' => 'box',
|
||||
'label' => "#{m_full_name}",
|
||||
'URL' => %{"#{url}"})
|
||||
'shape' => 'box',
|
||||
'label' => "#{m_full_name}",
|
||||
'URL' => %{"#{url}"})
|
||||
@global_names << m_full_name
|
||||
end
|
||||
@global_graph << DOT::Edge.new('from' => "#{m_full_name.gsub( /:/,'_' )}",
|
||||
'to' => "#{mod.full_name.gsub( /:/,'_' )}",
|
||||
'lhead' => "cluster_#{mod.full_name.gsub( /:/,'_' )}")
|
||||
'to' => "#{mod.full_name.gsub( /:/,'_' )}",
|
||||
'lhead' => "cluster_#{mod.full_name.gsub( /:/,'_' )}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -174,13 +174,14 @@ module RDoc
|
|||
# create dummy node (needed if empty and for module includes)
|
||||
if container.full_name
|
||||
graph << DOT::Node.new('name' => "#{container.full_name.gsub( /:/,'_' )}",
|
||||
'label' => "",
|
||||
'width' => (container.classes.empty? and
|
||||
container.modules.empty?) ?
|
||||
'0.75' : '0.01',
|
||||
'height' => '0.01',
|
||||
'shape' => 'plaintext')
|
||||
'label' => "",
|
||||
'width' => (container.classes.empty? and
|
||||
container.modules.empty?) ?
|
||||
'0.75' : '0.01',
|
||||
'height' => '0.01',
|
||||
'shape' => 'plaintext')
|
||||
end
|
||||
|
||||
container.classes.each_with_index do |cl, cl_index|
|
||||
last_file = cl.in_files[-1].file_relative_name
|
||||
|
||||
|
@ -197,16 +198,16 @@ module RDoc
|
|||
next if cl.name == 'Object' || cl.name[0,2] == "<<"
|
||||
|
||||
url = cl.http_url("classes")
|
||||
|
||||
|
||||
label = cl.name.dup
|
||||
if use_fileboxes && cl.in_files.length > 1
|
||||
label << '\n[' +
|
||||
label << '\n[' +
|
||||
cl.in_files.collect {|i|
|
||||
i.file_relative_name
|
||||
i.file_relative_name
|
||||
}.sort.join( '\n' ) +
|
||||
']'
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
attrs = {
|
||||
'name' => "#{cl.full_name.gsub( /:/, '_' )}",
|
||||
'fontcolor' => 'black',
|
||||
|
@ -218,40 +219,40 @@ module RDoc
|
|||
}
|
||||
|
||||
c = DOT::Node.new(attrs)
|
||||
|
||||
|
||||
if use_fileboxes
|
||||
files[last_file].push c
|
||||
files[last_file].push c
|
||||
else
|
||||
graph << c
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if use_fileboxes
|
||||
files.each_value do |val|
|
||||
graph << val
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
unless container.classes.empty?
|
||||
container.classes.each_with_index do |cl, cl_index|
|
||||
cl.includes.each do |m|
|
||||
m_full_name = find_full_name(m.name, cl)
|
||||
if @local_names.include?(m_full_name)
|
||||
@global_graph << DOT::Edge.new('from' => "#{m_full_name.gsub( /:/,'_' )}",
|
||||
'to' => "#{cl.full_name.gsub( /:/,'_' )}",
|
||||
'ltail' => "cluster_#{m_full_name.gsub( /:/,'_' )}")
|
||||
'to' => "#{cl.full_name.gsub( /:/,'_' )}",
|
||||
'ltail' => "cluster_#{m_full_name.gsub( /:/,'_' )}")
|
||||
else
|
||||
unless @global_names.include?(m_full_name)
|
||||
path = m_full_name.split("::")
|
||||
url = File.join('classes', *path) + ".html"
|
||||
@global_graph << DOT::Node.new('name' => "#{m_full_name.gsub( /:/,'_' )}",
|
||||
'shape' => 'box',
|
||||
'label' => "#{m_full_name}",
|
||||
'URL' => %{"#{url}"})
|
||||
'shape' => 'box',
|
||||
'label' => "#{m_full_name}",
|
||||
'URL' => %{"#{url}"})
|
||||
@global_names << m_full_name
|
||||
end
|
||||
@global_graph << DOT::Edge.new('from' => "#{m_full_name.gsub( /:/,'_' )}",
|
||||
'to' => "#{cl.full_name.gsub( /:/, '_')}")
|
||||
'to' => "#{cl.full_name.gsub( /:/, '_')}")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -261,21 +262,20 @@ module RDoc
|
|||
unless @local_names.include?(sclass_full_name) or @global_names.include?(sclass_full_name)
|
||||
path = sclass_full_name.split("::")
|
||||
url = File.join('classes', *path) + ".html"
|
||||
@global_graph << DOT::Node.new(
|
||||
'name' => "#{sclass_full_name.gsub( /:/, '_' )}",
|
||||
'label' => sclass_full_name,
|
||||
'URL' => %{"#{url}"})
|
||||
@global_graph << DOT::Node.new('name' => "#{sclass_full_name.gsub( /:/, '_' )}",
|
||||
'label' => sclass_full_name,
|
||||
'URL' => %{"#{url}"})
|
||||
@global_names << sclass_full_name
|
||||
end
|
||||
@global_graph << DOT::Edge.new('from' => "#{sclass_full_name.gsub( /:/,'_' )}",
|
||||
'to' => "#{cl.full_name.gsub( /:/, '_')}")
|
||||
'to' => "#{cl.full_name.gsub( /:/, '_')}")
|
||||
end
|
||||
end
|
||||
|
||||
container.modules.each do |submod|
|
||||
draw_module(submod, graph)
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
def convert_to_png(file_base, graph)
|
||||
|
@ -294,7 +294,7 @@ module RDoc
|
|||
File.open(src, 'w+' ) do |f|
|
||||
f << str << "\n"
|
||||
end
|
||||
|
||||
|
||||
system "dot", "-T#{op_type}", src, "-o", dot
|
||||
|
||||
# Now construct the imagemap wrapper around
|
||||
|
@ -305,10 +305,10 @@ module RDoc
|
|||
return ret
|
||||
end
|
||||
|
||||
# Extract the client-side image map from dot, and use it
|
||||
# to generate the imagemap proper. Return the whole
|
||||
# <map>..<img> combination, suitable for inclusion on
|
||||
# the page
|
||||
##
|
||||
# Extract the client-side image map from dot, and use it to generate the
|
||||
# imagemap proper. Return the whole <map>..<img> combination, suitable for
|
||||
# inclusion on the page
|
||||
|
||||
def wrap_in_image_map(src, dot)
|
||||
res = %{<map id="map" name="map">\n}
|
||||
|
@ -331,6 +331,7 @@ module RDoc
|
|||
res << %{<img src="#{dot}" usemap="#map" border="0" alt="#{dot}">}
|
||||
return res
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
module DOT
|
||||
module RDoc; end
|
||||
|
||||
module RDoc::DOT
|
||||
|
||||
TAB = ' '
|
||||
TAB2 = TAB * 2
|
||||
|
|
Loading…
Reference in a new issue