Add factory for generic elements.
This commit is contained in:
parent
193763a82a
commit
d5d9c101f0
@ -14,3 +14,6 @@ from .subfloat import subfloat
|
|||||||
from .table import table, tabledf
|
from .table import table, tabledf
|
||||||
from .tabular import tabular, tabulardf, hline_element, row_element, multicolumn
|
from .tabular import tabular, tabulardf, hline_element, row_element, multicolumn
|
||||||
from .inlines import it, bf, mt
|
from .inlines import it, bf, mt
|
||||||
|
from .latexfactory import factory
|
||||||
|
|
||||||
|
latex = factory()
|
||||||
|
38
pyltk/latexfactory.py
Normal file
38
pyltk/latexfactory.py
Normal 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)
|
Loading…
Reference in New Issue
Block a user