def render_entities(self, style_node): # We have a complete (start, stop) entity to render. if self.completed_entity is not None: entity_details = self.get_entity_details(self.completed_entity) opts = Options.for_entity(self.entity_decorators, entity_details['type']) props = entity_details['data'].copy() props['entity'] = { 'type': entity_details['type'], } if len(self.element_stack) == 1: children = self.element_stack[0] else: children = DOM.create_element() for n in self.element_stack: DOM.append_child(children, n) self.completed_entity = None self.element_stack = [] # Is there still another entity? (adjacent) if so add the current style_node for it. if self.has_entity(): self.element_stack.append(style_node) return DOM.create_element(opts.element, props, children) if self.has_entity(): self.element_stack.append(style_node) return None return style_node
def render_entities(self, style_node): if self.completed_entity is not None: entity_details = self.get_entity_details(self.completed_entity) opts = Options.for_entity(self.entity_decorators, entity_details['type']) props = entity_details['data'].copy() props['entity'] = { 'type': entity_details['type'], } nodes = DOM.create_element() for n in self.element_stack: DOM.append_child(nodes, n) elt = DOM.create_element(opts.element, props, nodes) self.completed_entity = None self.element_stack = [] elif self.has_no_entity(): elt = style_node else: self.element_stack.append(style_node) elt = None return elt
def test_for_entity_raises_missing_element(self): with self.assertRaises(ConfigException): Options.for_entity({'HORIZONTAL_RULE': {}}, 'HORIZONTAL_RULE')
def test_for_entity_raises_missing_type(self): with self.assertRaises(ConfigException): Options.for_entity({'HORIZONTAL_RULE': 'hr'}, 'TEST')
def test_for_entity_uses_fallback(self): self.assertEqual(Options.for_entity({'HORIZONTAL_RULE': 'hr', 'FALLBACK': 'div'}, 'TEST'), Options('TEST', 'div'))
def test_for_entity_simplest(self): self.assertEqual(Options.for_entity({'HORIZONTAL_RULE': 'hr'}, 'HORIZONTAL_RULE'), Options('HORIZONTAL_RULE', 'hr'))