Created
July 30, 2011 12:46
-
-
Save pilt/1115489 to your computer and use it in GitHub Desktop.
Incorporating Jammit with Django
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Put this file in core/management/commands/ (or other app of your choice). | |
# -*- coding: utf-8 -*- | |
from subprocess import call | |
from django.core.management.base import BaseCommand, CommandError | |
from django.core.management import call_command | |
class Command(BaseCommand): | |
help = "Collect static files and create assets." | |
def handle(self, **options): | |
call_command('collectstatic', link=True, interactive=False) | |
# staticfiles's finders will not find assets if they are put | |
# in public/assets/ (symlink to static/assets/) directly. This is | |
# also why we override STATICFILES_DIRS in settings.py. | |
call(['jammit', '--output', 'jammit/assets', '--force']) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Put this file in config/ dir. | |
embed_assets: datauri | |
javascript_compressor: closure | |
compress_assets: on | |
# Change javascripts and stylesheets as appropriate. | |
javascripts: | |
workspace: | |
- public/js/jquery-1.*.min.js | |
- public/js/jquery.*.js | |
- public/pinax/**/*.js | |
- public/js/*.js | |
stylesheets: | |
workspace: | |
- public/pinax/**/*.css | |
- public/uni_form/uni-form.css | |
- public/css/*.css |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source "http://rubygems.org" | |
gem "jammit" | |
gem "closure-compiler" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mkdir jammit config | |
# CSS url() paths get broken without this symlink in the current version | |
# of Jammit (0.6.2). This is also why we write public/ instead of static/ | |
# in config/assets.yml. | |
ln -s static public | |
# After all files beneath have been created. | |
bundle install # see Gemfile and read up on Ruby's bundler if you get errors here | |
python managy.py assets | |
# Needed after first run to get workspace.css and .js into static/assets/ dir. | |
python managy.py collectstatic -l | |
# Change templates to include {{STATIC_URL}}assets/workspace-datauri.css | |
# and {{STATIC_URL}}assets/workspace.js. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Relevant settings are listed beneath. | |
import os.path | |
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__)) | |
MEDIA_ROOT = os.path.join(PROJECT_ROOT, "media") | |
MEDIA_URL = "/media/" | |
STATIC_ROOT = os.path.join(PROJECT_ROOT, "static") | |
STATIC_URL = "/static/" | |
STATICFILES_DIRS = [ | |
os.path.join(PROJECT_ROOT, "jammit"), | |
] | |
# Replace "core" with where you put assets.py mgmt command. | |
INSTALLED_APPS += "core" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment