Class: Codex::GraphvizFilter::GraphViz

Inherits:
Filter
  • Object
show all
Defined in:
lib/codex/filters/graphviz_filter.rb

Instance Attribute Summary

Attributes inherited from Filter

#tag

Instance Method Summary collapse

Methods inherited from Filter

tag

Instance Method Details

#filter_inline(text, args) ⇒ Object



68
69
70
71
72
73
74
75
76
# File 'lib/codex/filters/graphviz_filter.rb', line 68

def filter_inline(text,args)
  d = Descriptor.new(args)
  output_file = "graphviz-" + Digest::MD5.hexdigest(text) + "." + d.file_type
  IO.popen(d.graphviz_cmd(OUTPUT_DIR + output_file),"w") do |pipe|
    pipe.write text
    pipe.close_write
  end
  to_html(d,output_file)
end

#filter_single(args) ⇒ Object



78
79
80
81
82
83
# File 'lib/codex/filters/graphviz_filter.rb', line 78

def filter_single(args)
  d = Descriptor.new(args)
  output_file = File.basename(d.file_name) + "." + d.file_type
  system d.graphviz_cmd(OUTPUT_DIR + output_file)
  to_html(d,output_file)
end

#height_html(desc) ⇒ Object



104
105
106
107
108
109
110
# File 'lib/codex/filters/graphviz_filter.rb', line 104

def height_html(desc)
  if desc.height.nil?
    ""
  else
    %{width="#{desc.height}"}
  end
end

#to_html(d, output_file) ⇒ Object



85
86
87
88
89
90
91
92
93
94
# File 'lib/codex/filters/graphviz_filter.rb', line 85

def to_html(d,output_file)
  if d.file_type == "svg"
    %{<object type="image/svg+xml" name="graphviz" data="#{LINK_DIR + output_file}" #{width_html(d)} #{height_html(d)}">\n} +
    %{If you a seeing this text, your browser probably doesn't support SVG. Try setting the filetype=png option instead.} +
    %{</object>}
  else
    %{<img type="image/#{d.file_type}" name="#{d.file_name}" src="#{output_file}" #{width_html(d)} #{height_html(d)}">\n} +
    %{</img>}
  end
end

#width_html(desc) ⇒ Object



96
97
98
99
100
101
102
# File 'lib/codex/filters/graphviz_filter.rb', line 96

def width_html(desc)
  if desc.width.nil?
    ""
  else
    %{width="#{desc.width}"}
  end
end