diff options
-rw-r--r-- | pastepy.py | 34 | ||||
-rw-r--r-- | static/paste.css | 3 | ||||
-rw-r--r-- | templates/full.html | 18 | ||||
-rw-r--r-- | templates/view.html | 2 |
4 files changed, 55 insertions, 2 deletions
@@ -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 @@ +<!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> + — + <a href="/full/{{ hash }}">View in fullscreen</a> {% endif %} </div> {% if rendered %} |