summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTyler Mandry <tmandry@gmail.com>2013-03-14 22:38:47 -0500
committerTyler Mandry <tmandry@gmail.com>2013-03-16 01:30:21 -0500
commit050b65ab3b0f1914772e382678df978c6426888f (patch)
tree5bd4ecdc6c1eaed52db1c9014040ff5be1ba00c2
parentdcb2cf752a24ef78899bdcef65962c93cda40855 (diff)
downloadaskbot-050b65ab3b0f1914772e382678df978c6426888f.tar.gz
askbot-050b65ab3b0f1914772e382678df978c6426888f.tar.bz2
askbot-050b65ab3b0f1914772e382678df978c6426888f.zip
Add django_compressor to compress CSS, JS and automatically compile LESS
-rw-r--r--askbot/setup_templates/settings.py15
-rw-r--r--askbot/skins/loaders.py6
-rw-r--r--askbot/templates/base.html11
-rw-r--r--askbot/templates/meta/html_head_javascript.html9
-rw-r--r--askbot/templates/meta/html_head_stylesheets.html3
-rw-r--r--askbot_requirements_dev.txt2
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 '<link href="%s" rel="%s" type="text/css" />' % (url, rel)
+ return '<link href="%s" rel="%s" type="text/less" />' % (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 %}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
@@ -12,18 +13,20 @@
{% endif %}
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<link rel="shortcut icon" href="{{ settings.SITE_FAVICON|media }}" />
- <link
+ <link
rel="alternate"
type="application/rss+xml"
title="{% trans site_title=settings.APP_SHORT_NAME %}RSS feed from {{ site_title }}{% endtrans %}"
href="{{ settings.APP_URL }}{% url "latest_questions_feed" %}"
/>
+ {% 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 %}
<script type="text/javascript" src="{{"/js/modernizr.custom.js"|media }}"></script>
-<script type="text/javascript" src="{% url django.views.i18n.javascript_catalog %}"></script>
<script type="text/javascript">
var askbot = {};
askbot['data'] = {};
@@ -7,11 +8,11 @@
askbot['data']['userIsAuthenticated'] = true;
askbot['data']['userId'] = {{request.user.id}};
askbot['data']['userName'] = '{{ request.user.username }}';
- askbot['data']['userIsAdminOrMod'] = {% if
+ askbot['data']['userIsAdminOrMod'] = {% if
request.user.is_administrator()
or request.user.is_moderator()
%}true{% else %}false{% endif %};
- askbot['data']['userIsAdmin'] = {% if
+ askbot['data']['userIsAdmin'] = {% if
request.user.is_administrator()
%}true{% else %}false{% endif %};
askbot['data']['userReputation'] = {{request.user.reputation}};
@@ -32,4 +33,6 @@
{% endif %}
askbot['messages'] = {};
</script>
+{% endcompress %}
+<script type="text/javascript" src="{% url django.views.i18n.javascript_catalog %}"></script>
{# 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 @@
<link href="{{'/bootstrap/css/bootstrap.css'|media}}" rel="stylesheet" type="text/css" />
{% endif %}
{% if settings.ASKBOT_CSS_DEVEL == False %}
-
-<link href="{{"/style/style.css"|media }}" rel="stylesheet" type="text/css" />
+<link href="{{"/style/style.less"|media }}" rel="stylesheet" type="text/less" />
{{ skin.get_extra_css_link() }}
{% else %}
<link href="{{"/style/style.less"|media }}" rel="stylesheet/less" type="text/css" />
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