ruby-changes:3269
From: ko1@a...
Date: 28 Dec 2007 16:11:53 +0900
Subject: [ruby-changes:3269] drbrain - Ruby:r14762 (trunk): Move lib/rdoc/dot/dot.rb to lib/rdoc, un-namespace.
drbrain 2007-12-28 16:11:30 +0900 (Fri, 28 Dec 2007) New Revision: 14762 Added files: trunk/lib/rdoc/dot.rb Removed directories: trunk/lib/rdoc/dot/ Modified files: trunk/ChangeLog trunk/lib/rdoc/diagram.rb Log: Move lib/rdoc/dot/dot.rb to lib/rdoc, un-namespace. Fix lib/rdoc/diagrom.rb for 1.9 Deleted: trunk/lib/rdoc/dot/ % svn ls -r 14762 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/lib/rdoc/dot/ http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=14762&r2=14761 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/lib/rdoc/dot.rb http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/lib/rdoc/diagram.rb?r1=14762&r2=14761 Index: ChangeLog =================================================================== --- ChangeLog (revision 14761) +++ ChangeLog (revision 14762) @@ -1,3 +1,9 @@ +Fri Dec 28 16:10:00 2007 Eric Hodel <drbrain@s...> + + * lib/rdoc/dot/dot.rb: Move to lib/rdoc/dot.rb. Fix namespacing. + + * lib/rdoc/diagram.rb: Update for 1.9. + Fri Dec 28 15:38:29 2007 Eric Hodel <drbrain@s...> * lib/rdoc/markup/sample/: Move to sample/rdoc/markup directory. Index: lib/rdoc/diagram.rb =================================================================== --- lib/rdoc/diagram.rb (revision 14761) +++ lib/rdoc/diagram.rb (revision 14762) @@ -4,7 +4,7 @@ # You must have the V1.7 or later in your path # http://www.research.att.com/sw/tools/graphviz/ -require "rdoc/dot/dot" +require "rdoc/dot" require 'rdoc/options' module RDoc @@ -55,7 +55,7 @@ @done_modules = {} @local_names = find_names(i) @global_names = [] - @global_graph = graph = DOT::DOTDigraph.new('name' => 'TopLevel', + @global_graph = graph = DOT::Digraph.new('name' => 'TopLevel', 'fontname' => FONT, 'fontsize' => '8', 'bgcolor' => 'lightcyan1', @@ -63,7 +63,7 @@ # it's a little hack %) i'm too lazy to create a separate class # for default node - graph << DOT::DOTNode.new('name' => 'node', + graph << DOT::Node.new('name' => 'node', 'fontname' => FONT, 'color' => 'black', 'fontsize' => 8) @@ -82,13 +82,13 @@ @local_names = find_names(mod) @global_names = [] - @global_graph = graph = DOT::DOTDigraph.new('name' => 'TopLevel', + @global_graph = graph = DOT::Digraph.new('name' => 'TopLevel', 'fontname' => FONT, 'fontsize' => '8', 'bgcolor' => 'lightcyan1', 'compound' => 'true') - graph << DOT::DOTNode.new('name' => 'node', + graph << DOT::Node.new('name' => 'node', 'fontname' => FONT, 'color' => 'black', 'fontsize' => 8) @@ -127,7 +127,7 @@ @counter += 1 url = mod.http_url("classes") - m = DOT::DOTSubgraph.new('name' => "cluster_#{mod.full_name.gsub( /:/,'_' )}", + m = DOT::Subgraph.new('name' => "cluster_#{mod.full_name.gsub( /:/,'_' )}", 'label' => mod.name, 'fontname' => FONT, 'color' => 'blue', @@ -143,7 +143,7 @@ mod.includes.each do |inc| m_full_name = find_full_name(inc.name, mod) if @local_names.include?(m_full_name) - @global_graph << DOT::DOTEdge.new('from' => "#{m_full_name.gsub( /:/,'_' )}", + @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( /:/,'_' )}") @@ -151,13 +151,13 @@ unless @global_names.include?(m_full_name) path = m_full_name.split("::") url = File.join('classes', *path) + ".html" - @global_graph << DOT::DOTNode.new('name' => "#{m_full_name.gsub( /:/,'_' )}", + @global_graph << DOT::Node.new('name' => "#{m_full_name.gsub( /:/,'_' )}", 'shape' => 'box', 'label' => "#{m_full_name}", 'URL' => %{"#{url}"}) @global_names << m_full_name end - @global_graph << DOT::DOTEdge.new('from' => "#{m_full_name.gsub( /:/,'_' )}", + @global_graph << DOT::Edge.new('from' => "#{m_full_name.gsub( /:/,'_' )}", 'to' => "#{mod.full_name.gsub( /:/,'_' )}", 'lhead' => "cluster_#{mod.full_name.gsub( /:/,'_' )}") end @@ -173,7 +173,7 @@ # create dummy node (needed if empty and for module includes) if container.full_name - graph << DOT::DOTNode.new('name' => "#{container.full_name.gsub( /:/,'_' )}", + graph << DOT::Node.new('name' => "#{container.full_name.gsub( /:/,'_' )}", 'label' => "", 'width' => (container.classes.empty? and container.modules.empty?) ? @@ -187,7 +187,7 @@ if use_fileboxes && !files.include?(last_file) @counter += 1 files[last_file] = - DOT::DOTSubgraph.new('name' => "cluster_#{@counter}", + DOT::Subgraph.new('name' => "cluster_#{@counter}", 'label' => "#{last_file}", 'fontname' => FONT, 'color'=> @@ -217,7 +217,7 @@ 'URL' => %{"#{url}"} } - c = DOT::DOTNode.new(attrs) + c = DOT::Node.new(attrs) if use_fileboxes files[last_file].push c @@ -237,20 +237,20 @@ cl.includes.each do |m| m_full_name = find_full_name(m.name, cl) if @local_names.include?(m_full_name) - @global_graph << DOT::DOTEdge.new('from' => "#{m_full_name.gsub( /:/,'_' )}", + @global_graph << DOT::Edge.new('from' => "#{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::DOTNode.new('name' => "#{m_full_name.gsub( /:/,'_' )}", + @global_graph << DOT::Node.new('name' => "#{m_full_name.gsub( /:/,'_' )}", 'shape' => 'box', 'label' => "#{m_full_name}", 'URL' => %{"#{url}"}) @global_names << m_full_name end - @global_graph << DOT::DOTEdge.new('from' => "#{m_full_name.gsub( /:/,'_' )}", + @global_graph << DOT::Edge.new('from' => "#{m_full_name.gsub( /:/,'_' )}", 'to' => "#{cl.full_name.gsub( /:/, '_')}") end end @@ -261,13 +261,13 @@ 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::DOTNode.new( + @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::DOTEdge.new('from' => "#{sclass_full_name.gsub( /:/,'_' )}", + @global_graph << DOT::Edge.new('from' => "#{sclass_full_name.gsub( /:/,'_' )}", 'to' => "#{cl.full_name.gsub( /:/, '_')}") end end @@ -313,12 +313,12 @@ def wrap_in_image_map(src, dot) res = %{<map id="map" name="map">\n} dot_map = `dot -Tismap #{src}` - dot_map.each do |area| + dot_map.split($/).each do |area| unless area =~ /^rectangle \((\d+),(\d+)\) \((\d+),(\d+)\) ([\/\w.]+)\s*(.*)/ $stderr.puts "Unexpected output from dot:\n#{area}" return nil end - + xs, ys = [$1.to_i, $3.to_i], [$2.to_i, $4.to_i] url, area_name = $5, $6 Index: lib/rdoc/dot.rb =================================================================== --- lib/rdoc/dot.rb (revision 0) +++ lib/rdoc/dot.rb (revision 14762) @@ -0,0 +1,247 @@ +module DOT + + TAB = ' ' + TAB2 = TAB * 2 + + # options for node declaration + NODE_OPTS = [ + 'bgcolor', + 'color', + 'fontcolor', + 'fontname', + 'fontsize', + 'height', + 'width', + 'label', + 'layer', + 'rank', + 'shape', + 'shapefile', + 'style', + 'URL', + ] + + # options for edge declaration + EDGE_OPTS = [ + 'color', + 'decorate', + 'dir', + 'fontcolor', + 'fontname', + 'fontsize', + 'id', + 'label', + 'layer', + 'lhead', + 'ltail', + 'minlen', + 'style', + 'weight' + ] + + # options for graph declaration + GRAPH_OPTS = [ + 'bgcolor', + 'center', + 'clusterrank', + 'color', + 'compound', + 'concentrate', + 'fillcolor', + 'fontcolor', + 'fontname', + 'fontsize', + 'label', + 'layerseq', + 'margin', + 'mclimit', + 'nodesep', + 'nslimit', + 'ordering', + 'orientation', + 'page', + 'rank', + 'rankdir', + 'ranksep', + 'ratio', + 'size', + 'style', + 'URL' + ] + + # a root class for any element in dot notation + class SimpleElement + attr_accessor :name + + def initialize( params = {} ) + @label = params['name'] ? params['name'] : '' + end + + def to_s + @name + end + end + + # an element that has options ( node, edge or graph ) + class Element < SimpleElement + #attr_reader :parent + attr_accessor :name, :options + + def initialize( params = {}, option_list = [] ) + super( params ) + @name = params['name'] ? params['name'] : nil + @parent = params['parent'] ? params['parent'] : nil + @options = {} + option_list.each{ |i| + @options[i] = params[i] if params[i] + } + @options['label'] ||= @name if @name != 'node' + end + + def each_option + @options.each{ |i| yield i } + end + + def each_option_pair + @options.each_pair{ |key, val| yield key, val } + end + + #def parent=( thing ) + # @parent.delete( self ) if defined?( @parent ) and @parent + # @parent = thing + #end + end + + + # this is used when we build nodes that have shape=record + # ports don't have options :) + class Port < SimpleElement + attr_accessor :label + + def initialize( params = {} ) + super( params ) + @name = params['label'] ? params['label'] : '' + end + def to_s + ( @name && @name != "" ? "<#{@name}>" : "" ) + "#{@label}" + end + end + + # node element + class Node < Element + + def initialize( params = {}, option_list = NODE_OPTS ) + super( params, option_list ) + @ports = params['ports'] ? params['ports'] : [] + end + + def each_port + @ports.each{ |i| yield i } + end + + def << ( thing ) + @ports << thing + end + + def push ( thing ) + @ports.push( thing ) + end + + def pop + @ports.pop + end + + def to_s( t = '' ) + + label = @options['shape'] != 'record' && @ports.length == 0 ? + @options['label'] ? + t + TAB + "label = \"#{@options['label']}\"\n" : + '' : + t + TAB + 'label = "' + " \\\n" + + t + TAB2 + "#{@options['label']}| \\\n" + + @ports.collect{ |i| + t + TAB2 + i.to_s + }.join( "| \\\n" ) + " \\\n" + + t + TAB + '"' + "\n" + + t + "#{@name} [\n" + + @options.to_a.collect{ |i| + i[1] && i[0] != 'label' ? + t + TAB + "#{i[0]} = #{i[1]}" : nil + }.compact.join( ",\n" ) + ( label != '' ? ",\n" : "\n" ) + + label + + t + "]\n" + end + end + + # subgraph element is the same to graph, but has another header in dot + # notation + class Subgraph < Element + + def initialize( params = {}, option_list = GRAPH_OPTS ) + super( params, option_list ) + @nodes = params['nodes'] ? params['nodes'] : [] + @dot_string = 'subgraph' + end + + def each_node + @nodes.each{ |i| yield i } + end + + def << ( thing ) + @nodes << thing + end + + def push( thing ) + @nodes.push( thing ) + end + + def pop + @nodes.pop + end + + def to_s( t = '' ) + hdr = t + "#{@dot_string} #{@name} {\n" + + options = @options.to_a.collect{ |name, val| + val && name != 'label' ? + t + TAB + "#{name} = #{val}" : + name ? t + TAB + "#{name} = \"#{val}\"" : nil + }.compact.join( "\n" ) + "\n" + + nodes = @nodes.collect{ |i| + i.to_s( t + TAB ) + }.join( "\n" ) + "\n" + hdr + options + nodes + t + "}\n" + end + end + + # this is graph + class Digraph < Subgraph + def initialize( params = {}, option_list = GRAPH_OPTS ) + super( params, option_list ) + @dot_string = 'digraph' + end + end + + # this is edge + class Edge < Element + attr_accessor :from, :to + def initialize( params = {}, option_list = EDGE_OPTS ) + super( params, option_list ) + @from = params['from'] ? params['from'] : nil + @to = params['to'] ? params['to'] : nil + end + + def to_s( t = '' ) + t + "#{@from} -> #{to} [\n" + + @options.to_a.collect{ |i| + i[1] && i[0] != 'label' ? + t + TAB + "#{i[0]} = #{i[1]}" : + i[1] ? t + TAB + "#{i[0]} = \"#{i[1]}\"" : nil + }.compact.join( "\n" ) + "\n" + t + "]\n" + end + end + +end + Property changes on: lib/rdoc/dot.rb ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + LF -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml