diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2011-02-01 20:01:14 -0500 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2011-02-01 20:01:14 -0500 |
commit | dcdea76efd616888609f0958b79238ec9e16ae63 (patch) | |
tree | 776e89b9613be96b854bd9cc6f9ed54a5301f5f0 | |
parent | 13fc6f1be7473637ea63c0c49b9d431fa35444f2 (diff) | |
download | askbot-dcdea76efd616888609f0958b79238ec9e16ae63.tar.gz askbot-dcdea76efd616888609f0958b79238ec9e16ae63.tar.bz2 askbot-dcdea76efd616888609f0958b79238ec9e16ae63.zip |
added ability to add extra.css file to the media collection
-rw-r--r-- | askbot/context.py | 2 | ||||
-rw-r--r-- | askbot/setup_templates/settings.py | 2 | ||||
-rwxr-xr-x | askbot/skins/README | 71 | ||||
-rw-r--r-- | askbot/skins/default/templates/base.html | 1 | ||||
-rw-r--r-- | askbot/skins/loaders.py | 18 | ||||
-rw-r--r-- | askbot/skins/utils.py | 2 |
6 files changed, 83 insertions, 13 deletions
diff --git a/askbot/context.py b/askbot/context.py index 94257f63..f3419abd 100644 --- a/askbot/context.py +++ b/askbot/context.py @@ -6,6 +6,7 @@ from django.conf import settings import askbot from askbot import api from askbot.conf import settings as askbot_settings +from askbot.skins.loaders import get_skin def application_settings(request): """The context processor function""" @@ -16,5 +17,6 @@ def application_settings(request): my_settings['ASKBOT_VERSION'] = askbot.get_version() return { 'settings': my_settings, + 'skin': get_skin(request), 'moderation_items': api.get_info_on_moderation_items(request.user) } diff --git a/askbot/setup_templates/settings.py b/askbot/setup_templates/settings.py index 9b745f81..7cfb1ce2 100644 --- a/askbot/setup_templates/settings.py +++ b/askbot/setup_templates/settings.py @@ -115,7 +115,7 @@ DEFAULT_FILE_STORAGE = 'django.core.files.storage.FileSystemStorage' #TEMPLATE_DIRS = (,) #template have no effect in askbot, use the variable below -#ASKBOT_EXTRA_SKIN_DIRS = (,)#path to your skin collection +#ASKBOT_EXTRA_SKIN_DIR = #path to your private skin collection #take a look here http://askbot.org/en/question/207/ TEMPLATE_CONTEXT_PROCESSORS = ( diff --git a/askbot/skins/README b/askbot/skins/README index 42a6ea25..3fbc8c33 100755 --- a/askbot/skins/README +++ b/askbot/skins/README @@ -1,20 +1,71 @@ -this directory contains available skins +============================= +Customization of Askbot skins +============================= -1) default - default skin with templates +The default skin at the moment is in the development, however +it is already possible to start customizing your site without +incurring much maintenance overhead. -to create a new skin just create another directory under skins/ -and start populating it with the directory structure as in -default/templates - templates must be named the same way +Current status of templates +=========================== +The two busiest templates are - the "main" page and the "question" page, +the main page is more or less complete. "Question" page will be significantly +refactored in the near future. -NO NEED TO CREATE ALL TEMPLATES/MEDIA FILES AT ONCE +How skins work in Askbot +======================== -templates are resolved in the following way: +The skins reside in up to two directories: + +* `askbot/skins` in the source code (contains any stock skins) +* directory pointed to by a ASKBOT_EXTRA_SKINS_DIR in your settings.py + with any other skins + +Currently, the skin is selected by the site administrator in the live settings. +Also, at the moment skin default is special - it serves any resources +absent in other skins. In a way - all other skins inherit from the "default". + +Templates and media are resolved in the following way: * check in skin named as in settings.ASKBOT_DEFAULT_SKIN * then skin named 'default' -media is resolved with one extra option -* settings.ASKBOT_DEFAULT_SKIN -* 'default' +How to customize a skin +======================= + +There are three options: + +* edit custom css via the settings interface - good for small tweaks + (no need to directly log in to the server) +* create a new skin in separate files (need direct access to the server + files, more maintenance overhead) +* directly modify the "default" skin (as in the previous option - need + direct access to the server, less maintenance overhead, some + knowledge of git system is required) + +The first option only allows to modify css and add custom javascript. +The latter two options allow changing the templates as well. + +If you wish to follow the second option, create a directory named the same +way as the skin you are building and start adding files with the same names +and relative locations as those in the "default" skin. + +NO NEED TO CREATE ALL TEMPLATES/MEDIA FILES AT ONCE as your skin will inherit +pieces from the "default". + +The disadvantage of thil second approach is that you will be on your own maintaining +the synchrony of your template, stylesheet and the core code. + +Third approach is the best, but it requires (the most basic) use of +git source code management software. With git you will easily merge the updates +from the development repository. + +Structure of the skin directories +================================= +Todo. + +To simplify maintenance of the css as the skin is being developed, +populate css file `media/style/extra.css` with any rules that will +override those in the `media/style/style.css` file. If you do that media does not have to be composed of files named the same way as in default skin whatever media you link to from your templates - will be in operation diff --git a/askbot/skins/default/templates/base.html b/askbot/skins/default/templates/base.html index a1575646..3e810103 100644 --- a/askbot/skins/default/templates/base.html +++ b/askbot/skins/default/templates/base.html @@ -14,6 +14,7 @@ {% endif %} <link rel="shortcut icon" href="{{ "/images/favicon.gif"|media }}" /> <link href="{{"/style/style.css"|media }}" rel="stylesheet" type="text/css" /> + {{ skin.get_extra_css_link() }} {% if settings.USE_CUSTOM_CSS %} <link href="{% url "custom_css" %}?v={{settings.MEDIA_RESOURCE_REVISION}}" diff --git a/askbot/skins/loaders.py b/askbot/skins/loaders.py index c9a1a059..b6b4755a 100644 --- a/askbot/skins/loaders.py +++ b/askbot/skins/loaders.py @@ -82,7 +82,6 @@ class SkinEnvironment(CoffinEnvironment): loaders = list() skin_dirs = utils.get_available_skins(selected = self.skin).values() template_dirs = [os.path.join(skin_dir, 'templates') for skin_dir in skin_dirs] - loaders.append(jinja_loaders.FileSystemLoader(template_dirs)) return loaders @@ -94,6 +93,16 @@ class SkinEnvironment(CoffinEnvironment): trans = translation.trans_real.translation(language_code) self.install_gettext_translations(trans) + def get_extra_css_link(self): + """returns either the link tag (to be inserted in the html head element) + or empty string - depending on the existence of file + SKIN_PATH/media/style/extra.css + """ + url = utils.get_media_url('style/extra.css') + if url is not None: + return '<link href="%s" rel="stylesheet" type="text/css" />' % url + return '' + ENV = SkinEnvironment( autoescape=False, extensions=['jinja2.ext.i18n'], @@ -111,6 +120,11 @@ def load_skins(): SKINS = load_skins() +def get_skin(request): + """retreives the skin environment + for a given request (request var is not used at this time)""" + return SKINS[askbot_settings.ASKBOT_DEFAULT_SKIN] + def get_template(template, request): """retreives template for the skin request variable will be used in the future to set @@ -118,7 +132,7 @@ def get_template(template, request): at this point request variable is not used though """ - skin = SKINS[askbot_settings.ASKBOT_DEFAULT_SKIN] + skin = get_skin(request) return skin.get_template(template) def render_into_skin(template, data, request, mimetype = 'text/html'): diff --git a/askbot/skins/utils.py b/askbot/skins/utils.py index a80c85ed..5c9a7a7c 100644 --- a/askbot/skins/utils.py +++ b/askbot/skins/utils.py @@ -88,6 +88,8 @@ def get_media_url(url): askbot_settings.ASKBOT_DEFAULT_SKIN, then 'default', then 'commmon' if file is not found - returns None and logs an error message + + todo: move this to the skin environment class """ #import datetime #before = datetime.datetime.now() |