MCPcopy Create free account
hub / github.com/PageBot/PageBot / compose

Method compose

Lib/pagebot/base/composer.py:44–99  ·  view source on GitHub ↗

Compose the galley element, based on code blocks in the galley. TODO: add more art-direction instructions here. Targets contains the resources for the composition, such as the doc, current page, current box and other info that the MarkDown assumes to be available. I

(self, galley=None, targets=None, page=None)

Source from the content-addressed store, hash-verified

42
43
44 def compose(self, galley=None, targets=None, page=None):
45 """Compose the galley element, based on code blocks in the galley.
46
47 TODO: add more art-direction instructions here.
48
49 Targets contains the resources for the composition, such as the doc,
50 current page, current box and other info that the MarkDown assumes to
51 be available. If targets is omitted, then a default target dictionary
52 is created by the Composer and answered at the end."""
53 if targets is None:
54 if page is None:
55 page = self.doc[1]
56
57 targets = dict(composer=self, doc=self.doc, page=page, style=self.doc.styles,
58 newText=newText)
59
60 if page is not None:
61 targets['box'] = page.select('main')
62
63 elif page is not None:
64 targets['page'] = page
65
66 if 'errors' not in targets:
67 targets['errors'] = []
68 errors = targets['errors']
69
70 if 'verbose' not in targets:
71 targets['verbose'] = []
72 verbose = targets['verbose']
73
74 if galley is None:
75 galley = page.galley
76
77 composerName = self.__class__.__name__
78
79 for e in galley.elements:
80 # Code can select a new page/box and execute other Python
81 # statements.
82 if isinstance(e, CodeBlock):
83 # Keep same targets, so code blocks share sequence of altered
84 # globals.
85 e.run(targets)
86 verbose.append('%s.compose: Run codeblock "%s"' % (composerName, e.code[:100]))
87
88 elif targets.get('box') is not None and targets.get('box').isText and targets.get('box').bs is not None and e.isText:
89 # If new content and last content are both text boxes, then
90 # merge the string.
91 targets.get('box').bs += e.bs
92
93 elif targets.get('box') is not None:
94 # Otherwise just paste the galley-element onto the target box.
95 e.parent = targets.get('box')
96 else:
97 errors.append('%s.compose: No valid box or image selected "%s - %s"' % (composerName, page, e))
98
99 return targets
100
101 def debug(self, s):

Callers 1

produceMethod · 0.95

Calls 4

selectMethod · 0.80
runMethod · 0.45
appendMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected