From 1473de0aaa1e066bce853fc78a2ba6473a0c176e Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Fri, 12 May 2017 19:10:08 +0200 Subject: Added fullscreen mode. --- pastepy.py | 34 +++++++++++++++++++++++++++++++++- static/paste.css | 3 ++- templates/full.html | 18 ++++++++++++++++++ templates/view.html | 2 ++ 4 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 templates/full.html 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 – %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 @@ + + + + {{ title }} + + + + + +{% if rendered %} +
+{% endif %} +{{ text }} +{% if rendered %} +
+{% endif %} + + 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 @@ {% if rendered %} -- cgit v1.2.3