<%inherit file="layout.html" />

<%! from pprint import pformat %>
<%! from smiley.presentation.syntax import syntax %>
<%! from smiley.util import get_variable_changes %>

<%def name="style()">
<link href="css/pygments.css" rel="stylesheet">
<link href="css/run.css" rel="stylesheet">
</%def>

<%def name="vartable(vars, show_none=True)" filter="syntax">
% if vars is None:
% if show_none:
None
% endif
% else:
% for n, v in sorted(vars.items()):
${n} = ${pformat(v, width=20)}
% endfor
% endif
</%def>

<%def name="varchanges(vars)" filter="syntax">
% for n, v in vars:
${n} = ${pformat(v, width=15)}
% endfor
</%def>

<%def name="nextandprev()">
NEXT AND PREV LINKS
</%def>

<%def name="page_link(page, per_page)">
trace-${page}.html
</%def>

<%def name="pagination(page, num_pages, per_page)">
<ul class="pagination">
% if page <= 1:
  <li class="disabled"><a href="${page_link(1, per_page)}">&laquo;</a></li>
% else:
  <li><a href="${page_link(page-1, per_page)}">&laquo;</a></li>
% endif
% for r in page_ranges:
% for p in range(r[0], r[1]+1):
  <li
% if p == page:
 class="active"
% endif
><a href="${page_link(p, per_page)}">${p}</a></li>
% endfor
% if len(page_ranges) > 1 and r != page_ranges[-1]:
    <li class="disabled"><a>...</a></li>
% endif
% endfor
% if page >= num_pages:
  <li class="disabled"><a href="${page_link(num_pages, per_page)}">&raquo;</a></li>
% else:
  <li><a href="${page_link(page+1, per_page)}">&raquo;</a></li>
% endif
</ul>
</%def>

<div class="row">
  <div class="col-md-6">
    ${pagination(page, num_pages, per_page)}
  </div>

  <div id="content" class="col-md-12">
    <table class="table table-striped table-condensed">
      <thead>
        <tr>
          <th>Location</th>
          <th>Event</th>
          <th>Statement</th>
          <th>Data</th>
        </tr>
      </thead>
      <tbody>
<%
older = {}
%>
% for t in trace:
        <tr>
          <td>
            <a href="file-${getfileid(filename=t.filename)}.html">${t.filename|self.display_filename}</a>:
% if t.line_no[0] == t.line_no[1]:
          ${t.line_no[0]}
% else:
          ${t.line_no[0]} - ${t.line_no[1]}
% endif
          </td>


% if t.event == 'call' and t.func_name == '<module>':
          <td>module</td>
% else:
          <td>${t.event}</td>
% endif

          <td class="run-source"><div class="highlight"><pre>${getlines(t.filename, t.line_no)}</pre></div></td>

% if t.event == 'return':
          <td>${pformat(t.trace_arg, width=20) | syntax}</td>
% elif t.event == 'call':
          <td></td>
% elif not t.local_vars:
          <td></td>
% else:
          <td>${varchanges(get_variable_changes(older, t.local_vars))}</td>
<%
older = t.local_vars or {}
%>
% endif

        </tr>
% endfor        
      </tbody>
    </table>

    ${pagination(page, num_pages, per_page)}

  </div>
</div>
