class Theme(object): """Represents a theme.""" def __init__(self, folder): self.id = path.basename(folder) self.folder = folder self.template_path = path.join(folder, 'templates') with open(path.join(folder, 'theme.ini')) as f: self.config = parse_ini(f) self.name = self.config.get('theme.name', self.id) self.packs = PackManager(path.join(folder, 'static'), self.get_link) for key, value in self.config.iteritems(): if key.startswith('packs.'): self.packs.add_pack(key[6:], value.split()) def open_resource(self, filename): """Opens a resource from the static folder as fd.""" pieces = split_path_safely(filename) if pieces is not None: fn = path.join(self.folder, 'static', *pieces) if path.isfile(fn): return open(fn, 'rb') def get_link(self, filename, ext=None): return url_for('themes.get_resource', theme=self.id, file=filename)
def __init__(self, folder): self.id = path.basename(folder) self.folder = folder self.template_path = path.join(folder, 'templates') with open(path.join(folder, 'theme.ini')) as f: self.config = parse_ini(f) self.name = self.config.get('theme.name', self.id) self.packs = PackManager(path.join(folder, 'static'), self.get_link) for key, value in self.config.iteritems(): if key.startswith('packs.'): self.packs.add_pack(key[6:], value.split())
# -*- coding: utf-8 -*- """ solace.packs ~~~~~~~~~~~~ The packs for static files. :copyright: (c) 2009 by Plurk Inc., see AUTHORS for more details. :license: BSD, see LICENSE for more details. """ import os from webdepcompress import PackManager def _url_for(*args, **kwargs): """Replaces itself on first call with the real URL for. This ugly hack exists because of circular dependencies at startup time. """ global _url_for from solace.application import url_for as _url_for return _url_for(*args, **kwargs) pack_mgr = PackManager(os.path.join(os.path.dirname(__file__), 'static'), lambda fn, ext: _url_for('static', file=fn)) pack_mgr.add_pack('default', ['layout.css', 'badges.css', 'jquery.js', 'babel.js', 'solace.js', 'jquery.form.js', 'jquery.autocomplete.js', 'creole.js'])