Module: SequenceDiagramMixin

Defined in:
lib/yard-sd/sequence_diagram_mixin.rb

Instance Method Summary collapse

Instance Method Details

#html_syntax_highlight_sd(source) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/yard-sd/sequence_diagram_mixin.rb', line 10

def html_syntax_highlight_sd(source)
  lines = source.split("\n")
   = lines.take_while {|l| l.start_with?("%")}
  source   = lines[.size..-1].join("\n")

   = {}
  .each do |line|
    if line =~ /^%\s*([^\s=]+)\s*=\s*(.+)$/
      key = $1.to_sym

      case key
      when  :size
        [key] = $2
      end
    end
  end

  begin
    diagram = SequenceDiagram::Diagram.new.parse(source)
    img     = diagram.to_png()

    hash = Digest::SHA1.hexdigest(source)
    name = "images/diagrams/#{hash}.png"
    options[:serializer].serialize(name, img)

    return "<img src='%s' alt='Sequence diagram' />" % url_for(options[:serializer].serialized_path(name))
  rescue SequenceDiagram::ParseError => e
    return "Error: Parsing error: #{h(e.inspect)}"
  rescue => e
    return "Error: #{h([e.message, e.backtrace].inspect)}"
  end
end

#htmlify(*args) ⇒ Object



4
5
6
7
8
# File 'lib/yard-sd/sequence_diagram_mixin.rb', line 4

def htmlify(*args)
  res = super
  res = res.gsub(/<pre class="[^"]+? sd"><code>(.+?)<\/code><\/pre>/m, "\\1")
  res
end