Mercurial > hg > decoupage
changeset 34:527ccb76d043
merged some stuff
author | k0s <k0scist@gmail.com> |
---|---|
date | Mon, 08 Feb 2010 11:44:20 -0500 |
parents | e384d4569ac3 (diff) 89a72b2fd149 (current diff) |
children | 20e3d138dc98 |
files | decoupage/formatters.py decoupage/web.py |
diffstat | 4 files changed, 58 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/decoupage/formatters.py Tue Feb 02 18:04:02 2010 +0000 +++ b/decoupage/formatters.py Mon Feb 08 11:44:20 2010 -0500 @@ -15,7 +15,6 @@ defaults = {} # default values for attrs to be set on the instance - def __init__(self, string): args = [ i.strip() for i in string.split(',')] for index, arg in enumerate(args): @@ -41,7 +40,6 @@ These files will not be linked to in the template. e.g. /ignore = .* *.pdf # don't list dotfiles and PDFs """ - def __init__(self, ignore): self.match = ignore.split() @@ -66,7 +64,6 @@ def __init__(self, pattern): self.match = pattern.split() - def __call__(self, request, data): _files = [] @@ -141,6 +138,24 @@ f['title'] = f['description'] f['description'] = None +class Links(FormatterBase): + """ + allow list of links per item: + foo.html = description of foo; [PDF]=foo.pdf; [TXT]=foo.txt + """ + + defaults = { 'separator': ';' } + + def __call__(self, request, data): + for f in data['files']: + if f['description'] and self.separator in f['description']: + f['description'], links = f['description'].split(self.separator, 1) + links = links.split(self.separator) + assert min(['=' in link for link in links]) + links = [ link.split('=', 1) for link in links ] + f['links'] = [ { 'text': text, 'link': link } + for text, link in links ] + class CSS(object): """specify CSS used (whitespace separated list)""" @@ -149,6 +164,22 @@ def __call__(self, request, data): data['css'] = self.css +class JavaScript(object): + """specify JS for the page""" + + def __init__(self, arg): + self.scripts = arg.split() + def __call__(self, request, data): + data['scripts'] = self.scripts + +class Favicon(object): + """specify favicons for the page""" + + def __init__(self, icon): + self.icon = icon + def __call__(self, request, data): + data['icon'] = self.icon + class Include(object): """include a file at the top of the body"""
--- a/decoupage/templates/index.html Tue Feb 02 18:04:02 2010 +0000 +++ b/decoupage/templates/index.html Mon Feb 08 11:44:20 2010 -0500 @@ -6,15 +6,25 @@ xmlns:xi="http://www.w3.org/2001/XInclude"> <head> <title>${title or path}</title> + <link py:if="icon" rel="icon" href="${icon}"/> <link py:for="sheet in css" rel="stylesheet" type="text/css" href="${sheet}"/> + <script py:for="script in scripts" src="${script}"></script> + </head> <body> <xi:include py:if="include" href="${include}"/> - <ul> + <h1 py:if="title">${title}</h1> + <ul id="listing"> <li py:if="request.path_info.strip('/')"><a href="..">..</a></li> <li py:for="f in files"> - <a href="${f['path']}">${f.get('title', f['description']) or f['name']}</a><span py:if="'title' in f and f['description']">: ${f['description']} + <a href="${f['path']}"> + ${f.get('title', f['description']) or f['name']}</a><span py:if="'title' in f and f['description']">: ${f['description']} </span> + <py:if test="'links' in f"> + <span py:for="link in f['links']" class="link"> + <a href="${link['link']}">${link['text']}</a> + </span> + </py:if> </li> </ul> </body>
--- a/decoupage/web.py Tue Feb 02 18:04:02 2010 +0000 +++ b/decoupage/web.py Mon Feb 08 11:44:20 2010 -0500 @@ -1,5 +1,5 @@ """ -decoupage: a view with webob +decoupage: a view with webob to index and serve static content """ import os @@ -104,13 +104,17 @@ # get the configuraton conf = self.conf(path) - # build data dictionary + ### build data dictionary files = self.filedata(path, directory, conf) data = {'path': path, 'files': files, 'request': request } + + # defaults; TODO: make this better data['title'] = conf.get('/title') data['directory'] = directory data['include'] = None data['css'] = () + data['scripts'] = () + data['icon'] = None # apply formatters # XXX this should be cached if not self.auto_reload
--- a/setup.py Tue Feb 02 18:04:02 2010 +0000 +++ b/setup.py Mon Feb 08 11:44:20 2010 -0500 @@ -6,7 +6,7 @@ except IOError: description = '' -version = '0.5' +version = '0.6' setup(name='decoupage', version=version, @@ -41,11 +41,14 @@ [decoupage.formatters] all = decoupage.formatters:All css = decoupage.formatters:CSS + describe = decoupage.formatters:FilenameDescription + icon = decoupage.formatters:Favicon ignore = decoupage.formatters:Ignore include = decoupage.formatters:Include - describe = decoupage.formatters:FilenameDescription + links = decoupage.formatters:Links + scripts = decoupage.formatter:JavaScript + sort = decoupage.formatters:Sort title = decoupage.formatters:TitleDescription - sort = decoupage.formatters:Sort """, )