summaryrefslogtreecommitdiff
path: root/lib/rdoc
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-01-07 07:06:59 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-01-07 07:06:59 +0000
commit9ad5f854e745043e144408b6408f38dff7bcf880 (patch)
treee607cbd78083928f935aa0c1c7ee9c1318401be4 /lib/rdoc
parent4b93d732e406957e094e848093517359b9ffecf4 (diff)
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
Diffstat (limited to 'lib/rdoc')
-rw-r--r--lib/rdoc/diagram.rb147
-rw-r--r--lib/rdoc/dot.rb4
2 files changed, 77 insertions, 74 deletions
diff --git a/lib/rdoc/diagram.rb b/lib/rdoc/diagram.rb
index 3b6547905c..e235e043dc 100644
--- a/lib/rdoc/diagram.rb
+++ b/lib/rdoc/diagram.rb
@@ -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
diff --git a/lib/rdoc/dot.rb b/lib/rdoc/dot.rb
index 01974af504..fbd2cfba02 100644
--- a/lib/rdoc/dot.rb
+++ b/lib/rdoc/dot.rb
@@ -1,4 +1,6 @@
-module DOT
+module RDoc; end
+
+module RDoc::DOT
TAB = ' '
TAB2 = TAB * 2