def write_attribute(self, key, value): u""" Auxiliary function to write each attribute to @self.result@. If the *key* is defined in @self.SINGLE_ATTRIBUTES@ then only output the single key name (even if this breaks XML validation). By default the @self.SINGLE_ATTRIBUTES@ is empty, but it can be redefined by the inheriting application class. If the *key* is in @self.CASCADING_ATTRIBUTES@ and the *value* is tuple or a list, then join the *value*, separated by spaces. This feature is especially used to build flexible cascading *class_* attributes. If the attribute has no value, then the output is skipped. """ line = None if key == 'class_': key = 'class' value = self.class2SpaceString(value) if key in self.SINGLE_ATTRIBUTES: line = u' ' + key elif isinstance(value, (list, tuple)): if key in self.CASCADING_ATTRIBUTES: value = TX.flatten2Class(value) if isinstance(value, basestring): value = value.replace('"', '"') if value: line = u' %s="%s"' % (key, value) else: raise ValueError( '[XmlTagBuilder.write_attribute] No list attribute value allowed for %s="%s"' % (key, ` value `)) elif value: if isinstance(value, basestring): value = value.replace('"', '"') line = u' %s="%s"' % (key, value) if line: self.output(line)
def write_attribute(self, key, value): u""" Auxiliary function to write each attribute to @self.result@. If the *key* is defined in @self.SINGLE_ATTRIBUTES@ then only output the single key name (even if this breaks XML validation). By default the @self.SINGLE_ATTRIBUTES@ is empty, but it can be redefined by the inheriting application class. If the *key* is in @self.CASCADING_ATTRIBUTES@ and the *value* is tuple or a list, then join the *value*, separated by spaces. This feature is especially used to build flexible cascading *class_* attributes. If the attribute has no value, then the output is skipped. """ line = None if key == 'class_': key = 'class' value = self.class2SpaceString(value) if key in self.SINGLE_ATTRIBUTES: line = u' ' + key elif isinstance(value, (list, tuple)): if key in self.CASCADING_ATTRIBUTES: value = TX.flatten2Class(value) if isinstance(value, basestring): value = value.replace('"', '"'); if value: line = u' %s="%s"' % (key, value) else: raise ValueError('[XmlTagBuilder.write_attribute] No list attribute value allowed for %s="%s"' % (key, `value`)) elif value: if isinstance(value, basestring): value = value.replace('"', '"'); line = u' %s="%s"' % (key, value) if line: self.output(line)
def image(self, component, class_=None): u""" """ if component.style: width = component.style.width_html height = component.style.height_html else: width = None height = None if height is None and width is None: width = '100%' elif height is not None: width = None self.img(src=component.url, width_html=width, height_html=height, alt=component.alt, class_=TX.flatten2Class(class_, component.getPrefixClass()))
def image(self, component, class_=None): u""" """ if component.style: width = component.style.width_html # Take explicit HTML width/height if defined in component. height = component.style.height_html else: width = None height = None if height is None and width is None: width = '100%' elif height is not None: width = None alt = component.alt or TX.path2Name(component.url) self.img(src=component.url, width_html=width, height_html=height, alt=alt, class_=TX.flatten2Class(class_, component.getPrefixClass()))