def render(self, formatter): """ renders formular """ _ = self._ # checks if initializing of all attributes in __init__ was done if not self.init_settings: return text = """%(mathtran_server)s?;D=%(scale_factor)s;tex=%(formular)s""" % { "mathtran_server": self.mathtran_server, "formular": wikiutil.url_quote(self.raw), "scale_factor": self.scale_factor, } key = cache.key(self.request, itemname=self.pagename, content=text) if not cache.exists(self.request, key) and urllib: # ToDo add a timeout image = urllib.urlopen(text) cache.put(self.request, key, image.read(), content_type="image/png") if cache.exists(self.request, key): credits = """<a href="http://www.mathtran.org/" title="MoinMoin uses the Mathtran Online translation of mathematical content software.">MathTran Powered</a>""" if not credits in self.request.cfg.page_credits: self.request.cfg.page_credits.append(credits) # ToDo show the credits only on pages using the parser extension return formatter.image(src=cache.url(self.request, key), alt=self.raw)
def render(self, formatter): """text to image conversion""" key = 'aafigure_%s' % (cache.key(self.request, itemname=self.pagename, content="%s%s" % (self.raw, self.args)), ) if not cache.exists(self.request, key) or not cache.exists( self.request, key + '_size'): # not in cache, regenerate image options = dict(format='svg') for arg in self.args.split(): try: k, v = arg.split('=', 1) except ValueError: # when splitting fails k = arg v = None if k == 'aspect': options['aspect'] = float(v) elif k == 'scale': options['scale'] = float(v) elif k == 'textual': options['textual'] = True elif k == 'proportional': options['proportional'] = True elif k == 'linewidth': options['linewidth'] = float(v) elif k == 'foreground': options['foreground'] = sanitizte_color(v) elif k == 'fill': options['fill'] = sanitizte_color(v) # no 'background' as SVG backend ignores that # no generic options # XXX unknown options are ignored with no message visitor, output = aafigure.render(self.raw, None, options) cache.put(self.request, key, output.getvalue(), content_type="image/svg+xml") # need to store the size attributes too cache.put(self.request, key + '_size', visitor.get_size_attrs(), content_type="text/plain") # get the information from the cache #~ return formatter.image(src=cache.url(self.request, key), alt=xxx) # XXX this currently only works for HTML, obviously... return formatter.rawHTML( '<object type="image/svg+xml" data="%s" %s></object>' % ( cache.url(self.request, key), cache._get_datafile( self.request, key + '_size').read() # XXX no way to directly read cache? ))
def render(self, formatter): """text to image conversion""" key = 'aafigure_%s' % (cache.key(self.request, itemname=self.pagename, content="%s%s" % (self.raw, self.args)),) if not cache.exists(self.request, key) or not cache.exists(self.request, key+'_size'): # not in cache, regenerate image options = dict(format='svg') for arg in self.args.split(): try: k, v = arg.split('=', 1) except ValueError: # when splitting fails k = arg v = None if k == 'aspect': options['aspect'] = float(v) elif k == 'scale': options['scale'] = float(v) elif k == 'textual': options['textual'] = True elif k == 'proportional': options['proportional'] = True elif k == 'linewidth': options['linewidth'] = float(v) elif k == 'foreground': options['foreground'] = sanitizte_color(v) elif k == 'fill': options['fill'] = sanitizte_color(v) # no 'background' as SVG backend ignores that # no generic options # XXX unknown options are ignored with no message visitor, output = aafigure.render(self.raw, None, options) cache.put(self.request, key, output.getvalue(), content_type="image/svg+xml") # need to store the size attributes too cache.put(self.request, key+'_size', visitor.get_size_attrs(), content_type="text/plain") # get the information from the cache #~ return formatter.image(src=cache.url(self.request, key), alt=xxx) # XXX this currently only works for HTML, obviously... return formatter.rawHTML('<object type="image/svg+xml" data="%s" %s></object>' % ( cache.url(self.request, key), cache._get_datafile(self.request, key+'_size').read() # XXX no way to directly read cache? ))
def render(self, formatter): from MoinMoin.action import cache # checks if initializing of all attributes in __init__ was done if not self.init_settings: return # check if diagram on this page has been rendered before key = cache.key(self.request, itemname=self.pagename, content=self.raw) if not cache.exists(self.request, key): image = urllib.urlopen(createYumlUrl(self.raw), proxies=proxies) cache.put(self.request, key, image.read(), content_type="image/png") return formatter.image(src=cache.url(self.request, key), alt=self.raw)
def cache_exists(request, key): if getattr(request.cfg, "gwiki_cache_invalidate", False): return False return cache.exists(request, key)
def cache_exists(request, key): if getattr(request.cfg, 'gwiki_cache_invalidate', False): return False return cache.exists(request, key)