def element_for(self, block, block_content): type_ = block['type'] depth = block['depth'] options = Options.for_block(self.block_map, type_) props = dict(options.props) props['block'] = block props['blocks'] = self.blocks # Make an element from the options specified in the block map. elt = DOM.create_element(options.element, props, block_content) parent = self.parent_for(options, depth, elt) return parent
def element_for(self, block, block_content): type_ = block['type'] depth = block['depth'] data = block.get('data', {}) options = Options.for_block(self.block_map, type_) props = dict(options.props) props['block'] = { 'type': type_, 'depth': depth, 'data': data, } # Make an element from the options specified in the block map. elt = DOM.create_element(options.element, props, block_content) parent = self.parent_for(options, depth, elt) return parent
def test_for_block_raises_missing_element(self): with self.assertRaises(ConfigException): Options.for_block({'header-one': {}}, 'header-one')
def test_for_block_raises_missing_type(self): with self.assertRaises(ConfigException): Options.for_block({'header-one': 'h1'}, 'header-two')
def test_for_block_uses_fallback(self): self.assertEqual(Options.for_block({'header-one': 'h1', 'fallback': 'div'}, 'header-two'), Options('header-two', 'div'))
def test_for_block_simplest(self): self.assertEqual(Options.for_block({'unordered-list-item': 'li'}, 'unordered-list-item'), Options('unordered-list-item', 'li'))