Code cleanup

This commit is contained in:
Martin Mahner 2018-06-23 14:31:19 +02:00
parent eb6dcb2b08
commit aef701ec89
12 changed files with 26 additions and 41 deletions

View file

@ -1,4 +1,3 @@
// Global padding across all first level elements // Global padding across all first level elements
@mixin boxPadding($paddingTop: 20px, $paddingBottom: 20px) { @mixin boxPadding($paddingTop: 20px, $paddingBottom: 20px) {
padding: $paddingTop $boxPadding $paddingBottom $boxPadding; padding: $paddingTop $boxPadding $paddingBottom $boxPadding;

View file

@ -1,10 +1,3 @@
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/
// html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video
html, body, p { html, body, p {
margin: 0; margin: 0;
padding: 0; padding: 0;

View file

@ -1,7 +1,3 @@
.snippet-text {
background-color: $bgColor;
}
.snippet-diff { .snippet-diff {
color: $codeTextColor; color: $codeTextColor;
background-color: $codeBgColor; background-color: $codeBgColor;

View file

@ -5,7 +5,6 @@
line-height: 17px; line-height: 17px;
} }
.snippet-form { .snippet-form {
background-color: $bgColor; background-color: $bgColor;
@ -82,4 +81,3 @@
} }
} }
} }

View file

@ -121,7 +121,6 @@ ul#snippetOptions {
} }
} }
.snippet-message { .snippet-message {
@include boxPadding(20px, 0); @include boxPadding(20px, 0);
padding: 8px 20px; padding: 8px 20px;

View file

@ -1,6 +1,3 @@
.history-header { .history-header {
@include boxPadding(15px, 15px); @include boxPadding(15px, 15px);
margin: 0; margin: 0;
@ -32,5 +29,3 @@
@include boxPadding(40px, 40px); @include boxPadding(40px, 40px);
color: $textColor; color: $textColor;
} }

View file

@ -1,3 +1,6 @@
.snippet-text {
background-color: $bgColor;
}
// Generic content pages such as About/404/500 // Generic content pages such as About/404/500
// and base styles for text based lexer. // and base styles for text based lexer.

View file

@ -1,6 +1,7 @@
from django.apps import AppConfig, apps from django.apps import AppConfig, apps
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
class dpasteAppConfig(AppConfig): class dpasteAppConfig(AppConfig):
name = 'dpaste' name = 'dpaste'
verbose_name = 'dpaste' verbose_name = 'dpaste'
@ -11,6 +12,8 @@ class dpasteAppConfig(AppConfig):
SLUG_LENGTH = 4 SLUG_LENGTH = 4
# String. A string of characters which are used to create the random slug. # String. A string of characters which are used to create the random slug.
# This is intentionally missing l and I as they look too similar with
# sans-serif fonts.
SLUG_CHOICES = 'abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ1234567890' SLUG_CHOICES = 'abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ1234567890'
# String. The lexer key that is pre-selected in the dropdown. Note that # String. The lexer key that is pre-selected in the dropdown. Note that
@ -31,7 +34,6 @@ class dpasteAppConfig(AppConfig):
# (3600 * 24 * 30 * 12 * 100, _('100 Years')), # (3600 * 24 * 30 * 12 * 100, _('100 Years')),
# ) # )
# #
# **Infinite snippets** are supported. You can keep snippets forever when # **Infinite snippets** are supported. You can keep snippets forever when
# you set the choice key to ``never``. The management command will ignore # you set the choice key to ``never``. The management command will ignore
# these snippets:: # these snippets::
@ -88,7 +90,6 @@ class dpasteAppConfig(AppConfig):
return 'https://{0}'.format(site.domain) return 'https://{0}'.format(site.domain)
return 'https://dpaste.de' return 'https://dpaste.de'
# Key names of the default text and code lexer. # Key names of the default text and code lexer.
PLAIN_TEXT_SYMBOL = '_text' PLAIN_TEXT_SYMBOL = '_text'
PLAIN_CODE_SYMBOL = '_code' PLAIN_CODE_SYMBOL = '_code'

View file

@ -14,15 +14,6 @@ from pygments.util import ClassNotFound
logger = getLogger(__file__) logger = getLogger(__file__)
config = apps.get_app_config('dpaste') config = apps.get_app_config('dpaste')
class NakedHtmlFormatter(HtmlFormatter):
"""Pygments HTML formatter with no further HTML tags."""
def wrap(self, source, outfile):
return self._wrap_code(source)
def _wrap_code(self, source):
for i, t in source:
yield i, t
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Highlight Code Snippets # Highlight Code Snippets
@ -62,7 +53,6 @@ class PlainTextHighlighter(Highlighter):
return linebreaksbr(code_string) return linebreaksbr(code_string)
class MarkdownHighlighter(PlainTextHighlighter): class MarkdownHighlighter(PlainTextHighlighter):
"""Markdown""" """Markdown"""
extensions = ('tables', 'fenced-code', 'footnotes', 'autolink,', extensions = ('tables', 'fenced-code', 'footnotes', 'autolink,',
@ -101,12 +91,25 @@ class RestructuredTextHighlighter(PlainTextHighlighter):
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
class PlainCodeHighlighter(Highlighter): class NakedHtmlFormatter(HtmlFormatter):
"""Plain Code. No highlighting but Pygments like span tags around each line.""" """Pygments HTML formatter with no further HTML tags."""
def wrap(self, source, outfile):
return self._wrap_code(source)
def _wrap_code(self, source):
for i, t in source:
yield i, t
class PlainCodeHighlighter(Highlighter):
"""
Plain Code. No highlighting but Pygments like span tags around each line.
"""
def highlight(self, code_string, **kwargs): def highlight(self, code_string, **kwargs):
return '\n'.join(['<span class="plain">{}</span>'.format(escape(l) or '&#8203;') return '\n'.join([
for l in code_string.splitlines()]) '<span class="plain">{}</span>'.format(escape(l) or '&#8203;')
for l in code_string.splitlines()
])
class PygmentsHighlighter(Highlighter): class PygmentsHighlighter(Highlighter):

View file

@ -40,9 +40,7 @@
<span class="sep"></span> <span class="sep"></span>
{% blocktrans with snippet.published|timesince as since %}Created {{ since }} ago{% endblocktrans %} {% blocktrans with snippet.published|timesince as since %}Created {{ since }} ago{% endblocktrans %}
</h3> </h3>
{{ snippet.highlight }} {{ snippet.highlight }}
{% empty %} {% empty %}
<p class="history-empty"> <p class="history-empty">
{% trans "No snippets saved. Either all your snippets are expired or your cookie has changed." %}</p> {% trans "No snippets saved. Either all your snippets are expired or your cookie has changed." %}</p>

View file

@ -79,7 +79,6 @@ class HighlightAPITestCase(TestCase):
value = PygmentsHighlighter().highlight(input, 'python') value = PygmentsHighlighter().highlight(input, 'python')
self.assertEqual(value, expected) self.assertEqual(value, expected)
def test_broken_rst_syntax(self): def test_broken_rst_syntax(self):
""" """
rst Syntax thats not valid must not raise an exception (SystemMessage) rst Syntax thats not valid must not raise an exception (SystemMessage)

View file

@ -78,8 +78,8 @@ class SnippetDetailView(SnippetView, DetailView):
snippet = self.get_object() snippet = self.get_object()
# One-Time snippet get deleted if the view count matches our limit # One-Time snippet get deleted if the view count matches our limit
if snippet.expire_type == Snippet.EXPIRE_ONETIME \ if (snippet.expire_type == Snippet.EXPIRE_ONETIME and
and snippet.view_count >= config.ONETIME_LIMIT: snippet.view_count >= config.ONETIME_LIMIT):
snippet.delete() snippet.delete()
raise Http404() raise Http404()
@ -274,5 +274,6 @@ class APIView(View):
def page_not_found(request, exception=None, template_name='dpaste/404.html'): def page_not_found(request, exception=None, template_name='dpaste/404.html'):
return django_page_not_found(request, exception, template_name=template_name) return django_page_not_found(request, exception, template_name=template_name)
def server_error(request, template_name='dpaste/500.html'): def server_error(request, template_name='dpaste/500.html'):
return django_server_error(request, template_name=template_name) # pragma: no cover return django_server_error(request, template_name=template_name) # pragma: no cover