Removed inline tag in favor of a separate app.

This commit is contained in:
Martin Mahner 2018-04-29 17:44:34 +02:00
parent 296c778bbd
commit c685f6a5ac
5 changed files with 7 additions and 59 deletions

View file

@ -117,6 +117,7 @@ TEMPLATES = [
] ]
INSTALLED_APPS = ( INSTALLED_APPS = (
'staticinline',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'django.contrib.sessions', 'django.contrib.sessions',
'dpaste.apps.dpasteAppConfig', 'dpaste.apps.dpasteAppConfig',

View file

@ -1,6 +1,6 @@
{% load i18n %} {% load i18n %}
{% load staticfiles %} {% load staticfiles %}
{% load dpaste_tags %} {% load staticinline %}
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
@ -8,7 +8,7 @@
<title>{% block title %}{% endblock %}</title> <title>{% block title %}{% endblock %}</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/> <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
{% block meta %}<meta name="robots" content="noindex, nofollow"/>{% endblock %} {% block meta %}<meta name="robots" content="noindex, nofollow"/>{% endblock %}
<style type="text/css">{% inlinestatic "dpaste.css" %}</style> <style type="text/css">{% staticinline "dpaste.css" %}</style>
</head> </head>
<body {% block body_type %}{%endblock %}> <body {% block body_type %}{%endblock %}>
@ -25,6 +25,6 @@
<main>{% block page %}{% endblock %}</main> <main>{% block page %}{% endblock %}</main>
<script>{% inlinestatic "dpaste.js" %}</script> <script>{% staticinline "dpaste.js" %}</script>
</body> </body>
</html> </html>

View file

@ -1,54 +0,0 @@
import os
from logging import getLogger
from django.conf import settings
from django.contrib.staticfiles.finders import find
from django.template.defaulttags import register
from django.utils.safestring import mark_safe
from django.contrib.staticfiles.storage import staticfiles_storage
logger = getLogger(__file__)
@register.simple_tag()
def inlinestatic(path):
"""
Similiar to Django's native `static` templatetag, but this includes
the file directly in the template, rather than a link to it.
Example:
<style type="text/css">{% inlinestatic "dpaste.css" %}</style>
<script>{% inlinestatic "dpaste.js" %}</script>
Becomes:
<style type="text/css">body{ color: red; }</style>
<script>alert("Hello World");</script>
Raises a ValueError if the the file does not exist, and
DEBUG is enabled.
:param path: (string) Filename of the file to include.
:return: (string) The included File or an empty string `''` if the
file was not found, and DEBUG is disabled.
"""
# Filename in build/ directory (when in Watch mode)
filename = find(path)
# File in collectstatic target directory (regular deployment)
if not filename:
if staticfiles_storage.exists(path):
filename = staticfiles_storage.path(path)
# If it wasn't found, raise an error if in DEBUG mode.
if not filename or not os.path.exists(filename):
logger.error('Unable to include inline static file "%s", '
'file not found.', filename)
if settings.DEBUG:
raise ValueError('Unable to include inline static file "{0}", '
'file not found.'.format(filename))
return ''
return mark_safe(open(filename).read())

View file

@ -4,12 +4,12 @@ from setuptools import find_packages, setup
long_description = '\n\n'.join(( long_description = '\n\n'.join((
open('README.rst').read(), open('README.rst').read(),
open('CHANGELOG').read() open('CHANGELOG.rst').read()
)) ))
setup( setup(
name='dpaste', name='dpaste',
version='3.0a3', version='3.0a4',
description='dpaste is a Django based pastebin. It\'s intended to run ' description='dpaste is a Django based pastebin. It\'s intended to run '
'separately but its also possible to be installed into an ' 'separately but its also possible to be installed into an '
'existing Django project like a regular app.', 'existing Django project like a regular app.',
@ -36,6 +36,7 @@ setup(
# Essential packages # Essential packages
'django>=1.11', 'django>=1.11',
'pygments>=1.6', 'pygments>=1.6',
'django-staticinline>=1.0',
# Additional Code Lexer # Additional Code Lexer
'pygments-lexer-solidity>=0.1.0', 'pygments-lexer-solidity>=0.1.0',