From 4cb285f1f921016b6b0c008283f59c49dfa0bc85 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Tue, 19 Jun 2012 14:12:03 -0400 Subject: [PATCH] Switch the cms over to using django-pipeline --- cms/envs/common.py | 63 +++++++++++++++++-- cms/models.py | 0 cms/static/sass/.gitignore | 1 + cms/templates/base.html | 6 ++ .../djangoapps/pipeline_mako/__init__.py | 6 +- .../pipeline_mako/templates/mako}/css.html | 0 .../templates/mako}/inline_js.html | 0 .../pipeline_mako/templates/mako}/js.html | 0 .../templates/static_content.html | 0 .../djangoapps}/static_replace.py | 0 lms/envs/common.py | 2 + requirements.txt | 2 +- 12 files changed, 72 insertions(+), 8 deletions(-) delete mode 100644 cms/models.py create mode 100644 cms/static/sass/.gitignore rename lms/lib/pipeline_mako.py => common/djangoapps/pipeline_mako/__init__.py (91%) rename {lms/templates/pipeline_mako => common/djangoapps/pipeline_mako/templates/mako}/css.html (100%) rename {lms/templates/pipeline_mako => common/djangoapps/pipeline_mako/templates/mako}/inline_js.html (100%) rename {lms/templates/pipeline_mako => common/djangoapps/pipeline_mako/templates/mako}/js.html (100%) rename {lms => common/djangoapps/pipeline_mako}/templates/static_content.html (100%) rename {lms/lib => common/djangoapps}/static_replace.py (100%) diff --git a/cms/envs/common.py b/cms/envs/common.py index c3c8ee85a8..20d49b7ac5 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -23,6 +23,12 @@ import sys import tempfile from path import path +############################ FEATURE CONFIGURATION ############################# + +MITX_FEATURES = { + 'USE_DJANGO_PIPELINE': True, +} + ############################# SET PATH INFORMATION ############################# PROJECT_ROOT = path(__file__).abspath().dirname().dirname() # /mitx/cms COMMON_ROOT = PROJECT_ROOT.dirname() / "common" @@ -43,7 +49,10 @@ sys.path.append(COMMON_ROOT / 'lib') # This is where we stick our compiled template files. MAKO_MODULE_DIR = tempfile.mkdtemp('mako') MAKO_TEMPLATES = {} -MAKO_TEMPLATES['main'] = [PROJECT_ROOT / 'templates'] +MAKO_TEMPLATES['main'] = [ + PROJECT_ROOT / 'templates', + COMMON_ROOT / 'djangoapps' / 'pipeline_mako' / 'templates' +] MITX_ROOT_URL = '' @@ -59,8 +68,8 @@ TEMPLATE_CONTEXT_PROCESSORS = ( # List of finder classes that know how to find static files in # various locations. STATICFILES_FINDERS = ( - 'django.contrib.staticfiles.finders.FileSystemFinder', - 'django.contrib.staticfiles.finders.AppDirectoriesFinder', + 'staticfiles.finders.FileSystemFinder', + 'staticfiles.finders.AppDirectoriesFinder', ) # List of callables that know how to import templates from various sources. @@ -132,14 +141,60 @@ USE_L10N = True # Messages MESSAGE_STORAGE = 'django.contrib.messages.storage.session.SessionStorage' +############################### Pipeline ####################################### + +STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage' + +PIPELINE_CSS = { + 'base-style': { + 'source_filenames': ['sass/base-style.scss'], + 'output_filename': 'css/base-style.css', + }, +} + +PIPELINE_ALWAYS_RECOMPILE = ['sass/base-style.scss'] + +PIPELINE_JS = { +} + +PIPELINE_COMPILERS = [ + 'pipeline.compilers.sass.SASSCompiler', + 'pipeline.compilers.coffee.CoffeeScriptCompiler', +] + +PIPELINE_SASS_ARGUMENTS = '-t compressed -r {proj_dir}/static/sass/bourbon/lib/bourbon.rb'.format(proj_dir=PROJECT_ROOT) + +PIPELINE_CSS_COMPRESSOR = None +PIPELINE_JS_COMPRESSOR = 'pipeline.compressors.yui.YUICompressor' + +STATICFILES_IGNORE_PATTERNS = ( + "sass/*", + "coffee/*", + "*.py", + "*.pyc" +) + +PIPELINE_YUI_BINARY = 'yui-compressor' +PIPELINE_SASS_BINARY = 'sass' +PIPELINE_COFFEE_SCRIPT_BINARY = 'coffee' + +# Setting that will only affect the MITx version of django-pipeline until our changes are merged upstream +PIPELINE_COMPILE_INPLACE = True + ############################ APPS ##################################### INSTALLED_APPS = ( + # Standard apps 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', - 'django.contrib.staticfiles', + + # For CMS 'contentstore', + + # For asset pipelining + 'pipeline', + 'staticfiles', ) diff --git a/cms/models.py b/cms/models.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/cms/static/sass/.gitignore b/cms/static/sass/.gitignore new file mode 100644 index 0000000000..b3a5267117 --- /dev/null +++ b/cms/static/sass/.gitignore @@ -0,0 +1 @@ +*.css diff --git a/cms/templates/base.html b/cms/templates/base.html index a23a31d9a5..271f73614d 100644 --- a/cms/templates/base.html +++ b/cms/templates/base.html @@ -1,10 +1,16 @@ +<%namespace name='static' file='static_content.html'/> + + % if settings.MITX_FEATURES['USE_DJANGO_PIPELINE']: + <%static:css group='base-style'/> + % else: + % endif <%block name="title"></%block> diff --git a/lms/lib/pipeline_mako.py b/common/djangoapps/pipeline_mako/__init__.py similarity index 91% rename from lms/lib/pipeline_mako.py rename to common/djangoapps/pipeline_mako/__init__.py index 34e65a63ac..f100d95916 100644 --- a/lms/lib/pipeline_mako.py +++ b/common/djangoapps/pipeline_mako/__init__.py @@ -21,7 +21,7 @@ def compressed_css(package_name): return render_individual_css(package, paths) def render_css(package, path): - template_name = package.template_name or "pipeline_mako/css.html" + template_name = package.template_name or "mako/css.html" context = package.extra_context context.update({ 'type': guess_type(path, 'text/css'), @@ -50,7 +50,7 @@ def compressed_js(package_name): return render_individual_js(package, paths, templates) def render_js(package, path): - template_name = package.template_name or "pipeline_mako/js.html" + template_name = package.template_name or "mako/js.html" context = package.extra_context context.update({ 'type': guess_type(path, 'text/javascript'), @@ -63,7 +63,7 @@ def render_inline_js(package, js): context.update({ 'source': js }) - return render_to_string("pipeline_mako/inline_js.html", context) + return render_to_string("mako/inline_js.html", context) def render_individual_js(package, paths, templates=None): tags = [render_js(package, js) for js in paths] diff --git a/lms/templates/pipeline_mako/css.html b/common/djangoapps/pipeline_mako/templates/mako/css.html similarity index 100% rename from lms/templates/pipeline_mako/css.html rename to common/djangoapps/pipeline_mako/templates/mako/css.html diff --git a/lms/templates/pipeline_mako/inline_js.html b/common/djangoapps/pipeline_mako/templates/mako/inline_js.html similarity index 100% rename from lms/templates/pipeline_mako/inline_js.html rename to common/djangoapps/pipeline_mako/templates/mako/inline_js.html diff --git a/lms/templates/pipeline_mako/js.html b/common/djangoapps/pipeline_mako/templates/mako/js.html similarity index 100% rename from lms/templates/pipeline_mako/js.html rename to common/djangoapps/pipeline_mako/templates/mako/js.html diff --git a/lms/templates/static_content.html b/common/djangoapps/pipeline_mako/templates/static_content.html similarity index 100% rename from lms/templates/static_content.html rename to common/djangoapps/pipeline_mako/templates/static_content.html diff --git a/lms/lib/static_replace.py b/common/djangoapps/static_replace.py similarity index 100% rename from lms/lib/static_replace.py rename to common/djangoapps/static_replace.py diff --git a/lms/envs/common.py b/lms/envs/common.py index d3416f8127..ec2e1f81de 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -73,7 +73,9 @@ MAKO_TEMPLATES['course'] = [DATA_DIR] MAKO_TEMPLATES['sections'] = [DATA_DIR / 'sections'] MAKO_TEMPLATES['custom_tags'] = [DATA_DIR / 'custom_tags'] MAKO_TEMPLATES['main'] = [PROJECT_ROOT / 'templates', + COMMON_ROOT / 'templates', COMMON_ROOT / 'lib' / 'capa' / 'templates', + COMMON_ROOT / 'djangoapps' / 'pipeline_mako' / 'templates', DATA_DIR / 'info', DATA_DIR / 'problems'] diff --git a/requirements.txt b/requirements.txt index 37a30b6cef..2618336630 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,7 +13,7 @@ python-memcached django-celery path.py django_debug_toolbar --e git+git://github.com/MITx/django-pipeline.git@incremental_compile#egg=django-pipeline +-e git+git://github.com/MITx/django-pipeline.git#egg=django-pipeline django-staticfiles>=1.2.1 django-masquerade fs