thanhleviet
4/11/2014 - 6:15 AM

Gemfile

source "http://rubygems.org"
gem "jammit"
gem "closure-compiler"
# 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'])
# 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
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.
# 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"