def run(self): if pygal is None: msg = ( "ERROR: " "To use the Chart directive you need to install " "the pygal module.\n" ) utils.show_msg(msg) return [nodes.raw('', '<div class="text-error">{0}</div>'.format(msg), format='html')] options = {} if 'style' in self.options: style_name = self.options.pop('style') else: style_name = 'DefaultStyle' if '(' in style_name: # Parametric style style = eval('pygal.style.' + style_name) else: style = getattr(pygal.style, style_name) for k, v in self.options.items(): options[k] = literal_eval(v) chart = getattr(pygal, self.arguments[0])(style=style) chart.config(**options) for line in self.content: label, series = literal_eval('({0})'.format(line)) chart.add(label, series) return [nodes.raw('', chart.render().decode('utf8'), format='html')]
def run(self): if pygal is None: msg = ("ERROR: " "To use the Chart directive you need to install " "the pygal module.\n") utils.show_msg(msg) return [ nodes.raw('', '<div class="text-error">{0}</div>'.format(msg), format='html') ] options = {} if 'style' in self.options: style_name = self.options.pop('style') else: style_name = 'DefaultStyle' if '(' in style_name: # Parametric style style = eval('pygal.style.' + style_name) else: style = getattr(pygal.style, style_name) for k, v in self.options.items(): options[k] = literal_eval(v) chart = getattr(pygal, self.arguments[0])(style=style) chart.config(**options) for line in self.content: label, series = literal_eval('({0})'.format(line)) chart.add(label, series) return [nodes.raw('', chart.render().decode('utf8'), format='html')]
def run(self): if requests is None: msg = ('ERROR:' 'To use the gist directive, you need to install the ' '"requests" package.\n') utils.show_msg(msg) return [ nodes.raw('', '<div class="text-error">{0}</div>'.format(msg), format='html') ] gistID = self.arguments[0].strip() embedHTML = "" rawGist = "" if 'file' in self.options: filename = self.options['file'] rawGist = (self.get_raw_gist_with_filename(gistID, filename)) embedHTML = ('<script src="https://gist.github.com/{0}.js' '?file={1}"></script>').format(gistID, filename) else: rawGist = (self.get_raw_gist(gistID)) embedHTML = ('<script src="https://gist.github.com/{0}.js">' '</script>').format(gistID) return [ nodes.raw('', embedHTML, format='html'), nodes.raw('', '<noscript>', format='html'), nodes.literal_block('', rawGist), nodes.raw('', '</noscript>', format='html') ]
def run(self): if requests is None: msg = ( 'ERROR:' 'To use the gist directive, you need to install the ' '"requests" package.\n' ) utils.show_msg(msg) return [nodes.raw('', '<div class="text-error">{0}</div>'.format(msg), format='html')] gistID = self.arguments[0].strip() embedHTML = "" rawGist = "" if 'file' in self.options: filename = self.options['file'] rawGist = (self.get_raw_gist_with_filename(gistID, filename)) embedHTML = ('<script src="https://gist.github.com/{0}.js' '?file={1}"></script>').format(gistID, filename) else: rawGist = (self.get_raw_gist(gistID)) embedHTML = ('<script src="https://gist.github.com/{0}.js">' '</script>').format(gistID) return [nodes.raw('', embedHTML, format='html'), nodes.raw('', '<noscript>', format='html'), nodes.literal_block('', rawGist), nodes.raw('', '</noscript>', format='html')]
def check_modules(self): if requests is None: msg = ( "Error: " "To use the Vimeo directive you need to install " "the requests module.\n" ) utils.show_msg(msg) return [nodes.raw('', '<div class="text-error">{0}</div>'.format(msg), format='html')] return None
def check_modules(self): if requests is None: msg = ("Error: " "To use the Vimeo directive you need to install " "the requests module.\n") utils.show_msg(msg) return [ nodes.raw('', '<div class="text-error">{0}</div>'.format(msg), format='html') ] return None
def run(self): if micawber is None: msg = ( "Error: " "To use the media directive you need to install " "the micawber module." ) utils.show_msg(msg) return [nodes.raw('', '<div class="text-error">{0}</div>'.format(msg), format='html')] providers = micawber.bootstrap_basic() return [nodes.raw('', micawber.parse_text(" ".join(self.arguments), providers), format='html')]
def run(self): if micawber is None: msg = ("Error: " "To use the media directive you need to install " "the micawber module.") utils.show_msg(msg) return [ nodes.raw('', '<div class="text-error">{0}</div>'.format(msg), format='html') ] providers = micawber.bootstrap_basic() return [ nodes.raw('', micawber.parse_text(" ".join(self.arguments), providers), format='html') ]
def resize_image(self, src, dst, max_size): """Make a copy of the image in the requested size.""" if not Image: utils.copy_file(src, dst) return im = Image.open(src) w, h = im.size if w > max_size or h > max_size: size = max_size, max_size # Panoramas get larger thumbnails because they look *awful* if w > 2 * h: size = min(w, max_size * 4), min(w, max_size * 4) try: exif = im._getexif() except Exception: exif = None if exif is not None: for tag, value in list(exif.items()): decoded = ExifTags.TAGS.get(tag, tag) if decoded == 'Orientation': if value == 3: im = im.rotate(180) elif value == 6: im = im.rotate(270) elif value == 8: im = im.rotate(90) break try: im.thumbnail(size, Image.ANTIALIAS) except Exception: utils.show_msg("WARNING: can't thumbnail {0}".format(src)) pass else: im.save(dst) else: utils.copy_file(src, dst)