Hello everyone!
I’m developing an app using the Python library for document building, which generates documents based on various “components” that users can select. Each component is defined in a .docbuilder file and comes with different arguments.
My approach involves combining the Python document builder library with .docbuilder scripts to create the documents. For example, I can specify that I want a document with a header component, a paragraph section, an image, and another paragraph section. I then pass the information using the --argument
option in builder.SetProperty("--argument", "arguments dictionary")
and execute builder.Run(Path-to-script)
.
Initially, I tried to use the .SetProperty
method for each builder.Run
with the appropriate arguments for each .docbuilder script. However, I discovered that this method only works for the first script run. While I can pass all arguments to the builder in one go, having multiple instances of the same component causes the key arguments to overwrite each other.
Sample of my generateFile function:
def generateFile(docName, docType, positionArray, objectsDict):
filename = docName + "." + docType
dstPath = './filestore/' + filename
builder = docbuilder.CDocBuilder()
builder.CreateFile(docType)
for position in positionArray:
builder.SetProperty("--argument", str(objectsDict[position]['params']).replace('\'','\"'))
builder.Run(f'./templates/{position}.docbuilder')
builder.SaveFile(docType, dstPath)
builder.CloseFile()
return filename
Sample from a docbuilder that writes a paragraph section:
var oDocument = Api.GetDocument();
var sArray = Argument["array"];
var oParagraph = Api.CreateParagraph();
oParagraph.AddText("Vamos escrever um array de paragrafos :)");
oDocument.Push(oParagraph);
sArray.forEach(function(item, i, Array) {
var oParagraph = Api.CreateParagraph();
oParagraph.AddText(item);
oDocument.Push(oParagraph);
});
Has anyone faced a similar issue or has suggestions on how to handle multiple components with the same arguments without them conflicting? Any insights would be greatly appreciated!