Skip to content

Commit

Permalink
Merge pull request #1 from vorushin/master
Browse files Browse the repository at this point in the history
Use STATIC_ROOT / STATIC_URL settings when possible instead of MEDIA_ROOT / MEDIA_URL
  • Loading branch information
Andrey Fedoseev committed Jul 28, 2011
2 parents 2db1b66 + 90d4ec3 commit 482cca6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
28 changes: 14 additions & 14 deletions README.rst
Expand Up @@ -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``.
Expand All @@ -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
Expand All @@ -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

::
Expand All @@ -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.


Expand All @@ -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.
11 changes: 8 additions & 3 deletions coffeescript/templatetags/coffeescript.py
Expand Up @@ -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)

Expand Down Expand Up @@ -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("/")
2 changes: 1 addition & 1 deletion coffeescript/tests/django_settings.py
Expand Up @@ -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.