estebistec / django-twitter-bootstrap

This package provides a Django app whose static folder contains the sources of Twitter Bootstrap, nothing more and nothing less.
MIT License
64 stars 22 forks source link

Create functions that help build lessc's --include-path option #17

Open estebistec opened 10 years ago

estebistec commented 10 years ago

It might be nice to have some utilities to help build your lessc --include-path option to be used in PIPELINE_LESS_ARGUMENTS.

This originated in #15, and is a follow up to #16 where I will at least document how to do it today.

The follow-on, is that it would be nice if we could simplify the bits of code that we're going to have everybody copy around to achieve this.

FIRST OF ALL, though I'm logging the issue here, I'd like for the result to live in a new project. The stated goal of this project is to be "the sources of Bootstrap, nothing more and nothing less." Therefore, this would be one such helper I don't want to pollute this project up with.

Typically, you want to include static paths from your Django INSTALLED_APPS. The simplest thing to do would be to automatically include all static folders found:

# settings.py
import django_static_utils
PIPELINE_LESS_ARGUMENTS = u'--include-path={}'.format(
    ':'.join(django_static_utils.get_static_paths(INSTALLED_APPS))
)

Now the interesting thing here is that we have to make an assumption about the folder from your apps to include. The safest bet is just the static folder itself. Your less @import relative paths must then agree with this assumption. It's a reasonable default behavior.

However, you may instead want to include a more specific path within all or one specific of your INSTALLED_APPS. For this case we may expose a simple function that helps you build one path from an app:

# settings.py
import django_static_utils
twitter_bootstrap_less = django_static_utils.get_static_path(
    'twitter_bootstrap',  # The name of the INSTALLED_APPS entry
    ['twitter_bootstrap', 'less']  # The path components inside <app-path>/static/
)
PIPELINE_LESS_ARGUMENTS = u'--include-path={}'.format(twitter_bootstrap_less)

This is just a sketch of some ideas so far.