Back to index

moin  1.9.0~rc2
__init__.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003     MoinMoin - static files and serving them
00004 
00005     MoinMoin uses some static files, like css, js, images, applets etc. and
00006     they need to get served somehow.
00007 
00008     How does moin use the static files?
00009     -----------------------------------
00010     Well, in fact, the moin wiki engine code does not access those files at all,
00011     it just emits URLs to those files, so the browser of the wiki user will load
00012     these files by requesting them from these URLs.
00013 
00014     To generate correct URLs to these files, moin uses 2 configuration settings:
00015     url_prefix_static - this the URL moin uses to generate URLs for static files,
00016                         default: '/moin_staticXYZ' for moin version X.Y.Z
00017     url_prefix_local - same thing, but some stuff is required to be on same server
00018                        or the browser will reject it (e.g. FCKeditor javascript).
00019                        So, if you point url_prefix_static to another server, you
00020                        will have to give url_prefix_local with a URL on the same
00021                        server.
00022 
00023     Where are the static files located on your disk?
00024     ------------------------------------------------
00025     You can:
00026     * Just serve our builtin static stuff from STATIC_FILES_PATH (in the moin code
00027       at MoinMoin/web/static/htdocs) - in that case you should not modify the
00028       files or your modifications could be overwritten when you upgrade moin.
00029     * Copy that stuff to somewhere else and modify it THERE and use it from
00030       THERE.
00031 
00032     How to serve those static files?
00033     --------------------------------
00034     * Let moin serve them at <script_root>/moin_staticXYZ (this is the easiest
00035       way, you can optimize it later) and use that by setting:
00036       * for wikis running at root URL (/):
00037         url_prefix_static = '/moin_staticXYZ' # this is the default!
00038       * for wikis running at a non-root URL (like e.g. /mymoin):
00039         from MoinMoin import config
00040         url_prefix_static = '/mymoin' + config.url_prefix_static
00041     * Later, you can serve them with your web server (e.g. apache) - you need to
00042       configure apache to serve the url_prefix_static URL with the files from the
00043       static files path.
00044 
00045     @copyright: 2009 MoinMoin:ThomasWaldmann
00046     @license: GNU GPL, see COPYING for details.
00047 """
00048 
00049 from os.path import join, abspath, dirname, isdir
00050 
00051 from MoinMoin import config
00052 
00053 from werkzeug import SharedDataMiddleware
00054 
00055 STATIC_FILES_PATH = join(abspath(dirname(__file__)), 'htdocs')
00056 
00057 
00058 def make_static_serving_app(application, shared):
00059     """
00060     wrap application in a static file serving app
00061 
00062     @param application: WSGI wiki application that should be wrapped
00063     @param shared:  directory where static files are located (then we create the
00064                     usual mapping dict we need automatically), or a ready-to-use
00065                     mapping dict for SharedDataMiddleware.
00066                     If True, use builtin static files from STATIC_FILES_PATH.
00067     @returns: wrapped WSGI application
00068     """
00069     if not isinstance(shared, dict):
00070         if shared is True:
00071             shared = STATIC_FILES_PATH
00072         if isdir(shared):
00073             shared = {config.url_prefix_static: shared,
00074                       # XXX only works / makes sense for root-mounted wikis:
00075                       '/favicon.ico': join(shared, 'favicon.ico'),
00076                       '/robots.txt': join(shared, 'robots.txt')}
00077         else:
00078             raise ValueError("Invalid path given for shared parameter")
00079     return SharedDataMiddleware(application, shared)
00080