First steps at using jinja2 for qute:log.
This commit is contained in:
parent
9da504c6a0
commit
1dce50309b
@ -1,5 +1,7 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<!-- vim: ft=html fileencoding=utf-8 sts=4 sw=4 et: -->
|
<!--
|
||||||
|
vim: ft=html fileencoding=utf-8 sts=4 sw=4 et:
|
||||||
|
-->
|
||||||
|
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
|
35
qutebrowser/html/log.html
Normal file
35
qutebrowser/html/log.html
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block style %}
|
||||||
|
body {
|
||||||
|
background-color: black;
|
||||||
|
color: white;
|
||||||
|
font-size: 11px;
|
||||||
|
}
|
||||||
|
|
||||||
|
table {
|
||||||
|
border: 1px solid grey;
|
||||||
|
border-collapse: collapse;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre {
|
||||||
|
margin: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
th, td {
|
||||||
|
border: 1px solid grey;
|
||||||
|
padding-left: 5px;
|
||||||
|
padding-right: 5px;
|
||||||
|
}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
{{ super() }}
|
||||||
|
{% if content %}
|
||||||
|
<table>
|
||||||
|
{{ content | safe() }}
|
||||||
|
</table>
|
||||||
|
{% else %}
|
||||||
|
<p>Log output was disabled.</p>
|
||||||
|
{% endif %}
|
||||||
|
{% endblock %}
|
@ -20,12 +20,9 @@
|
|||||||
"""Handler functions for different qute:... pages.
|
"""Handler functions for different qute:... pages.
|
||||||
|
|
||||||
Module attributes:
|
Module attributes:
|
||||||
_HTML_TEMPLATE: The HTML boilerplate used to convert text into html.
|
|
||||||
pyeval_output: The output of the last :pyeval command.
|
pyeval_output: The output of the last :pyeval command.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import html as pyhtml
|
|
||||||
|
|
||||||
from PyQt5.QtNetwork import QNetworkReply
|
from PyQt5.QtNetwork import QNetworkReply
|
||||||
|
|
||||||
import qutebrowser
|
import qutebrowser
|
||||||
@ -34,42 +31,9 @@ from qutebrowser.utils import version, utils, jinja
|
|||||||
from qutebrowser.utils import log as logutils
|
from qutebrowser.utils import log as logutils
|
||||||
|
|
||||||
|
|
||||||
_HTML_TEMPLATE = """
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>{title}</title>
|
|
||||||
{head}
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
{body}
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
pyeval_output = ":pyeval was never called"
|
pyeval_output = ":pyeval was never called"
|
||||||
|
|
||||||
|
|
||||||
def _get_html(title, snippet, head=None):
|
|
||||||
"""Add HTML boilerplate to a html snippet.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
title: The title the page should have.
|
|
||||||
snippet: The html snippet.
|
|
||||||
head: Additional stuff to put in <head>
|
|
||||||
|
|
||||||
Return:
|
|
||||||
HTML content as bytes.
|
|
||||||
"""
|
|
||||||
if head is None:
|
|
||||||
head = ""
|
|
||||||
html = _HTML_TEMPLATE.format(title=title, body=snippet, head=head).encode(
|
|
||||||
'UTF-8', errors='xmlcharrefreplace')
|
|
||||||
return html
|
|
||||||
|
|
||||||
|
|
||||||
class QuteSchemeHandler(schemehandler.SchemeHandler):
|
class QuteSchemeHandler(schemehandler.SchemeHandler):
|
||||||
|
|
||||||
"""Scheme handler for qute: URLs."""
|
"""Scheme handler for qute: URLs."""
|
||||||
@ -136,35 +100,13 @@ class QuteHandlers:
|
|||||||
@classmethod
|
@classmethod
|
||||||
def log(cls):
|
def log(cls):
|
||||||
"""Handler for qute:log. Return HTML content as bytes."""
|
"""Handler for qute:log. Return HTML content as bytes."""
|
||||||
style = """
|
|
||||||
<style type="text/css">
|
|
||||||
body {
|
|
||||||
background-color: black;
|
|
||||||
color: white;
|
|
||||||
font-size: 11px;
|
|
||||||
}
|
|
||||||
|
|
||||||
table {
|
|
||||||
border: 1px solid grey;
|
|
||||||
border-collapse: collapse;
|
|
||||||
}
|
|
||||||
|
|
||||||
pre {
|
|
||||||
margin: 2px;
|
|
||||||
}
|
|
||||||
|
|
||||||
th, td {
|
|
||||||
border: 1px solid grey;
|
|
||||||
padding-left: 5px;
|
|
||||||
padding-right: 5px;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
"""
|
|
||||||
if logutils.ram_handler is None:
|
if logutils.ram_handler is None:
|
||||||
html = "<p>Log output was disabled.</p>"
|
html_log = None
|
||||||
else:
|
else:
|
||||||
html = logutils.ram_handler.dump_log(html=True)
|
html_log = logutils.ram_handler.dump_log(html=True)
|
||||||
return _get_html('log', html, head=style)
|
html = jinja.env.get_template('log.html').render(
|
||||||
|
title='log', content=html_log)
|
||||||
|
return html.encode('UTF-8', errors='xmlcharrefreplace')
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def gpl(cls):
|
def gpl(cls):
|
||||||
|
@ -317,13 +317,12 @@ class RAMHandler(logging.Handler):
|
|||||||
self.data.append(record)
|
self.data.append(record)
|
||||||
|
|
||||||
def dump_log(self, html=False):
|
def dump_log(self, html=False):
|
||||||
"""Dump the complete formatted log data as as string."""
|
"""Dump the complete formatted log data as as string.
|
||||||
if html:
|
|
||||||
fmt = self.html_formatter.format
|
FIXME: We should do all the HTML formatter via jinja2.
|
||||||
lines = ['<table>']
|
"""
|
||||||
else:
|
lines = []
|
||||||
fmt = self.format
|
fmt = self.html_formatter.format if html else self.format
|
||||||
lines = []
|
|
||||||
self.acquire()
|
self.acquire()
|
||||||
try:
|
try:
|
||||||
records = list(self.data)
|
records = list(self.data)
|
||||||
@ -331,8 +330,6 @@ class RAMHandler(logging.Handler):
|
|||||||
self.release()
|
self.release()
|
||||||
for record in records:
|
for record in records:
|
||||||
lines.append(fmt(record))
|
lines.append(fmt(record))
|
||||||
if html:
|
|
||||||
lines.append('</table>')
|
|
||||||
return '\n'.join(lines)
|
return '\n'.join(lines)
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,25 +48,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/> or use
|
|||||||
:open qute:gpl.
|
:open qute:gpl.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
GPL_BOILERPLATE_HTML = """
|
|
||||||
<p>
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <a href="http://www.gnu.org/licenses/">
|
|
||||||
http://www.gnu.org/licenses/</a> or open <a href="qute:gpl">qute:gpl</a>.
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
def _git_str():
|
def _git_str():
|
||||||
"""Try to find out git version.
|
"""Try to find out git version.
|
||||||
|
Loading…
Reference in New Issue
Block a user