Total Pageviews

Sunday, 1 June 2014

django模板标签-Cleverstyle

A set of django template tags for using clevercss code instead of css.

These templatetags can be used in your Django applications to load stylesheets and css code based on the awesome clevercss python module.
There is a similar project http://code.google.com/p/django-clevercss/ which allows you store your clevercss code in the db and call it from the templates.
I used the file extension .pcss for no other reason than it's easy to identify. A .pcss file is a file written in clevercss code which will be used to generate css files and code. You can separate your styles by writing multiple .pcss files and merging them into one css file inside your templates.
The default setup assumes both the css and pcss dir are subdirectories of the same directory (i.e. they're siblings) and will look for .pcss files in MEDIA_ROOT/pcss, convert them and save them to MEDIA_ROOT/css under the same filename.
I don't know how taxing this could be in a production environment. I generally use this module during the development phase and then use the {% stylelink 'my_merged_css_file' %} template tag (included in this package) or hard link to the previously generated merged css file once going live.

Settings

In your application settings you can set the following.
  • CLEVERSTYLE_BASE_DIR - Default: ''
    • The base directory in relation to MEDIA_ROOT. The css and pcss directories should be subdirectories of this.
  • CLEVERSTYLE_PCSS_DIR - Default: 'pcss'
    • The directory which holds the .pcss files in relation to settings.CLEVERSTYLE_BASE_DIR.
  • CLEVERSTYLE_CSS_DIR - Default: 'css'
    • The directory which will hold the generated .css files in relation to settings.CLEVERSTYLE_BASE_DIR.
Add cleverstyle to your installed apps
INSTALLED_APPS=(
        'django.contrib.sessions',
        'django.contrib.sites',
        'cleverstyle',
)
 
from http://code.google.com/p/cleverstyle/