berteh / ScribusGenerator

Create beautiful documents with data. Open source pdf (and Scribus) template and mail-merge alternative.
http://berteh.github.io/ScribusGenerator/
MIT License
247 stars 37 forks source link

Add support for JSON #184

Closed S1SYPHOS closed 2 years ago

S1SYPHOS commented 3 years ago

This PR adds support for JSON files being passed as csvFile, see #10

I'd suggest though that everything related to CSV be renamed to 'data', so csvFile becomes dataFile etc BUT CSV-specific variables should keep their names, like csvSeparator. Where an equivalent is needed, like with CSV_ENCODING, a JSON variant should be added, in this case JSON_ENCODING.

S1SYPHOS commented 3 years ago

There's lots of other stuff I'd like to know, for example why using the dataBuffer is necessary, but since I'm not as experienced as you, I just left it like it was.

Apart from that, I turned everything into snake_case, moved stuff around in order that it appears in the run() function, renamed some variables, etc.

This got out of hand quickly, but I think most of it is alright with you - at least I hope it is :confused:

S1SYPHOS commented 3 years ago

As suggested, I renamed csvFile to dataFile to avoid confusion in the future.

S1SYPHOS commented 2 years ago

I guess you are very busy right now, if it's the PR that's bothering you, just let me know!

berteh commented 2 years ago

Hi Martin. sorry for not merging this PR earlier, I completely forgot.Thanks for your help !

berteh commented 2 years ago

There's lots of other stuff I'd like to know, for example why using the dataBuffer is necessary, but since I'm not as experienced as you, I just left it like it was.

Maybe I took a too obscure approach. The purpose is to be able to hande a single document that consumes multiple rows (via %SG-NEXT-RECORD%).

Imagine the data files holds 15 data entries, and Scribus template uses 4. The code at https://github.com/berteh/ScribusGenerator/blob/92d63372196f595d2f41624bf88ead72df94a1cb/ScribusGeneratorBackend.py#L168 will lead to making 4 substitutions from the document template top element, respectively using 4, 4, 4 and 3 data entries. It is the dataBuffer that accumulates the needed amound of data rows to feed the subsitution.

Any simplification idea is welcome.

Apart from that, I turned everything into snake_case, moved stuff around in order that it appears in the run() function, renamed some variables, etc.

This got out of hand quickly, but I think most of it is alright with you - at least I hope it is confused