Skip to content

Commit

Permalink
Small update to get this working on 1.7+
Browse files Browse the repository at this point in the history
  • Loading branch information
lpomfrey committed Aug 13, 2015
1 parent 6bc8873 commit 5e455e2
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 34 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.eggs/
*.egg
*.egg-info
*.py[co]
Expand Down
4 changes: 4 additions & 0 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
import os
import sys

import django


os.environ['PYTHONPATH'] = os.path.dirname(__file__)
os.environ['DJANGO_SETTINGS_MODULE'] = 'test_project.settings'


def runtests():
if django.VERSION >= (1, 7):
django.setup()
from django.conf import settings
from django.test.utils import get_runner
test_runner = get_runner(settings)()
Expand Down
13 changes: 4 additions & 9 deletions staticpreprocessor/contrib/processors/less.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ class LessProcessor(CommandListProcessor):
output = 'less_styles.css'

def get_command(self, **kwargs):
return 'lessc {compress_string} {yui_compress_string} '\
'{optimization_string} {input} {output}'.format(
compress_string='--compress' if self.compress else '',
yui_compress_string='--yui-compress'
if self.yui_compress else '',
optimization_string='-O{0}'.format(self.optimization)
if self.optimization is not None else '',
**kwargs
)
return 'lessc {compress_string} {input} {output}'.format(
compress_string='--compress' if self.compress else '',
**kwargs
)
10 changes: 4 additions & 6 deletions staticpreprocessor/finders.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
AppDirectoriesFinder as BaseAppDirectoriesFinder
)

from staticpreprocessor.storage import StaticPreprocessorAppStorage
from staticpreprocessor.storage import StaticPreprocessorFileStorage


_finders = SortedDict()
Expand Down Expand Up @@ -63,11 +63,9 @@ def list(self, ignore_patterns):


class AppDirectoriesFinder(BaseAppDirectoriesFinder):
'''
A static files finder that looks in the directory of each app as
specified in the source_dir attribute of the given storage class.
'''
storage_class = StaticPreprocessorAppStorage

storage_class = StaticPreprocessorFileStorage
source_dir = 'rawstatic'


def find(path, all=False): # pragma: no cover
Expand Down
4 changes: 2 additions & 2 deletions staticpreprocessor/management/commands/preprocess_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Command(NoArgsCommand):
'before trying to copy or link the original file.'),
)
help = 'Precompile static files'
requires_model_validation = False
requires_model_validation = True

def __init__(self, *args, **kwargs):
super(NoArgsCommand, self).__init__(*args, **kwargs)
Expand Down Expand Up @@ -157,7 +157,7 @@ def handle_noargs(self, **options):
self.log('Completed pre-processing static files.\n', level=1)
if destination_path:
self.log(
'Results are in{0}'.format(self.destination_display),
'Results are in{0}'.format(destination_display),
level=1
)

Expand Down
7 changes: 0 additions & 7 deletions staticpreprocessor/storage.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.contrib.staticfiles.storage import AppStaticStorage
from django.core.files.storage import FileSystemStorage, get_storage_class
from django.utils.functional import LazyObject



class StaticPreprocessorAppStorage(AppStaticStorage):

source_dir = 'rawstatic'


class StaticPreprocessorFileStorage(FileSystemStorage):

def __init__(self, location=None, base_url=None, *args, **kwargs):
Expand Down
16 changes: 6 additions & 10 deletions staticpreprocessor/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ def test_invalid_dirs_setting(self):
('some-prefix', os.path.join(TEST_PROJECT, 'rawstaticprefixed')),
os.path.join(TEST_PROJECT, 'rawstatic'),
],
STATIC_PREPROCESSOR_ROOT=
os.path.join(TEST_PROJECT, 'processedstatic'),
STATIC_PREPROCESSOR_ROOT=os.path.join(TEST_PROJECT, 'processedstatic'),
STATIC_PREPROCESSOR_FINDERS=[
'staticpreprocessor.finders.FileSystemFinder',
]
Expand Down Expand Up @@ -105,8 +104,7 @@ def test_unprefixed(self):


@override_settings(
STATIC_PREPROCESSOR_ROOT=
os.path.join(TEST_PROJECT, 'processedstatic'),
STATIC_PREPROCESSOR_ROOT=os.path.join(TEST_PROJECT, 'processedstatic'),
STATIC_PREPROCESSOR_FINDERS=[
'staticpreprocessor.finders.AppDirectoriesFinder',
],
Expand Down Expand Up @@ -327,17 +325,15 @@ def test_sass_get_command(self):
)

def test_less_get_command(self):
processor = less.LessProcessor(
compress=True, yui_compress=True, optimization=2)
processor = less.LessProcessor(compress=True)
self.assertEqual(
processor.get_command(input='input', output='output'),
'lessc --silent --compress --yui-compress -O2 input output',
'lessc --compress input output',
)
processor = less.LessProcessor(
compress=False, yui_compress=False, optimization=None)
processor = less.LessProcessor(compress=False)
self.assertEqual(
processor.get_command(input='input2', output='output2'),
'lessc --silent input2 output2',
'lessc input2 output2',
)


Expand Down

0 comments on commit 5e455e2

Please sign in to comment.