Commit 002d85d5 by Axel Haustant Committed by Timothée Peignier

Allow custom separator with PIPELINE_TEMPLATE_SEPARATOR (fix #206)

parent 4171027e
......@@ -12,6 +12,7 @@ or just made Pipeline more awesome.
* Andreas Cederström <andreas@klydd.se>
* Ara Anjargolian <ara818@gmail.com>
* Arnar Yngvason <arnar@hvitahusid.is>
* Axel Haustant <noirbizarre@gmail.com>
* Balazs Kossovics <balazs.kossovics@e-loue.com>
* Ben Vinegar <ben@benv.ca>
* Brant Young <brant.young@gmail.com>
......
......@@ -167,6 +167,13 @@ Other settings
Defaults to ``"_.template"``
``PIPELINE_TEMPLATE_SEPARATOR``
...............................
Charater chain used by Pipeline as replacement for directory separator.
Defaults to ``"_"``
Embedding fonts and images
==========================
......
......@@ -58,6 +58,14 @@ your own extension via ``PIPELINE_TEMPLATE_EXT`` ::
PIPELINE_TEMPLATE_EXT = '.mustache'
Template separator
..................
Templates identifier are built using a replacement for directory separator,
by default ``_``, but you specify your own sperator via ``PIPELINE_TEMPLATE_SEPARATOR`` ::
PIPELINE_TEMPLATE_SEPARATOR = '/'
Using it with your favorite template library
--------------------------------------------
......@@ -92,6 +100,15 @@ To use it with `Handlebars <http://handlebarsjs.com/>`_, use the following setti
PIPELINE_TEMPLATE_FUNC = 'Handlebars.compile'
PIPELINE_TEMPLATE_NAMESPACE = 'Handlebars.templates'
Ember.js + Handlebars
.....................
To use it with `Ember.js <http://emberjs.com/>`_, use the following settings ::
PIPELINE_TEMPLATE_EXT = '.handlebars'
PIPELINE_TEMPLATE_FUNC = 'Ember.Handlebars.compile'
PIPELINE_TEMPLATE_NAMESPACE = 'window.Ember.TEMPLATES'
PIPELINE_TEMPLATE_SEPARATOR = '/'
Prototype
.........
......
......@@ -117,7 +117,7 @@ class Compressor(object):
name = re.sub(r"^%s[\/\\]?(.*)%s$" % (
re.escape(base), re.escape(settings.PIPELINE_TEMPLATE_EXT)
), r"\1", path)
return re.sub(r"[\/\\]", "_", name)
return re.sub(r"[\/\\]", settings.PIPELINE_TEMPLATE_SEPARATOR, name)
def concatenate_and_rewrite(self, paths, output_filename, variant=None):
"""Concatenate together files and rewrite urls"""
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import sys
from django.conf import settings as _settings
DEFAULTS = {
'DEBUG': False,
'PIPELINE_ENABLED': not _settings.DEBUG,
'PIPELINE_ROOT': _settings.STATIC_ROOT,
'PIPELINE_URL': _settings.STATIC_URL,
'PIPELINE_STORAGE': 'pipeline.storage.PipelineFinderStorage',
'PIPELINE_CSS_COMPRESSOR': 'pipeline.compressors.yuglify.YuglifyCompressor',
'PIPELINE_JS_COMPRESSOR': 'pipeline.compressors.yuglify.YuglifyCompressor',
'PIPELINE_COMPILERS': [],
'PIPELINE_CSS': {},
'PIPELINE_JS': {},
'PIPELINE_TEMPLATE_NAMESPACE': "window.JST",
'PIPELINE_TEMPLATE_EXT': ".jst",
'PIPELINE_TEMPLATE_FUNC': "template",
'PIPELINE_TEMPLATE_SEPARATOR': "_",
'PIPELINE_DISABLE_WRAPPER': False,
'PIPELINE_CSSTIDY_BINARY': '/usr/bin/env csstidy',
'PIPELINE_CSSTIDY_ARGUMENTS': '--template=highest',
'PIPELINE_YUGLIFY_BINARY': '/usr/bin/env yuglify',
'PIPELINE_YUGLIFY_CSS_ARGUMENTS': '--terminal',
'PIPELINE_YUGLIFY_JS_ARGUMENTS': '--terminal',
'PIPELINE_YUI_BINARY': '/usr/bin/env yuicompressor',
'PIPELINE_YUI_CSS_ARGUMENTS': '',
'PIPELINE_YUI_JS_ARGUMENTS': '',
'PIPELINE_CLOSURE_BINARY': '/usr/bin/env closure',
'PIPELINE_CLOSURE_ARGUMENTS': '',
'PIPELINE_UGLIFYJS_BINARY': '/usr/bin/env uglifyjs',
'PIPELINE_UGLIFYJS_ARGUMENTS': '',
'PIPELINE_CSSMIN_BINARY': '/usr/bin/env cssmin',
'PIPELINE_CSSMIN_ARGUMENTS': '',
'PIPELINE_COFFEE_SCRIPT_BINARY': '/usr/bin/env coffee',
'PIPELINE_COFFEE_SCRIPT_ARGUMENTS': '',
'PIPELINE_LIVE_SCRIPT_BINARY': '/usr/bin/env lsc',
'PIPELINE_LIVE_SCRIPT_ARGUMENTS': '',
'PIPELINE_SASS_BINARY': '/usr/bin/env sass',
'PIPELINE_SASS_ARGUMENTS': '--update',
'PIPELINE_STYLUS_BINARY': '/usr/bin/env stylus',
'PIPELINE_STYLUS_ARGUMENTS': '',
'PIPELINE_LESS_BINARY': '/usr/bin/env lessc',
'PIPELINE_LESS_ARGUMENTS': '',
'PIPELINE_MIMETYPES': (
('text/coffeescript', '.coffee'),
('text/less', '.less'),
('text/javascript', '.js'),
('text/x-sass', '.sass'),
('text/x-scss', '.scss')
),
'PIPELINE_EMBED_MAX_IMAGE_SIZE': 32700,
'PIPELINE_EMBED_PATH': r'[/]?embed/',
}
class PipelineSettings(object):
'''
Lazy Django settings wrapper for Django Pipeline
'''
def __init__(self, wrapped_settings):
self.wrapped_settings = wrapped_settings
def __getattr__(self, name):
if hasattr(self.wrapped_settings, name):
return getattr(self.wrapped_settings, name)
elif name in DEFAULTS:
return DEFAULTS[name]
else:
raise AttributeError("'%s' setting not found" % name)
settings = PipelineSettings(_settings)
from __future__ import unicode_literals
from django.conf import settings
DEBUG = getattr(settings, 'DEBUG', False)
PIPELINE_ENABLED = getattr(settings, 'PIPELINE_ENABLED', not DEBUG)
PIPELINE_ROOT = getattr(settings, 'PIPELINE_ROOT', settings.STATIC_ROOT)
PIPELINE_URL = getattr(settings, 'PIPELINE_URL', settings.STATIC_URL)
PIPELINE_STORAGE = getattr(settings, 'PIPELINE_STORAGE',
'pipeline.storage.PipelineFinderStorage')
PIPELINE_CSS_COMPRESSOR = getattr(settings, 'PIPELINE_CSS_COMPRESSOR',
'pipeline.compressors.yuglify.YuglifyCompressor')
PIPELINE_JS_COMPRESSOR = getattr(settings, 'PIPELINE_JS_COMPRESSOR',
'pipeline.compressors.yuglify.YuglifyCompressor')
PIPELINE_COMPILERS = getattr(settings, 'PIPELINE_COMPILERS', [])
PIPELINE_CSS = getattr(settings, 'PIPELINE_CSS', {})
PIPELINE_JS = getattr(settings, 'PIPELINE_JS', {})
PIPELINE_TEMPLATE_NAMESPACE = getattr(settings, 'PIPELINE_TEMPLATE_NAMESPACE', "window.JST")
PIPELINE_TEMPLATE_EXT = getattr(settings, 'PIPELINE_TEMPLATE_EXT', ".jst")
PIPELINE_TEMPLATE_FUNC = getattr(settings, 'PIPELINE_TEMPLATE_FUNC', "template")
PIPELINE_DISABLE_WRAPPER = getattr(settings, 'PIPELINE_DISABLE_WRAPPER', False)
PIPELINE_CSSTIDY_BINARY = getattr(settings, 'PIPELINE_CSSTIDY_BINARY', '/usr/bin/env csstidy')
PIPELINE_CSSTIDY_ARGUMENTS = getattr(settings, 'PIPELINE_CSSTIDY_ARGUMENTS', '--template=highest')
PIPELINE_YUGLIFY_BINARY = getattr(settings, 'PIPELINE_YUGLIFY_BINARY', '/usr/bin/env yuglify')
PIPELINE_YUGLIFY_CSS_ARGUMENTS = getattr(settings, 'PIPELINE_YUGLIFY_CSS_ARGUMENTS', '--terminal')
PIPELINE_YUGLIFY_JS_ARGUMENTS = getattr(settings, 'PIPELINE_YUGLIFY_JS_ARGUMENTS', '--terminal')
PIPELINE_YUI_BINARY = getattr(settings, 'PIPELINE_YUI_BINARY', '/usr/bin/env yuicompressor')
PIPELINE_YUI_CSS_ARGUMENTS = getattr(settings, 'PIPELINE_YUI_CSS_ARGUMENTS', '')
PIPELINE_YUI_JS_ARGUMENTS = getattr(settings, 'PIPELINE_YUI_JS_ARGUMENTS', '')
PIPELINE_CLOSURE_BINARY = getattr(settings, 'PIPELINE_CLOSURE_BINARY', '/usr/bin/env closure')
PIPELINE_CLOSURE_ARGUMENTS = getattr(settings, 'PIPELINE_CLOSURE_ARGUMENTS', '')
PIPELINE_UGLIFYJS_BINARY = getattr(settings, 'PIPELINE_UGLIFYJS_BINARY', '/usr/bin/env uglifyjs')
PIPELINE_UGLIFYJS_ARGUMENTS = getattr(settings, 'PIPELINE_UGLIFYJS_ARGUMENTS', '')
PIPELINE_CSSMIN_BINARY = getattr(settings, 'PIPELINE_CSSMIN_BINARY', '/usr/bin/env cssmin')
PIPELINE_CSSMIN_ARGUMENTS = getattr(settings, 'PIPELINE_CSSMIN_ARGUMENTS', '')
PIPELINE_COFFEE_SCRIPT_BINARY = getattr(settings, 'PIPELINE_COFFEE_SCRIPT_BINARY', '/usr/bin/env coffee')
PIPELINE_COFFEE_SCRIPT_ARGUMENTS = getattr(settings, 'PIPELINE_COFFEE_SCRIPT_ARGUMENTS', '')
PIPELINE_LIVE_SCRIPT_BINARY = getattr(settings, 'PIPELINE_LIVE_SCRIPT_BINARY', '/usr/bin/env lsc')
PIPELINE_LIVE_SCRIPT_ARGUMENTS = getattr(settings, 'PIPELINE_LIVE_SCRIPT_ARGUMENTS', '')
PIPELINE_SASS_BINARY = getattr(settings, 'PIPELINE_SASS_BINARY', '/usr/bin/env sass')
PIPELINE_SASS_ARGUMENTS = getattr(settings, 'PIPELINE_SASS_ARGUMENTS', '--update')
PIPELINE_STYLUS_BINARY = getattr(settings, 'PIPELINE_STYLUS_BINARY', '/usr/bin/env stylus')
PIPELINE_STYLUS_ARGUMENTS = getattr(settings, 'PIPELINE_STYLUS_ARGUMENTS', '')
PIPELINE_LESS_BINARY = getattr(settings, 'PIPELINE_LESS_BINARY', '/usr/bin/env lessc')
PIPELINE_LESS_ARGUMENTS = getattr(settings, 'PIPELINE_LESS_ARGUMENTS', '')
PIPELINE_MIMETYPES = getattr(settings, 'PIPELINE_MIMETYPES', (
('text/coffeescript', '.coffee'),
('text/less', '.less'),
('text/javascript', '.js'),
('text/x-sass', '.sass'),
('text/x-scss', '.scss')
))
PIPELINE_EMBED_MAX_IMAGE_SIZE = getattr(settings, 'PIPELINE_EMBED_MAX_IMAGE_SIZE', 32700)
PIPELINE_EMBED_PATH = getattr(settings, 'PIPELINE_EMBED_PATH', r'[/]?embed/')
if PIPELINE_COMPILERS is None:
PIPELINE_COMPILERS = []
......@@ -10,6 +10,7 @@ except ImportError:
from unittest.mock import patch # noqa
from django.test import TestCase
from django.test.utils import override_settings
from pipeline.compressors import Compressor, TEMPLATE_FUNC, \
SubProcessCompressor
......@@ -79,6 +80,17 @@ class CompressorTest(TestCase):
'templates\\')
self.assertEqual(name, 'photo_detail')
@override_settings(PIPELINE_TEMPLATE_SEPARATOR='/')
def test_template_name_separator(self):
name = self.compressor.template_name('templates/photo/detail.jst',
'templates/')
self.assertEqual(name, 'photo/detail')
name = self.compressor.template_name('templates/photo_edit.jst', '')
self.assertEqual(name, 'photo_edit')
name = self.compressor.template_name('templates\photo\detail.jst',
'templates\\')
self.assertEqual(name, 'photo/detail')
def test_compile_templates(self):
templates = self.compressor.compile_templates([_('pipeline/templates/photo/list.jst')])
self.assertEqual(templates, """window.JST = window.JST || {};\n%s\nwindow.JST[\'list\'] = template(\'<div class="photo">\\n <img src="<%%= src %%>" />\\n <div class="caption">\\n <%%= caption %%>\\n </div>\\n</div>\');\n""" % TEMPLATE_FUNC)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment