From 178f9ed3c03e7f283f34db5d4afb12a174e37139 Mon Sep 17 00:00:00 2001 From: berteh Date: Tue, 29 Jan 2019 23:31:21 +0100 Subject: [PATCH] changed %VAR_NEXT-RECORD% to %SG_NEXT-RECORD%, #118 --- README.md | 14 ++++++++++--- ScribusGeneratorBackend.py | 6 +++--- example/MonsterCards/MonsterCards.sla | 14 ++++++------- example/Next_Record.sla | 10 +++++----- .../ConvertSGAttributesToSG27.py | 0 utils/ConvertVAR_NEXT-RECORDToSG28.py | 12 +++++++++++ utils/README.md | 20 +++++++++++++++++++ 7 files changed, 58 insertions(+), 18 deletions(-) rename ConvertSGAttributesToSG27.py => utils/ConvertSGAttributesToSG27.py (100%) create mode 100644 utils/ConvertVAR_NEXT-RECORDToSG28.py create mode 100644 utils/README.md diff --git a/README.md b/README.md index ce00f3c..3822def 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ You can place the variable at any position within a Text Frame. Apply all format ![Illustration: Scribus File for Generator](pic/SG-01.png) -If you wish to generate one page (or many) for each data entry you're done, congratulations ! If you would rather display many data entries on a single page simply add the text ``%VAR_NEXT-RECORD%`` after each entry but the last: ScribusGenerator will automatically load the new data record when it reaches the end of your template. +If you wish to generate one page (or many) for each data entry you're done, congratulations ! If you would rather display many data entries on a single page simply add the text ``%SG_NEXT-RECORD%`` after each entry but the last: ScribusGenerator will automatically load the new data record when it reaches the end of your template. ### Create your (csv) Data File @@ -142,15 +142,23 @@ Multiple records on a single page ----------- [**Scribus Generator**](https://github.com/berteh/ScribusGenerator/) allows you to display mupliple data entries in a single document. Great to generate your own listings, team charts, game cards, who's who posters and more. -Simply drop the text ``%VAR_NEXT-RECORD%`` in your document between each data entry, following our [example document](https://github.com/berteh/ScribusGenerator/blob/master/example/Next-Record.sla). +Simply drop the text ``%SG_NEXT-RECORD%`` in your document between each data entry, following our [example document](https://github.com/berteh/ScribusGenerator/blob/master/example/Next-Record.sla). -Scribus Generator will automatically load the next record when it reaches the end of your template... so don't add the ``%VAR_NEXT-RECORD%`` at the end of your last page. +Scribus Generator will automatically load the next record when it reaches the end of your template... so don't add the ``%SG_NEXT-RECORD%`` at the end of your last page. A full example to generate Monsters Game Cards based on [Dungeon World](http://www.dungeon-world.com/) is available in the [MonsterCards](https://github.com/berteh/ScribusGenerator/tree/master/example/MonsterCards) directory, created by [Dustin Andrews](https://github.com/dustinandrews): [![Illustration: Example card deck of monsters, by Dustin Andrew](pic/MonsterCards_partial.png)](https://github.com/berteh/ScribusGenerator/raw/master/example/MonsterCards/MonsterCards_partial.pdf) +Please note Scribus Generator v2.8 (from January 2019) changed the syntax of the ["Next Record" feature](https://github.com/berteh/ScribusGenerator#multiple-records-on-a-single-page) +to a less confusing name, as per [suggestion #118](https://github.com/berteh/ScribusGenerator/issues/118) + +Update your older templates manually, changing ``%VAR_NEXT-RECORD`` to ``%SG_NEXT-RECORD``, or all at once by calling, for instance: + + python ./ConvertVAR_NEXT-RECORDToSG28.py ~/ScribusProjects/*/*.sla + + Dynamic output file location ----------- [**Scribus Generator**](https://github.com/berteh/ScribusGenerator/) allows you to customize the name (and location) of the generated document easily. Add the output file name you wish in your data, and use the corresponding variable (or combination of multiple variables) in the field "Output File Name". Kindly note this file name is always relative to the output directory, and has *no extension*. diff --git a/ScribusGeneratorBackend.py b/ScribusGeneratorBackend.py index 5d8118c..9af1794 100644 --- a/ScribusGeneratorBackend.py +++ b/ScribusGeneratorBackend.py @@ -6,6 +6,7 @@ # For further information (manual, description, etc.) please visit: # https://github.com/berteh/ScribusGenerator/ # +# v2.8 (2019-01-29): code style > PEP8 approximate, renamed %VAR_NEXT-RECORD% into %SG_NEXT-RECORD% # v2.7 (2018-04-22): change SGAttribute to work in Scribus 1.5.3 GUI. # v2.6 (2018-04-07): bug fix (dynamic output file directory, linked frames limit, Python 3.6 syntax) # v2.5 (2017-03-27): support for multiple records on same page (Next-Record mechanism), bug fix (multiple SGAttributes) @@ -29,9 +30,8 @@ import platform import logging import logging.config -#import traceback import sys -import xml.etree.ElementTree as ET # common Python xml implementation +import xml.etree.ElementTree as ET import json import re import string @@ -61,7 +61,7 @@ class CONST: KEEP_TAB_LINEBREAK = 1 SG_VERSION = '2.5' # set to any word you'd like to use to trigger a jump to the next data record. using a name similar to the variables %VAR_ ... % will ensure it is cleaned after generation, and not show in the final document(s). - NEXT_RECORD = '%VAR_NEXT-RECORD%' + NEXT_RECORD = '%SG_NEXT-RECORD%' class ScribusGenerator: diff --git a/example/MonsterCards/MonsterCards.sla b/example/MonsterCards/MonsterCards.sla index d5ea02c..4e1dc5c 100644 --- a/example/MonsterCards/MonsterCards.sla +++ b/example/MonsterCards/MonsterCards.sla @@ -115,7 +115,7 @@ - + @@ -146,7 +146,7 @@ - + @@ -177,7 +177,7 @@ - + @@ -208,7 +208,7 @@ - + @@ -239,7 +239,7 @@ - + @@ -270,7 +270,7 @@ - + @@ -301,7 +301,7 @@ - + diff --git a/example/Next_Record.sla b/example/Next_Record.sla index c460117..816b0de 100644 --- a/example/Next_Record.sla +++ b/example/Next_Record.sla @@ -182,7 +182,7 @@ - + @@ -210,7 +210,7 @@ - + @@ -231,7 +231,7 @@ - + @@ -252,7 +252,7 @@ - + @@ -273,7 +273,7 @@ - + diff --git a/ConvertSGAttributesToSG27.py b/utils/ConvertSGAttributesToSG27.py similarity index 100% rename from ConvertSGAttributesToSG27.py rename to utils/ConvertSGAttributesToSG27.py diff --git a/utils/ConvertVAR_NEXT-RECORDToSG28.py b/utils/ConvertVAR_NEXT-RECORDToSG28.py new file mode 100644 index 0000000..ed6c55a --- /dev/null +++ b/utils/ConvertVAR_NEXT-RECORDToSG28.py @@ -0,0 +1,12 @@ +import fileinput +import re +# +# convert old syntax of %VAR_NEXT-RECORD% to new syntax of %SG_NEXT-RECORD% in your SLA files (ScribusGenerator version 2.8+). Creates a backup of all modified files (.bak) +# run, for instance: +# python ./ConvertVAR_NEXT-RECORDToSG28.py examples/old-template-with-VAR_NEXT-RECORD.sla +# python ./ConvertVAR_NEXT-RECORDToSG28.py ~/ScribusProjects/*/*.sla + +for line in fileinput.input(inplace=1, backup='.bak'): + line = re.sub(r'VAR_NEXT-RECORD', + r'SG_NEXT-RECORD', line.rstrip()) + print(line) diff --git a/utils/README.md b/utils/README.md new file mode 100644 index 0000000..405010a --- /dev/null +++ b/utils/README.md @@ -0,0 +1,20 @@ +Various Scripts +=========== + +Fixes to retro-compatibility issues +----------- + +SG v2.7 (April 2018) changed the syntax of [Advanced Attributes](https://github.com/berteh/ScribusGenerator#more-advanced-uses), +to support Scribus 1.5 branch. + +Update your older templates by calling, for instance: + + python ./ConvertSGAttributesToSG27.py ~/ScribusProjects/*/*.sla + + +SG v2.8 (January 2019) changed the syntax of the ["Next Record" feature](https://github.com/berteh/ScribusGenerator#multiple-records-on-a-single-page) +to a less confusing name, as per [suggestion #118](https://github.com/berteh/ScribusGenerator/issues/118) + +Update your older templates by calling, for instance: + + python ./ConvertVAR_NEXT-RECORDToSG28.py ~/ScribusProjects/*/*.sla