Switch the cms over to using django-pipeline
This commit is contained in:
committed by
Matthew Mongeau
parent
1898691544
commit
d147638d07
@@ -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']
|
||||
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
from staticfiles.storage import staticfiles_storage
|
||||
|
||||
from mitxmako.shortcuts import render_to_string
|
||||
|
||||
from pipeline.conf import settings
|
||||
from pipeline.packager import Packager
|
||||
from pipeline.utils import guess_type
|
||||
|
||||
def compressed_css(package_name):
|
||||
package = settings.PIPELINE_CSS.get(package_name, {})
|
||||
if package:
|
||||
package = {package_name: package}
|
||||
packager = Packager(css_packages=package, js_packages={})
|
||||
|
||||
package = packager.package_for('css', package_name)
|
||||
|
||||
if settings.PIPELINE:
|
||||
return render_css(package, package.output_filename)
|
||||
else:
|
||||
paths = packager.compile(package.paths)
|
||||
return render_individual_css(package, paths)
|
||||
|
||||
def render_css(package, path):
|
||||
template_name = package.template_name or "pipeline_mako/css.html"
|
||||
context = package.extra_context
|
||||
context.update({
|
||||
'type': guess_type(path, 'text/css'),
|
||||
'url': staticfiles_storage.url(path)
|
||||
})
|
||||
return render_to_string(template_name, context)
|
||||
|
||||
def render_individual_css(package, paths):
|
||||
tags = [render_css(package, path) for path in paths]
|
||||
return '\n'.join(tags)
|
||||
|
||||
|
||||
def compressed_js(package_name):
|
||||
package = settings.PIPELINE_JS.get(package_name, {})
|
||||
if package:
|
||||
package = {package_name: package}
|
||||
packager = Packager(css_packages={}, js_packages=package)
|
||||
|
||||
package = packager.package_for('js', package_name)
|
||||
|
||||
if settings.PIPELINE:
|
||||
return render_js(package, package.output_filename)
|
||||
else:
|
||||
paths = packager.compile(package.paths)
|
||||
templates = packager.pack_templates(package)
|
||||
return render_individual_js(package, paths, templates)
|
||||
|
||||
def render_js(package, path):
|
||||
template_name = package.template_name or "pipeline_mako/js.html"
|
||||
context = package.extra_context
|
||||
context.update({
|
||||
'type': guess_type(path, 'text/javascript'),
|
||||
'url': staticfiles_storage.url(path)
|
||||
})
|
||||
return render_to_string(template_name, context)
|
||||
|
||||
def render_inline_js(package, js):
|
||||
context = package.extra_context
|
||||
context.update({
|
||||
'source': js
|
||||
})
|
||||
return render_to_string("pipeline_mako/inline_js.html", context)
|
||||
|
||||
def render_individual_js(package, paths, templates=None):
|
||||
tags = [render_js(package, js) for js in paths]
|
||||
if templates:
|
||||
tags.append(render_inline_js(package, templates))
|
||||
return '\n'.join(tags)
|
||||
@@ -1,19 +0,0 @@
|
||||
from staticfiles.storage import staticfiles_storage
|
||||
import re
|
||||
|
||||
PREFIX = '/static/'
|
||||
STATIC_PATTERN = re.compile(r"""
|
||||
(?P<quote>['"]) # the opening quotes
|
||||
{prefix} # the prefix
|
||||
(?P<rest>.*?) # everything else in the url
|
||||
(?P=quote) # the first matching closing quote
|
||||
""".format(prefix=PREFIX), re.VERBOSE)
|
||||
PREFIX_LEN = len(PREFIX)
|
||||
|
||||
def replace(static_url):
|
||||
quote = static_url.group('quote')
|
||||
url = staticfiles_storage.url(static_url.group('rest'))
|
||||
return "".join([quote, url, quote])
|
||||
|
||||
def replace_urls(text):
|
||||
return STATIC_PATTERN.sub(replace, text)
|
||||
@@ -1,12 +0,0 @@
|
||||
<link href="${url}" rel="stylesheet" type="${type}" \
|
||||
% if media:
|
||||
media="${media}" \
|
||||
% endif
|
||||
% if title:
|
||||
title="${title}" \
|
||||
% endif
|
||||
% if charset:
|
||||
charset="${charset}" \
|
||||
% endif
|
||||
/>
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
<script \
|
||||
% if async:
|
||||
async \
|
||||
% endif
|
||||
if defer:
|
||||
defer \
|
||||
type="text/javascript" charset="utf-8">
|
||||
${source | safe}
|
||||
</script>
|
||||
@@ -1,8 +0,0 @@
|
||||
<script \
|
||||
% if async:
|
||||
async \
|
||||
% endif
|
||||
% if defer:
|
||||
defer \
|
||||
% endif
|
||||
type="${type}" src="${ url }" charset="utf-8"></script>
|
||||
@@ -1,10 +0,0 @@
|
||||
<%!
|
||||
from staticfiles.storage import staticfiles_storage
|
||||
from pipeline_mako import compressed_css, compressed_js
|
||||
from static_replace import replace_urls
|
||||
%>
|
||||
|
||||
<%def name='url(file)'>${staticfiles_storage.url(file)}</%def>
|
||||
<%def name='css(group)'>${compressed_css(group)}</%def>
|
||||
<%def name='js(group)'>${compressed_js(group)}</%def>
|
||||
<%def name='replace_urls(text)'>${replace_urls(text)}</%def>
|
||||
Reference in New Issue
Block a user