summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2017-05-12 19:10:08 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2017-05-12 19:10:08 +0200
commit1473de0aaa1e066bce853fc78a2ba6473a0c176e (patch)
tree1d6dc1d1dbe7ceaee9fa1637ed41dffea727ca7b
parent5123d1a3b48920db78e5ec638d0b1c6a1d513380 (diff)
Added fullscreen mode.
-rw-r--r--pastepy.py34
-rw-r--r--static/paste.css3
-rw-r--r--templates/full.html18
-rw-r--r--templates/view.html2
4 files changed, 55 insertions, 2 deletions
diff --git a/pastepy.py b/pastepy.py
index 32a2f74..734ba54 100644
--- a/pastepy.py
+++ b/pastepy.py
@@ -225,6 +225,38 @@ class Paste(object):
self.start_response('200 OK', [('Content-Type', 'text/plain; charset=UTF-8')])
return [t2b(paste.text)]
+ def full(self):
+ hash = self.path[1]
+
+ try:
+ session = db.Session()
+ try:
+ cache = session.query(db.Cache).filter_by(paste_hash = hash).one()
+ paste = cache.paste
+ except db.NoResultFound:
+ try:
+ paste = session.query(db.Paste).filter_by(hash = hash).one()
+ except db.NoResultFound:
+ self.start_response('404 Not Found', [])
+ return []
+ try:
+ lexername, text = self.get_formatted(paste.syntax, paste.text)
+ except UnknownSyntaxError:
+ return self.message('Could not find the lexer "%s".' % paste.syntax, 'Error')
+ cache = db.Cache(hash, lexername, text)
+ session.add(cache)
+ session.commit()
+ # Workaround for attribute refresh.
+ paste = cache.paste
+ finally:
+ session.close()
+
+ return self.render_template('full.html', {
+ 'title': '%s &ndash; %s' % (settings.pastebin_name, paste.title or 'Untitled'),
+ 'text': b2t(cache.text),
+ 'rendered': (cache.syntax_name or '').startswith('Rendered '),
+ })
+
def highlight_stylesheet(self):
self.start_response('200 OK', [('Content-Type', 'text/css')])
return [t2b(self.formatter.get_style_defs())]
@@ -243,7 +275,7 @@ class Paste(object):
path = self.environ['PATH_INFO'].split('/')[1:]
module = path[0] or 'paste'
- if module in ('list', 'paste', 'view', 'raw', 'static', 'highlight_stylesheet'):
+ if module in ('list', 'paste', 'view', 'raw', 'full', 'static', 'highlight_stylesheet'):
self.path = path
return getattr(self, module)()
else:
diff --git a/static/paste.css b/static/paste.css
index 941715f..5e59d4d 100644
--- a/static/paste.css
+++ b/static/paste.css
@@ -11,7 +11,8 @@ div#info { font-size: small; color: #bbb; }
span#nick, span#date, span#syntax-type { color: #888; }
div#alt-links { font-size: small; }
div#alt-links a { color: #44f; }
-div.paste-rendered { background-color: #fff; margin-top: 1em; padding: 1em; }
+div.paste-rendered { padding: 1em; }
+div#paste div.paste-rendered { background-color: #fff; margin-top: 1em; }
.highlighttable { width: 100%; padding-top: 1em; }
.highlighttable td.code { width: 100%; background-color: #fff; }
.highlighttable td { vertical-align: top; }
diff --git a/templates/full.html b/templates/full.html
new file mode 100644
index 0000000..dfa0606
--- /dev/null
+++ b/templates/full.html
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <title>{{ title }}</title>
+ <link rel="StyleSheet" href="/highlight_stylesheet" type="text/css">
+ <link rel="StyleSheet" href="/static/paste.css" type="text/css">
+ <script type="text/javascript" src="/static/view.js"></script>
+</head>
+<body>
+{% if rendered %}
+<div class="paste-rendered">
+{% endif %}
+{{ text }}
+{% if rendered %}
+</div>
+{% endif %}
+</body>
+</html>
diff --git a/templates/view.html b/templates/view.html
index 0a20a62..a1d00a7 100644
--- a/templates/view.html
+++ b/templates/view.html
@@ -13,6 +13,8 @@
<div id="alt-links">
{% if hash %}
<a href="/raw/{{ hash }}">Download as plain text</a>
+ &mdash;
+ <a href="/full/{{ hash }}">View in fullscreen</a>
{% endif %}
</div>
{% if rendered %}