Add factory for generic elements.

This commit is contained in:
Holt59 2018-07-07 15:56:30 +02:00
parent 193763a82a
commit d5d9c101f0
2 changed files with 41 additions and 0 deletions

View File

@ -14,3 +14,6 @@ from .subfloat import subfloat
from .table import table, tabledf
from .tabular import tabular, tabulardf, hline_element, row_element, multicolumn
from .inlines import it, bf, mt
from .latexfactory import factory
latex = factory()

38
pyltk/latexfactory.py Normal file
View File

@ -0,0 +1,38 @@
# -*- encoding: utf-8 -*-
from .element import element
class generic_element(element):
templates = {
'element': '\\{name}{options}{attributes}',
'options': '[{content}]'
}
autolabel = False
def __init__(self, name, *args, parent=None, **kargs):
super().__init__(parent, **kargs)
self.name = name
if not args:
self.attributes = '{}'
else:
self.attributes = ''
for arg in args:
self.attributes += '{{{}}}'.format(arg)
def content(self):
return self.fmt().format('element', {
'name': self.name,
'attributes': self.attributes,
'options': self.format_options(self.options)
})
class factory:
def __getattr__(self, name):
return lambda *args, **kargs: \
generic_element(name, *args, **kargs)