Class: DepVizDoc
- Inherits:
-
DepViz
- Object
- DepViz
- DepVizDoc
- Defined in:
- lib/depvizdoc.rb
Instance Method Summary collapse
- #build(s) ⇒ Object
-
#initialize(s = '', root: 'platform', style: default_stylesheet(), path: '.', debug: false) ⇒ DepVizDoc
constructor
A new instance of DepVizDoc.
- #render(path = @path) ⇒ Object
Constructor Details
#initialize(s = '', root: 'platform', style: default_stylesheet(), path: '.', debug: false) ⇒ DepVizDoc
Returns a new instance of DepVizDoc.
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/depvizdoc.rb', line 28 def initialize(s='', root: 'platform', style: default_stylesheet(), path: '.', debug: false) @style, @root, @debug, @path = style, root, debug, path @header = " <?polyrex schema='items[type]/item[label, url]' delimiter =' # '?> type: digraph " build(s) end |
Instance Method Details
#build(s) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/depvizdoc.rb', line 40 def build(s) return if s.empty? lines = s.lines lines.shift if lines.first =~ /^<\?depvizdoc\b/ puts 'DepVizDoc::initialize before DependencyBuilder' if @debug @s = tree = DependencyBuilder.new(lines.join).to_s puts 'master @s: ' + @s.inspect if @debug puts 'DepVizDoc::initialize after DependencyBuilder' if @debug s2 = tree.lines.map do |line| x = line.chomp "%s # %s.html" % [x, x[/\w+$/]] end.join("\n") s = @root ? (@root + "\n" + s2.lines.map {|x| ' ' + x}.join) : s2 puts 'DepVizDoc::initialize before PxGraphViz' if @debug @pxg = PxGraphViz.new(@header + s, style: @style) puts 'DepVizDoc::initialize after PxGraphViz' if @debug end |
#render(path = @path) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/depvizdoc.rb', line 68 def render(path=@path) # generate each HTML file items = @s.lines.flatten.map {|x| x.chomp.lstrip }.uniq FileUtils.mkdir_p File.join(path, 'svg') items.each do |name| puts 'DepVizDoc::initialize name: ' + name.inspect if @debug # generate the dependency chart File.write File.join(path, 'svg', name + '_dep.svg'), self.item(name).dependencies.to_svg rdep = self.item(name).reverse_dependencies # generate the reverse dependency chart md = " # #{name} ## Dependencies }) ## Reverse dependencies " md << if rdep then File.write File.join(path, 'svg', name + '_rdep.svg'), rdep.to_svg "" % File.join(path, 'svg', name + '_rdep.svg') else 'none' end html = RDiscount.new(Martile.new(md).to_s).to_html File.write File.join(path, name + '.html'), html end filepath = File.join(path, 'chart.svg') File.write filepath, self.to_svg 'saved to ' + filepath end |