def prerender(self): """Return a Tag or TagContent object.""" tag = Tag('input', type_='text', name=self.name, value=self.value, id=self._id) tag.set_attributes(self.attributes) if self.label: if self.label.align == 'left': args = [self.label.label(self), ' ', tag] else: args = [tag, ' ', self.label.label(self)] tag = TagContent(*args) if self.wrapper: tag = self.wrapper.wrap(tag, self) return tag
def test_tag_with_tagcontent(self): self.assertEqual( Tag('p', TagContent('Hello world')).render(), '<p>Hello world</p>')
def test_mixed_tag_content(self): self.assertEqual( TagContent('hello', SomeHtml(), 'world').render(), 'hello<html>world')
def test_html_tag_content(self): self.assertEqual(TagContent(SomeHtml()).render(), '<html>')
def test_string_tag_content_escape(self): self.assertEqual( TagContent('<hello>', '&world').render(), '<hello>&world')
def test_multi_string_tag_content(self): self.assertEqual(TagContent('hello', 'world').render(), 'helloworld')
def test_string_tag_content(self): self.assertEqual(TagContent('test').render(), 'test') self.assertEqual(TagContent('test').__html__(), 'test')
def wrap(self, tag, field): if self.align == 'left': args = [self.text, ' ', tag] else: args = [tag, ' ', self.text] return Tag('label', TagContent(*args), for_=field.id)