diff --git a/element.py b/element.py
index 7c60c25..e5b0851 100644
--- a/element.py
+++ b/element.py
@@ -17,12 +17,22 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see .
+import copy
+
+
+def build(element):
+ if hasattr(element, 'build'):
+ return element.build()
+ else:
+ return str(element), {}
+
class Element(object):
- def __init__(self, tagname, inner, **kwargs):
+ def __init__(self, tagname, inner, injections=None, **kwargs):
self.tagname = tagname
self.inner = inner
+ self._injections = injections if injections else []
if 'class_' in kwargs:
kwargs['class'] = kwargs.pop('class_')
self.args = kwargs
@@ -36,6 +46,13 @@ def build(self):
def __str__(self):
return self.build()
+ def injections(self):
+ result = copy.copy(self._injections)
+ for i in self.inner:
+ if hasattr(i, 'injections'):
+ result += i.injections()
+ return result
+
def __iter__(self):
'Hack to be returned to CherryPy with no prior conversion'
class TagIterator(object):
@@ -69,4 +86,4 @@ def build(self):
class HTMLElement(Element):
def build(self):
- return '\n' + Element.build(self)
\ No newline at end of file
+ return '\n' + Element.build(self)
diff --git a/tests/test_tags.py b/tests/test_tags.py
index 0ce8ea9..3937f54 100644
--- a/tests/test_tags.py
+++ b/tests/test_tags.py
@@ -29,3 +29,5 @@ def test_page():
t.p('Paragraph'),
)
).build()
+ assert r == '\n\n
\n\nTitle\n
\n\nParagraph\n
\n\n'
+