Sha256: c64a5647ecce196e55dd72bbca7924a19169c8d852de85a41c5ca8c4f2acb27d

Contents?: true

Size: 1.89 KB

Versions: 8

Compression:

Stored size: 1.89 KB

Contents

# This file use notugly.xsl: An XSL transform to pretty up the SVG output from Graphviz
#
# See: http://www.hokstad.com/making-graphviz-output-pretty-with-xsl.html
# And: http://www.hokstad.com/making-graphviz-output-pretty-with-xsl-updated.html
#
# By Vidar Hokstad and Ryan Shea; Contributions by Jonas Tingborn,
# Earl Cummings, Michael Kennedy (Graphviz 2.20.2 compatibility, bug fixes,
# testing, lots of gradients)

require 'rubygems'
begin
   require 'xml/xslt'
   XSLT_METHOD = :xml_xslt_transform
rescue LoadError => e
   require 'libxml'
   require 'libxslt'
   XSLT_METHOD = :libxslt_transform
end

class GraphViz
  # Transform to pretty up the SVG output
  #
  # For more information, see http://www.hokstad.com/making-graphviz-output-pretty-with-xsl.html
  # and http://www.hokstad.com/making-graphviz-output-pretty-with-xsl-updated.html
  #
  # You can use the :nothugly option to GraphViz#output :
  #
  #   graph.output( :svg => "myGraph.svg", :nothugly => true )
  #
  # Or directly on an SVG output graph :
  #
  #   GraphViz.nothugly( "myGraph.svg" )
  def self.nothugly( file, save = true )
    xsl = File.join( File.dirname(File.expand_path(__FILE__)), "nothugly", "nothugly.xsl" )
    out = self.send(XSLT_METHOD, file, xsl)

    if save
      fname = File.join( File.dirname(File.expand_path(file)), File.basename(file))
      File.open( fname, "w" ) { |io|
        io.print out
      }
    else
      return out
    end
  end

  def self.xml_xslt_transform(xml, xsl)
    xslt = XML::XSLT.new()
    xslt.xml = xml
    xslt.xsl = xsl
    xslt.serve()
  end

  def self.libxslt_transform(xml, xsl)
     LibXML::XML.default_load_external_dtd = false
     LibXML::XML.default_substitute_entities = false

     stylesheet_doc = LibXML::XML::Document.file(xsl)
     stylesheet = LibXSLT::XSLT::Stylesheet.new(stylesheet_doc)
     xml_doc = LibXML::XML::Document.file(xml)
     stylesheet.apply(xml_doc).to_s
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
ruby-graphviz-1.2.2 lib/graphviz/nothugly.rb
ruby-graphviz-1.2.1 lib/graphviz/nothugly.rb
ruby-graphviz-1.2.0 lib/graphviz/nothugly.rb
ruby-graphviz-1.1.0 lib/graphviz/nothugly.rb
ruby-graphviz_c-1.1.1 lib/graphviz/nothugly.rb
ruby-graphviz_c-1.1.0 lib/graphviz/nothugly.rb
ruby-graphviz-1.0.9 lib/graphviz/nothugly.rb
ruby-graphviz-1.0.8 lib/graphviz/nothugly.rb