Skip to content

Commit dce8aad

Browse files
committed
multiple callables per provider
1 parent bd010a9 commit dce8aad

7 files changed

+70
-67
lines changed

.idea/workspace.xml

+49-53
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

output.pptx

0 Bytes
Binary file not shown.

src/parser/ContentRenderer.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@
33
class ContentRenderer(object):
44

55
def __init__(self):
6-
self.providers = {}
6+
self.providers = []
77

88
def addProvider(self, provider):
9-
self.providers[provider.callable] = provider
9+
self.providers.append(provider)
1010

1111
def render(self, paragraph, templateContent, templateData):
1212
template = JinjaTemplate(templateContent)
1313
self.__registerProviders(paragraph, template)
1414
return template.render(templateData)
1515

1616
def __registerProviders(self, paragraph, template):
17-
for name, provider in self.providers.iteritems():
18-
template.globals[name] = self.__getProvider(paragraph, provider)
17+
for provider in self.providers:
18+
for callable in provider.getCallables():
19+
template.globals[callable] = self.__getCallable(callable, paragraph, provider)
1920

20-
def __getProvider(self, paragraph, provider):
21-
return lambda *args: provider.getCallable(paragraph, *args)
21+
def __getCallable(self, callable, paragraph, provider):
22+
return lambda *args: getattr(provider, callable)(paragraph, *args)

src/provider/ContentProvider.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
class ContentProvider(object):
44

55
@abc.abstractmethod
6-
def getCallable(self, paragraph):
6+
def getCallables(self):
77
pass

src/provider/basic/ImageProvider.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33

44
class ImageProvider(ContentProvider):
55

6-
callable = 'image'
6+
def getCallables(self):
7+
return ['image']
78

8-
def getCallable(self, paragraph, filepath):
9+
def image(self, paragraph, filepath):
910
self.__insert(paragraph, os.path.join(os.getcwd(), filepath))
1011
return ''
1112

src/provider/basic/TableProvider.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ def __insert(self, file):
1616

1717
class TableProvider(ContentProvider):
1818

19-
callable = 'table'
19+
def getCallables(self):
20+
return ['table', 'cell']
2021

21-
def getCallable(self, paragraph, path):
22+
def table(self, paragraph, path):
23+
return ''
24+
25+
def cell(self, paragraph, path):
2226
return ''

src/provider/basic/TextProvider.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33

44
class TextProvider(ContentProvider):
55

6-
callable = 'text'
7-
86
def __init__(self, dictionary):
97
self.dictionary = dictionary
108

11-
def getCallable(self, paragraph, path):
9+
def getCallables(self):
10+
return ['text']
11+
12+
def text(self, paragraph, path):
1213
return DictUtils.get(self.dictionary, path.strip(), "#undefined#")
1314

0 commit comments

Comments
 (0)