def handle(self, options, global_options, *args): from uliweb.utils.pyini import Ini from uliweb.utils.common import pkg from uliweb.contrib.template.tags import find from uliweb.contrib.staticfiles import url_for_static from uliweb import json_dumps if not options.dest and not options.app: print 'Error: Please use -d to specify output app' sys.exit(1) app = self.get_application(global_options) if options.app: settings_file = pkg.resource_filename(options.app, 'settings.ini') x = Ini(settings_file) else: x = app.settings if options.dest: filename = pkg.resource_filename(options.dest, '/static/jsmodules.js') else: filename = pkg.resource_filename(options.app, '/static/jsmodules.js') d = {} for name in x.get('TEMPLATE_USE', {}).keys(): s = find(name) m = s[0] + s[1] d[name] = [url_for_static(i) for i in m if not i.startswith('<!--')] print 'jsmodules.js is saved in {} please check'.format(filename) with open(filename, 'wb') as f: f.write('var jsmodules = ') f.write(json_dumps(d))
def get_image_url(self): from uliweb.contrib.upload import get_url from uliweb.contrib.staticfiles import url_for_static if self.image: return get_url(self.image) else: return url_for_static('images/user%dx%d.jpg' % (50, 50))
def assemble(self, links): toplinks = [''] bottomlinks = [''] for _type, result in [('toplinks', toplinks), ('bottomlinks', bottomlinks)]: for x in links[_type]: if isinstance(x, dict): link, media = x['value'], x['media'] else: link, media = x, None if link.endswith('.js'): link = url_for_static(link) result.append('<script type="text/javascript" src="%s"></script>' % link) elif link.endswith('.css'): link = url_for_static(link) if media: result.append('<link rel="stylesheet" type="text/css" href="%s" media="%s"/>' % (link, media)) else: result.append('<link rel="stylesheet" type="text/css" href="%s"/>' % link) elif link.endswith('.less'): link = url_for_static(link) result.append('<link rel="stylesheet/less" href="%s"/>' % link) else: result.append(link) return {'toplinks':'\n'.join(toplinks), 'bottomlinks':'\n'.join(bottomlinks)}
def _clean_collection(self, existlinks): r = {'toplinks':[], 'bottomlinks':[]} links = {} #process links, link could be (order, link) or link for _type in ['toplinks', 'bottomlinks']: t = self.links.get(_type, []) for link in t: #link will also be template string if '{{' in link and '}}' in link: link = template(link, self.env) if link.endswith('.js') or link.endswith('.css'): _link = url_for_static(link) else: _link = link if not link in r[_type] and not _link in existlinks: r[_type].append(link) return r
def handle(self, options, global_options, *args): from uliweb.utils.pyini import Ini from uliweb.utils.common import pkg from uliweb.contrib.template.tags import find from uliweb.contrib.staticfiles import url_for_static from uliweb import json_dumps if not options.dest and not options.app: print('Error: Please use -d to specify output app') sys.exit(1) app = self.get_application(global_options) if options.app: settings_file = pkg.resource_filename(options.app, 'settings.ini') x = Ini(settings_file) else: x = app.settings if options.dest: filename = pkg.resource_filename(options.dest, '/static/jsmodules.js') else: filename = pkg.resource_filename(options.app, '/static/jsmodules.js') d = {} for name in x.get('TEMPLATE_USE', {}).keys(): s = find(name) m = s[0] + s[1] d[name] = [ url_for_static(i) for i in m if not i.startswith('<!--') ] print('jsmodules.js is saved in {} please check'.format(filename)) with open(filename, 'wb') as f: f.write('var jsmodules = ') f.write(json_dumps(d))
def get_default_image_url(self, size=50): from uliweb.contrib.staticfiles import url_for_static return url_for_static('images/user%dx%d.jpg' % (size, size))