From 050b65ab3b0f1914772e382678df978c6426888f Mon Sep 17 00:00:00 2001 From: Tyler Mandry Date: Thu, 14 Mar 2013 22:38:47 -0500 Subject: Add django_compressor to compress CSS, JS and automatically compile LESS --- askbot/setup_templates/settings.py | 15 +++++++++++++++ askbot/skins/loaders.py | 6 +++--- askbot/templates/base.html | 11 +++++++---- askbot/templates/meta/html_head_javascript.html | 9 ++++++--- askbot/templates/meta/html_head_stylesheets.html | 3 +-- askbot_requirements_dev.txt | 2 ++ 6 files changed, 34 insertions(+), 12 deletions(-) diff --git a/askbot/setup_templates/settings.py b/askbot/setup_templates/settings.py index 237a1280..ee5f8935 100644 --- a/askbot/setup_templates/settings.py +++ b/askbot/setup_templates/settings.py @@ -116,6 +116,14 @@ MIDDLEWARE_CLASSES = ( 'askbot.middleware.spaceless.SpacelessMiddleware', ) +JINJA2_EXTENSIONS = ( + 'compressor.contrib.jinja2ext.CompressorExtension', +) + +COMPRESS_PRECOMPILERS = ( + ('text/less', 'lessc {infile} {outfile}'), +) + ROOT_URLCONF = os.path.basename(os.path.dirname(__file__)) + '.urls' @@ -176,6 +184,8 @@ INSTALLED_APPS = ( 'followit', 'tinymce', #'avatar',#experimental use git clone git://github.com/ericflo/django-avatar.git$ + + 'compressor', ) @@ -234,6 +244,11 @@ CSRF_COOKIE_NAME = 'askbot_csrf' STATICFILES_DIRS = ( ('default/media', os.path.join(ASKBOT_ROOT, 'media')), ) +STATICFILES_FINDERS = ( + 'django.contrib.staticfiles.finders.FileSystemFinder', + 'django.contrib.staticfiles.finders.AppDirectoriesFinder', + 'compressor.finders.CompressorFinder', +) RECAPTCHA_USE_SSL = True diff --git a/askbot/skins/loaders.py b/askbot/skins/loaders.py index 367433eb..f46f0f07 100644 --- a/askbot/skins/loaders.py +++ b/askbot/skins/loaders.py @@ -57,17 +57,17 @@ class SkinEnvironment(CoffinEnvironment): def get_extra_css_link(self): """returns either the link tag (to be inserted in the html head element) or empty string - depending on the existence of file - SKIN_PATH/media/style/extra.css + SKIN_PATH/media/style/extra.less """ url = None if django_settings.ASKBOT_CSS_DEVEL is True: url = utils.get_media_url('style/extra.less', ignore_missing = True) rel = "stylesheet/less" if url is None: - url = utils.get_media_url('style/extra.css', ignore_missing = True) + url = utils.get_media_url('style/extra.less', ignore_missing = True) rel = "stylesheet" if url is not None: - return '' % (url, rel) + return '' % (url, rel) return '' def load_skins(): diff --git a/askbot/templates/base.html b/askbot/templates/base.html index 6c162057..1e4c5bec 100644 --- a/askbot/templates/base.html +++ b/askbot/templates/base.html @@ -1,3 +1,4 @@ +{% load compress %} @@ -12,18 +13,20 @@ {% endif %} - + {% compress css %} {% block before_css %}{% endblock %} {% include "meta/html_head_stylesheets.html" %} - {% include "meta/fonts.html" %} - {% block forestyle %}{% endblock %} + {% endcompress %} + {% include "meta/fonts.html" %} {# may contain external files #} + {% compress css %}{% block forestyle %}{% endblock %}{% endcompress %} {% include "meta/html_head_javascript.html" %} - {% block forejs %}{% endblock %} + {% compress js %}{% block forejs %}{% endblock %}{% endcompress %} {% if settings.USE_CUSTOM_HTML_HEAD %} {{ settings.CUSTOM_HTML_HEAD }} {% endif %} diff --git a/askbot/templates/meta/html_head_javascript.html b/askbot/templates/meta/html_head_javascript.html index 306f325a..bd5e6ed5 100644 --- a/askbot/templates/meta/html_head_javascript.html +++ b/askbot/templates/meta/html_head_javascript.html @@ -1,5 +1,6 @@ +{% load compress %} +{% compress js %} - +{% endcompress %} + {# avoid adding javascript here so that pages load faster #} diff --git a/askbot/templates/meta/html_head_stylesheets.html b/askbot/templates/meta/html_head_stylesheets.html index cb02f8e5..2a2fb159 100644 --- a/askbot/templates/meta/html_head_stylesheets.html +++ b/askbot/templates/meta/html_head_stylesheets.html @@ -2,8 +2,7 @@ {% endif %} {% if settings.ASKBOT_CSS_DEVEL == False %} - - + {{ skin.get_extra_css_link() }} {% else %} diff --git a/askbot_requirements_dev.txt b/askbot_requirements_dev.txt index 1fbd064c..b88592cf 100644 --- a/askbot_requirements_dev.txt +++ b/askbot_requirements_dev.txt @@ -8,6 +8,8 @@ oauth2 Lamson markdown2 html5lib==0.90 +django-appconf +django-compressor==1.2 django-keyedcache django-threaded-multihost django-robots -- cgit v1.2.3-1-g7c22