Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixes #11. Only looks through STATICFILES_DIRS - research way to get

django to list all staticfiles locations.
  • Loading branch information...
commit 82ff4a6a920bc444757633fe565eefe8d1714703 1 parent b6d6b6b
@jMyles jMyles authored
View
7 README.rst
@@ -64,7 +64,7 @@ renders to
Note that by default compiled files are saved into ``COFFEESCRIPT_CACHE`` folder under your ``STATIC_ROOT`` (or ``MEDIA_ROOT`` if you have no ``STATIC_ROOT`` in your settings).
-You can change this folder name with ``COFFEESCRIPT_OUTPUT_DIR`` setting.
+You can change this folder name with ``COLDBREW_CUP`` setting.
Settings
@@ -73,8 +73,9 @@ Settings
``COFFEESCRIPT_EXECUTABLE``
Path to CoffeeScript compiler executable. Default: ``"coffee"``.
-``COFFEESCRIPT_OUTPUT_DIR``
- Output directory for compiled external scripts. It's relative to ``STATIC_ROOT``. Default: ``"COFFEESCRIPT_CACHE"``.
+``COLDBREW_CUP``
+ The "cup" in which to place the brewed coffee, ie, compiled javascript.
+ This location is relative to ``STATIC_ROOT``. Default: ``"COFFEESCRIPT_CACHE"``.
``COFFEESCRIPT_USE_CACHE``
Whether to use cache for inline scripts. Default: ``True``.
View
32 coldbrew/__init__.py
@@ -1,6 +1,7 @@
from coldbrew.exceptions import ColdBrewCompileError
from coldbrew.cache import get_cache_key, get_hexdigest, get_hashed_mtime
-from . import settings
+from . import settings as coldbrew_settings
+from django.conf import settings as django_settings
import logging
import os
import shlex
@@ -36,4 +37,31 @@ def compile(coffeescript_string):
return True, errors
if out:
- return True, out.decode("utf-8")
+ return True, out.decode("utf-8")
+
+
+def compile_from_path(source_file_path):
+ coffee_string = get_string_from_path(source_file_path)
+ if coffee_string:
+ quiet, compile_result = compile(coffee_string)
+ return quiet, compile_result
+ else:
+ return False, "Coffee String was blank. Weak Coffee don't brew."
+
+def save_compiled_string(compiled_string, filename):
+ if filename.endswith(".coffee"):
+ base_filename = filename[:-7]
+ else:
+ base_filename = filename
+ output_directory = os.path.join(django_settings.STATIC_ROOT,
+ coldbrew_settings.COLDBREW_CUP)
+
+ output_path = os.path.join(output_directory,
+ "%s.js" % base_filename)
+
+ if not os.path.exists(output_directory):
+ os.makedirs(output_directory)
+ compiled_file = open(output_path, "w+")
+ compiled_file.write(compiled_string)
+ compiled_file.close()
+
View
0  coldbrew/management/__init__.py
No changes.
View
0  coldbrew/management/commands/__init__.py
No changes.
View
33 coldbrew/management/commands/collect_coldbrew.py
@@ -0,0 +1,33 @@
+from coldbrew import get_string_from_path, compile_from_path, \
+ settings as coldbrew_settings, save_compiled_string
+from coldbrew.exceptions import ColdBrewCompileError
+from django.conf import settings
+from django.core.management.base import BaseCommand
+import os
+
+class Command(BaseCommand):
+
+ def handle(self, *args, **options):
+ for static_dir in settings.STATICFILES_DIRS:
+ for root, dirs, files in os.walk(static_dir):
+ for f in files:
+ fullpath = os.path.join(root, f)
+
+ try:
+ filename = os.path.split(fullpath)[-1]
+ quiet, compile_result = compile_from_path(fullpath)
+ if not quiet:
+ if filename.endswith(".coffee"):
+ raise ColdBrewCompileError(fullpath, compile_result)
+ else:
+ print "Not compiling %s; doesn't look like coffeescript, didn't end in .coffee" % fullpath
+ continue
+ else:
+ save_compiled_string(compile_result, filename)
+ print "Compiled %s" % fullpath
+ except UnicodeDecodeError:
+ print "Not compiling %s; file is not Unicode" % fullpath
+ continue
+
+
+
View
2  coldbrew/settings.py
@@ -7,7 +7,7 @@
COFFEESCRIPT_USE_CACHE = getattr(settings, "COFFEESCRIPT_USE_CACHE", True)
COFFEESCRIPT_CACHE_TIMEOUT = getattr(settings, "COFFEESCRIPT_CACHE_TIMEOUT", 60 * 60 * 24 * 30) # 30 days
COFFEESCRIPT_MTIME_DELAY = getattr(settings, "COFFEESCRIPT_MTIME_DELAY", 10) # 10 seconds
-COFFEESCRIPT_OUTPUT_DIR = getattr(settings, "COFFEESCRIPT_OUTPUT_DIR", "COFFEESCRIPT_CACHE")
+COLDBREW_CUP = getattr(settings, "COLDBREW_CUP", "COFFEESCRIPT_CACHE")
COLDBREW_FAIL_LOUD = getattr(settings, 'COLDBREW_FAIL_LOUD', settings.DEBUG)
View
7 coldbrew/templatetags/coldbrew.py
@@ -64,13 +64,12 @@ def coffeescript(source_file_path):
output_parent = settings.STATIC_ROOT
else:
output_parent = settings.STATICFILES_DIRS[0]
-
-
- output_directory = os.path.join(output_parent, coldbrew_settings.COFFEESCRIPT_OUTPUT_DIR)
+
+ output_directory = os.path.join(output_parent, coldbrew_settings.COLDBREW_CUP)
output_path = os.path.join(output_directory, "%s-%s.js" % (base_filename, hashed_mtime))
# Now we know to which path we'll write; let's just make the URL.
- url = "%s/%s-%s.js" % (settings.COFFEESCRIPT_OUTPUT_DIR,
+ url = "%s/%s-%s.js" % (settings.COLDBREW_CUP,
base_filename,
hashed_mtime
)
View
2  coldbrew/tests/test_settings.py
@@ -11,7 +11,7 @@
"coldbrew",
)
COFFEESCRIPT_MTIME_DELAY = 2
-COFFEESCRIPT_OUTPUT_DIR = "COFFEESCRIPT_CACHE"
+COLDBREW_CUP = "COFFEESCRIPT_CACHE"
DATABASES={
'default': {
View
4 coldbrew/tests/tests.py
@@ -21,7 +21,7 @@ class CoffeeScriptTestCase(TestCase):
def setUp(self):
output_dir = os.path.join(settings.MEDIA_ROOT,
- settings.COFFEESCRIPT_OUTPUT_DIR)
+ settings.COLDBREW_CUP)
# Remove the output directory if it exists to start from scratch
if os.path.exists(output_dir):
@@ -80,7 +80,7 @@ def test_external_coffeescript(self):
compiled_filename_3))
self.assertEquals(len(os.listdir(compiled_file_dir)), 1)
- @override_settings(COFFEESCRIPT_OUTPUT_DIR="%s/compiled/" % settings.STATIC_ROOT)
+ @override_settings(COLDBREW_CUP="%s/compiled/" % settings.STATIC_ROOT)
def test_compiled_file_already_exists_file_is_not_written_again(self):
template = Template("""
{% load coldbrew %}
Please sign in to comment.
Something went wrong with that request. Please try again.