class DrawUml::Engine

Attributes

request[RW]
tree[RW]

Private Class Methods

call(env) click to toggle source
# File lib/draw_uml/engine.rb, line 74
def call(env)
  prototype.call(env)
end
prototype() click to toggle source
# File lib/draw_uml/engine.rb, line 70
def prototype
  @prototype ||= new
end

Public Instance Methods

call(env) click to toggle source
# File lib/draw_uml/engine.rb, line 8
def call(env)
  @request = Rack::Request.new(env)
  @tree = DrawUml::Tree.create(DrawUml::Configure.source_path)

  status = 200
  headers = {'Content-Type' => 'text/html'}
  body = ERB.new(DrawUml::Configure.application_template).result(binding)

  [status, headers, [body]]
end

Private Instance Methods

diagram_tag() click to toggle source
# File lib/draw_uml/engine.rb, line 42
def diagram_tag
  render_branch(tree)
end
find_entry(id) click to toggle source
# File lib/draw_uml/engine.rb, line 31
def find_entry(id)
  raw = nil
  tree.each do |entry|
    if entry.id == id
      raw = entry
      break
    end
  end
  raw
end
image_path() click to toggle source
# File lib/draw_uml/engine.rb, line 20
def image_path
  path = nil
  entry = find_entry(request.path_info)
  unless entry.nil?
    diagram = DrawUml::Diagram.new(DrawUml::Configure.dest_path)
    diagram.create(entry.path, entry.id)
    path = File.join(DrawUml::Configure.image_path, entry.id + '.png')
  end
  path
end
render_branch(node) click to toggle source
# File lib/draw_uml/engine.rb, line 46
def render_branch(node)
  raw = ''
  raw += "<div style=\"padding-left: #{node.level}0px;\">\n"
  raw += "<h3 onclick=\"check_branch('#{node.id}')\" >#{node.name}</h3>\n"
  raw += "<div id=#{node.id}>\n"
  arr = []
  node.entries.each do |entry|
    if entry.leaf?
      arr << entry
    else
      raw += render_branch(entry)
    end
  end
  raw += "<ul>" + arr.map do |entry|
    raw = "<li"
    raw += " class='active'"if entry.id == request.path_info
    raw += "><a href=#{request.script_name}#{entry.id}>#{entry.name}</a></li>"
  end.join("\n")
  raw += "</ul></div></div>\n"
  raw
end