Mercurial > hg > decoupage
changeset 31:89a72b2fd149
merge from head
author | egj@socialplanning.org |
---|---|
date | Tue, 02 Feb 2010 18:04:02 +0000 |
parents | 81607129a45e (current diff) ffd661a0f169 (diff) |
children | 527ccb76d043 |
files | decoupage/web.py |
diffstat | 4 files changed, 79 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/README.txt Tue Feb 02 18:02:27 2010 +0000 +++ b/README.txt Tue Feb 02 18:04:02 2010 +0000 @@ -63,16 +63,46 @@ at [decoupage.formatters]). For example: /include = site.html could include the site.html genshi template at the top of the body. +Formatters: + +sort: + determines how to sort the files in a directory; + right now only by case-insensitive alphabetically + * reverse : reverse the order of the sorting + all: only pass files of a certain pattern; the inverse of ignore calling all with no arguments means only files with descriptions are used -title: splits a description into a title and a description with a -separator -describe: substitute the description for the filename -ignore: ignore files of a certain pattern +title: + splits a description into a title and a description via a + separator in + the description. The template will now have an additional + variable, + 'title', per file + Arguments: + * separator: what separator to use (':' by default) + +describe: + obtain the description from the filename + the file extension (if any) will be dropped and + spaces will be substituted for underscores + +ignore: + ignore files of a glob patterns. + These files will not be linked to in the template. + e.g. /ignore = .* *.pdf # don't list dotfiles and PDFs + include: include a file at the top of the body -css: specify CSS +css: specify CSS used (whitespace separated list) + +Decoupage also makes use of other special intrinsic keywords: +formatters: ordered list of formatters to apply + +inherit: inherit configuration from a certain directory (instead of +the parent + +transform: a list of transformers for contenttransformer
--- a/decoupage/formatters.py Tue Feb 02 18:02:27 2010 +0000 +++ b/decoupage/formatters.py Tue Feb 02 18:04:02 2010 +0000 @@ -36,7 +36,11 @@ ### formatters class Ignore(object): - """ignore files of a certain pattern""" + """ + ignore files of a glob patterns. + These files will not be linked to in the template. + e.g. /ignore = .* *.pdf # don't list dotfiles and PDFs + """ def __init__(self, ignore): @@ -79,7 +83,11 @@ data['files'] = _files class Sort(object): - """ determines how to sort the files in a directory """ + """ + determines how to sort the files in a directory; + right now only by case-insensitive alphabetically + * reverse : reverse the order of the sorting + """ def __init__(self, pattern): self.args = [i.strip() for i in pattern.split(',')] @@ -92,13 +100,19 @@ class FilenameDescription(FormatterBase): - """substitute the description for the filename""" + """ + obtain the description from the filename + the file extension (if any) will be dropped and + spaces will be substituted for underscores + """ + # TODO : deal with CamelCaseFilenames def __call__(self, request, data): for f in data['files']: if f['description'] is None: description = f['name'] - description = description.rsplit('.', 1)[0] + if '.' in description: + description = description.rsplit('.', 1)[0] decription = description.strip('_') if '_' in description: description = ' '.join([i.title() for i in description.split('_')]) @@ -106,8 +120,14 @@ class TitleDescription(FormatterBase): - """splits a description into a title and a description with a separator""" - + """ + splits a description into a title and a description via a separator in + the description. The template will now have an additional variable, + 'title', per file + Arguments: + * separator: what separator to use (':' by default) + """ + # XXX what about setting the page title? defaults = { 'separator': ':' } @@ -122,12 +142,12 @@ f['description'] = None class CSS(object): - """specify CSS""" + """specify CSS used (whitespace separated list)""" def __init__(self, arg): self.css = arg.split() def __call__(self, request, data): - data['stylesheets'] = self.css + data['css'] = self.css class Include(object): """include a file at the top of the body"""
--- a/decoupage/web.py Tue Feb 02 18:02:27 2010 +0000 +++ b/decoupage/web.py Tue Feb 02 18:04:02 2010 +0000 @@ -4,6 +4,7 @@ import os +from contenttransformer.app import FileTypeTransformer from formatters import formatters from genshi.builder import Markup @@ -62,6 +63,8 @@ self.loader = TemplateLoader(self.template_directories, auto_reload=self.auto_reload) + + ### methods dealing with HTTP def __call__(self, environ, start_response): request = Request(environ) @@ -76,15 +79,18 @@ res = self.get(request) return res(environ, start_response) else: - fileserver = self.fileserver(path) + conf = self.conf(request.path_info.rsplit('/',1)[0]) + if '/transformer' in conf: + args = [i.split('=', 1) for i in conf['/transformer'].split(',') if '=' in i] + fileserver = FileTypeTransformer(*args) + else: + fileserver = FileApp + + fileserver = fileserver(path) return fileserver(environ, start_response) else: raise exc.HTTPNotFound() - def get_response(self, text, content_type='text/html'): - """construct a response to a GET request""" - res = Response(content_type=content_type, body=text) - return res def get(self, request): """ @@ -152,7 +158,8 @@ return self.fileserver(local_index) raise - return self.get_response(res) + return Response(content_type='text/html', body=res) + ### internal methods @@ -202,7 +209,7 @@ parent_configuration = self.conf(inherit_directory) for key, value in parent_configuration.items(): if key.startswith('/') and key not in conf: - conf[key] = value + conf[key] = value # cache configuration if not self.auto_reload:
--- a/setup.py Tue Feb 02 18:02:27 2010 +0000 +++ b/setup.py Tue Feb 02 18:04:02 2010 +0000 @@ -6,7 +6,7 @@ except IOError: description = '' -version = '0.4.2' +version = '0.5' setup(name='decoupage', version=version, @@ -27,6 +27,7 @@ 'PasteScript', 'genshi', 'martINI', + 'contenttransformer', ], entry_points=""" # -*- Entry points: -*-