Skip to content
Browse files

Merge pull request #1 from vorushin/master

Use STATIC_ROOT / STATIC_URL settings when possible instead of MEDIA_ROOT / MEDIA_URL
  • Loading branch information...
2 parents 2db1b66 + 90d4ec3 commit 482cca67d9f4f101c1c5d21295f4819d07c97294 @andreyfedoseev andreyfedoseev committed Jul 28, 2011
Showing with 23 additions and 18 deletions.
  1. +14 −14 README.rst
  2. +8 −3 coffeescript/templatetags/coffeescript.py
  3. +1 −1 coffeescript/tests/django_settings.py
View
28 README.rst
@@ -8,7 +8,7 @@ Installation
************
1. Add ``"coffeescript"`` to ``INSTALLED_APPS`` setting.
-2. Make sure that you have ``coffee`` executable installed. See
+2. Make sure that you have ``coffee`` executable installed. See
`CoffeeScript official site <http://jashkenas.github.com/coffee-script/>`_ for details.
3. Optionally, you can specify the full path to ``coffee`` executable with ``COFFEESCRIPT_EXECUTABLE`` setting.
By default it's set to ``coffee``.
@@ -22,22 +22,22 @@ Inline
::
{% load coffeescript %}
-
+
<script type="text/javascript">
{% inlinecoffeescript %}
console.log "Hello, World!"
- {% endinlinecoffeescript %}
+ {% endinlinecoffeescript %}
</script>
renders to
-::
+::
- <script type="text/javascript">
+ <script type="text/javascript">
(function() {
console.log("Hello, World!");
}).call(this);
-
+
</script>
External file
@@ -46,11 +46,11 @@ External file
::
{% load coffeescript %}
-
+
<script type="text/javascript"
- src="{{ MEDIA_URL}}{% coffeescript "path/to/script.coffee" %}">
+ src="{{ STATIC_URL}}{% coffeescript "path/to/script.coffee" %}">
</script>
-
+
renders to
::
@@ -59,7 +59,7 @@ renders to
src="/media/COFFEESCRIPT_CACHE/path/to/script-91ce1f66f583.js">
</script>
-Note that by default compiled files are saved into ``COFFEESCRIPT_CACHE`` folder under your ``MEDIA_ROOT``.
+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.
@@ -70,13 +70,13 @@ Settings
Path to CoffeeScript compiler executable. Default: ``"coffee"``.
``COFFEESCRIPT_OUTPUT_DIR``
- Output directory for compiled external scripts. It's relative to ``MEDIA_ROOT``. Default: ``"COFFEESCRIPT_CACHE"``.
-
+ Output directory for compiled external scripts. It's relative to ``STATIC_ROOT``. Default: ``"COFFEESCRIPT_CACHE"``.
+
``COFFEESCRIPT_USE_CACHE``
Whether to use cache for inline scripts. Default: ``True``.
-
+
``COFFEESCRIPT_CACHE_TIMEOUT``
Cache timeout for inline scripts (in seconds). Default: 30 days.
-
+
``COFFEESCRIPT_MTIME_DELAY``
Cache timeout for reading the modification time of external scripts (in seconds). Default: 10 seconds.
View
11 coffeescript/templatetags/coffeescript.py
@@ -54,10 +54,15 @@ def do_inlinecoffeescript(parser, token):
@register.simple_tag
def coffeescript(path):
- full_path = os.path.join(settings.MEDIA_ROOT, path)
+ try:
+ STATIC_ROOT = settings.STATIC_ROOT
+ except AttributeError:
+ STATIC_ROOT = settings.MEDIA_ROOT
+
+ full_path = os.path.join(STATIC_ROOT, path)
filename = os.path.split(path)[-1]
- output_directory = os.path.join(settings.MEDIA_ROOT, COFFEESCRIPT_OUTPUT_DIR, os.path.dirname(path))
+ output_directory = os.path.join(STATIC_ROOT, COFFEESCRIPT_OUTPUT_DIR, os.path.dirname(path))
hashed_mtime = get_hashed_mtime(full_path)
@@ -89,4 +94,4 @@ def coffeescript(path):
if filename.startswith(base_filename) and filename != compiled_filename:
os.remove(os.path.join(output_directory, filename))
- return output_path[len(settings.MEDIA_ROOT):].lstrip("/")
+ return output_path[len(STATIC_ROOT):].lstrip("/")
View
2 coffeescript/tests/django_settings.py
@@ -7,4 +7,4 @@
"coffeescript",
)
COFFEESCRIPT_MTIME_DELAY = 2
-COFFEESCRIPT_OUTPUT_DIR = "COFFEESCRIPT_CACHE"
+COFFEESCRIPT_OUTPUT_DIR = "COFFEESCRIPT_CACHE"

0 comments on commit 482cca6

Please sign in to comment.
Something went wrong with that request. Please try again.