ruby-changes:3435
From: ko1@a...
Date: 7 Jan 2008 16:07:18 +0900
Subject: [ruby-changes:3435] drbrain - Ruby:r14928 (trunk): Namespace RDoc::DOT. Clean up formatting of RDoc::Diagrams.
drbrain 2008-01-07 16:06:59 +0900 (Mon, 07 Jan 2008) New Revision: 14928 Modified files: trunk/ChangeLog trunk/lib/rdoc/diagram.rb trunk/lib/rdoc/dot.rb Log: Namespace RDoc::DOT. Clean up formatting of RDoc::Diagrams. http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=14928&r2=14927&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/lib/rdoc/dot.rb?r1=14928&r2=14927&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/lib/rdoc/diagram.rb?r1=14928&r2=14927&diff_format=u Index: ChangeLog =================================================================== --- ChangeLog (revision 14927) +++ ChangeLog (revision 14928) @@ -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@s...> * lib/rdoc/options.rb: Convert to OptionParser, clean up -h output, Index: lib/rdoc/diagram.rb =================================================================== --- lib/rdoc/diagram.rb (revision 14927) +++ lib/rdoc/diagram.rb (revision 14928) @@ -30,8 +30,9 @@ 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 @@ @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 @@ @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 @@ @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 @@ @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 @@ 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 @@ # 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 @@ 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 @@ } 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 @@ 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 @@ 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 @@ 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 @@ res << %{<img src="#{dot}" usemap="#map" border="0" alt="#{dot}">} return res end + end end Index: lib/rdoc/dot.rb =================================================================== --- lib/rdoc/dot.rb (revision 14927) +++ lib/rdoc/dot.rb (revision 14928) @@ -1,5 +1,7 @@ -module DOT +module RDoc; end +module RDoc::DOT + TAB = ' ' TAB2 = TAB * 2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml