diff --git a/tempy/tempy.py b/tempy/tempy.py index c487791..a61891e 100755 --- a/tempy/tempy.py +++ b/tempy/tempy.py @@ -703,11 +703,16 @@ def clone(self): return copy(self) @classmethod - def join(cls, list): - n = len(list) + def join(cls, list_ele): + n = len(list_ele) for index in range(1, 2*n-2, 2): - list.insert(index, cls()) - return list + list_ele.insert(index, cls()) + return list_ele + + @classmethod + def map(cls, list_ele): + mapped_list = [cls()(ele) for ele in list_ele] + return mapped_list class Escaped(DOMElement): diff --git a/tests/test_DOMElement.py b/tests/test_DOMElement.py index e2730e6..48b93e4 100755 --- a/tests/test_DOMElement.py +++ b/tests/test_DOMElement.py @@ -6,7 +6,7 @@ from tempy.elements import Tag from tempy.exceptions import WrongContentError, WrongArgsError, TagError, DOMModByKeyError, DOMModByIndexError -from tempy.tags import Div, A, P, Html, Head, Body, Pre, Br +from tempy.tags import Div, A, P, Html, Head, Body, Pre, Br, Td from tempy.tempy import DOMElement, Escaped @@ -578,7 +578,14 @@ def test_find(self): self.assertEqual(len(result), 1) def test_join(self): - tag= Div() - list=['foo', 'Br', 'Div', 'Pre'] - result= tag.join(list) + tag = Div() + list_ele = ['foo', 'Br', 'Div', 'Pre'] + result = tag.join(list_ele) self.assertEqual(len(result), 7) + + def test_map(self): + tag = Td() + list_ele = ['foo', 'Br', 'Div', 'Pre'] + result = tag.map(list_ele) + self.assertEqual(len(result), 4) +