PROJECT_DIR = os.path.abspath(os.path.dirname(__file__))

try:
  from werkzeug.debug import tbtools
  from werkzeug.utils import escape
  tbtools.FRAME_HTML = u'''\
  <div class="frame" id="frame-%(id)d">
    <h4>File <a style="color:%(projectfile)s;" href="txmt://open/?url=file://%(filename)s&line=%(lineno)s" class="filename">%(filename)s</a>,
        line <em class="line">%(lineno)s</em>,
        in <code class="function">%(function_name)s</code></h4>
    <pre>%(current_line)s</pre>
  </div>
  '''
  
  def myrender(self):
    return tbtools.FRAME_HTML % {
      'id':       self.id,
      'projectfile':    'firebrick' if self.filename.find(PROJECT_DIR) == 0 else 'inherit',
      'filename':     escape(self.filename),
      'lineno':     self.lineno,
      'function_name':  escape(self.function_name),
      'current_line':   escape(self.current_line.strip())
    }
  
  tbtools.Frame.render = myrender
  
except ImportError:
  pass