From: Konrad Rosenbaum Date: Wed, 21 Aug 2013 17:00:24 +0000 (+0200) Subject: bring ODT template docu up to date X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=b9d26443430b796f50a270583497a4b5bcb00819;p=web%2Fkonrad%2Fsmoke.git bring ODT template docu up to date --- diff --git a/doc/prog_odttemplate.html b/doc/prog_odttemplate.html index ca7c1c4..9fb9df0 100644 --- a/doc/prog_odttemplate.html +++ b/doc/prog_odttemplate.html @@ -1,9 +1,9 @@ -Magic Smoke ODT Templates +Magic Smoke ODF Templates -

Magic Smoke ODT Templates

+

Magic Smoke ODF Templates

-This text describes how ODT templates are generated and which ones exist. ODT templates always use the suffix ".odtt". +This text describes how ODF templates are generated and which ones exist. ODT templates always use the suffix ".odtt" for text templates and ".odst" for spreadsheet templates.

Creating a Template

@@ -12,143 +12,109 @@ Open Document Files (*.od?, usually *.odt) are basically zipped XML files. Magic This process needs some knowledge in XML.

    -
  1. Write an OD file that meets your expectations for what you want to template. It is recommended that you already put all variables (@VAR@, see below) into the file to make it easier to find each location.
  2. +
  3. Write an OD file that meets your expectations for what you want to template. It is recommended that you already put all variables (@VAR@, see below) or at least some markers into the file to make it easier to find each location. Alternatively you can go through the "Edit Templates" dialog to retrieve an existing template.
  4. -
  5. Unzip it into a clean directory - make sure the directory structure of the ODT-ZIP-file is kept intact.
    Eg. under Linux to extract example.odt: mkdir example; cd example; unzip ../example.odt
  6. +
  7. Open MagicSmoke and log into your system (this is necessary to test localization and to have data available for testing the template).
  8. -
  9. Reformat content.xml to make it readable for yourself. You can use any XML tool that suits your need.
    Eg. xmllint --format content.xml >content2.xml; mv content2.xml content.xml
  10. +
  11. Go to the menu "Actions" - "Templates" - "ODF Editor", then go to "File" - "Import ODF File" and load your file.
  12. -
  13. Enter all missing variables and loops. Note that the Template language is line based, while XML is not.
  14. +
  15. Enter all missing variables and loops. See below.
  16. -
  17. Zip the result into a template file.
    Eg.: cd example; zip -r ../example.odtt .
  18. +
  19. Test the template: +
    1. Go to "Test" - "Test with..."; depending on what kind of template you are constructing chose the correct type.
    2. +
    3. MagicSmoke asks for the Order ID or Event to use as a template - it is best if you check beforehand to have a few examples handy that fulfill your requirements for testing a template (e.g. one order with multiple different tickets, one with vouchers, one paid, one partly paid...)
    4. +
    5. A window opens that contains the example information - it behaves just the same as in normal mode except that it always uses the template you just created for printing. Warning: if you make changes to an order in this window, they WILL end up in the system!
    6. +
    7. Go to the print or save function and test the template, it is recommended to use a virtual PDF printer or to just save as ODF file for testing to avoid wasting paper.
    8. +
    9. Close the window, continue to change the file or save it.
    10. +
    -
  20. Upload the template file to the server
  21. +
  22. Save the template locally. It is recommended to keep this saved file around to have a backup for later reference.
  23. + +
  24. Upload the template file to the server: "Templates" - "Edit Templates", use the "Upload new Variant" button to upload your file.

Syntax

-

Variables

- -Variable names are enclosed in two "@" signs and contain only upper-case letters. Any syntax violation results in the template parser interpreting the text as simple non-variable text and dumping it as is. To create a single "@" you can simply enter "@@".

- -If a variable exists it is replaced by the value that Magic Smoke intended for it. If it does not exist it is replaced by an empty string.

+ODF templates use a pure XML syntax, they are actually ODF files that have been enhanced with some XML tags that allow to create special behavior.

-If a value contains special characters they are replaced by the correct XML sequences (eg. < by &lt;). - -

Loops and Loop Variables

+You have the following syntactic elements at your disposal: + -Some templates use repeating elements. These are expressed as loops. Loops are sections of text that are repeated for every iteration of the internal loop, eg.: +

Variables and Formulas

-
-#LOOP:EXAMPLE
-<markup>this value changes with each iteration: @EXAMPLE:VAR@</markup>
-#ENDLOOP
-
+Variables and Formulas can be added to any text element by enclosing them in two "@" signs. Predefined variables contain only upper-case letters, you can assign variables with any combination of upper- and lower-case. The parser is case sensitive. Any syntax violation results in empty text. To create a single "@" you can simply enter "@@".

-Each loop begins with a line that starts "#LOOP:" and finishes with the loop name. It ends with a line that contains only "#ENDLOOP". If a loop does not exist this deletes the content in between, if it does exist the content is replicated as often as the loop iterates.

- -Loop variable names are enclosed in "@", and contain the loop name and the variable name separated by a colon. In each iteration the loop variables are set to the current iterations value. Variables from different loops are handled like unknown variables: they are replaced by empty strings.

- -Loops cannot be nested. - -

Conditional Output

+If a variable exists it is replaced by the value that Magic Smoke intended for it.

-The output of parsed lines can be suppressed: +If a value contains special characters they are replaced by the correct XML sequences (eg. < by &lt;).

-

-#IF:MYVAR < 66
-output if the value is smaller than 66
-#ELSE
-output otherwise
-#ENDIF
-
- -A condition consists of exactly two values (both may be variables) and an operator. More complex expressions are not possible at the moment. If the condition evaluates to false, then the output and calculation of all lines until #ELSE or #ENDIF is suppressed.

- -At the moment the #ELSE statement reverses the output suppression between #IF and #ENDIF. Multiple #ELSEs are possible at the moment, but should not be relied upon in case the logic changes in subsequent versions.

- -Conditions cannot be nested, but conditions can be embedded in loops or be put around loops. If a condition is put around a loop, it does not prevent the processor from evaluating the loop, only the output and internal calculations are suppressed.

+You can use the usual mathematical operations to add, subtract, multiply or divide. There are a number of functions available to convert values.

+Operators and functions:
- - - - - - - - - -
OperatorDescription
<lighter than
<=lighter or equal
>greater than
>=greater or equal
<>not equal
!=not equal
=equal
==equal
- - -

Calculations

- -Numeric variables allow some very simple calculations in place: +@123@literal integer value 123 - rendered as number 123 +@"hello"@literal string value rendered as hello (without "quotes") +@VAR@tries to find the variable VAR and replaces it by its value +@VAR1 + VAR2@add the value of two variables VAR1 and VAR2, or if one of them is string: concatenate them +@VAR1 + 9@add 9 to the value of the variable VAR1 and display the result +@VAR1 - VAR2@subtract the value of VAR2 from VAR1 +@VAR1 * VAR2@multiply two values +@VAR1 / VAR2@divide two values +@VAR1 == 12@compare two values for equality, yields a boolean usable in if(...), other operators are != (non-equality), < (less than), <= (less or equal), > (greater), >= (greater or equal) +@VAR1 || true@logical OR of the value of VAR1 and the literal boolean true, other logical operators are: && (AND), and ^^ (XOR) +@VAR = 123@assign a value to variable VAR and also print this value +@int(VAR)@try to convert the value of VAR into a numeric value, succeeds for integers, floats and all strings that contain digits only +@float(VAR)@try to convert to a floating point number +@bool(VAR)@try to convert to a boolean (succeeds for numbers: zero is false, anything else is true) +@string(VAR)@converts a value to string (after this numbers can be concatenated, but not multiplied anymore) +@strlen(VAR)@returns the number of characters of the variable +@concat(VAR1,VAR2,...)@concatenate multiple values into one string +@null@a literal value for "invalid value", cannot be used as variable name +@true@, @false@literal truth values +@!true@inverts a boolean value +@if(BOOL, IFTRUEEXPR [,IFFALSEEXPR])@if the first parameters evaluates to true, the result is the second parameter, otherwise the (optional) third parameter (if omitted: null) +@isNull(EXPR)@evaluates to true if the parameter is null (invalid) +@isException(EXPR)@evaluates to true if the parameter yields an exception (i.e. the operation is not permitted on those values or a variable or function is unknown) +@isExceptionOrNull(EXPR)evaluates to true if the parameter is null or yields an exception +@catch(EXPR [, IFEXC [, IFOK]] )@if the EXPR yields and exception returns the second paramter (IFEXC) or true, otherwise the third parameter or false +@toMoney(INTVAL)@converts a value in cents to a normal monetary value, including currency sign +@toMoneyLocal(INTVAL)@converts a value in cents to a normal monetary value, including currency sign in its localized form +@toMoneyNL(INTVAL)@converts a value in cents to a normal monetary value, including currency sign in its non-localized form +@fromMoney(STRVAL)@converts a string representing a monetary value to a number in cents (inverse of toMoney(..); also: fromMoneyLocal(..), fromMoneyNL(..)) +@unix2date(INTVAL [,LOCAL])@converts a numeric Unix time to a human readable date value, per default localized, the optional parameter means: true=localized, false=non-localized +@unix2time(INTVAL [,LOCAL])@converts a numeric Unix time to a human readable time (without date) value +@unix2dateTime(INTVAL [,LOCAL])@converts a numeric Unix time to a human readable date and time value +@cent2str(INTVAL)@, @str2cent(STRVAL)@aliases for toMoney() and fromMoney() +

-

-@VARONE+11@
-@VARTWO-77@
-
- -In the above example the first line will be replaced by the amount of VARONE plus 11 and the second line by the amount of VARTWO minus 77.

- -For integer variables this works on the plain integer value. For money values it adds/subtracts cents.

- -More complex calculations can be done with the #CALC statement: +

Loops and Loop Variables

-
-#CALC:TVAR/MONEY:VAR1 * VAR2 + 4
-
+Some templates use repeating elements. These are expressed as loops. Loops are sections of XML that are repeated for every iteration of the internal loop.

-The above creates the temporary variable "@#TVAR@" that is the product of @VAR1@ and @VAR2@'s content plus 4. It is marked as a monetary value. Please note that the variables are not enclosed in "@".

+If you want to repeat some XML elements multiple times mark them all (using Shift + Click) and then select "Edit" - "Wrap in Loop" from the menu. The loop element will be placed where those wrapped elements were and the wrapped elements will be placed inside the loop. This can be used to loop through text, table rows, or other XML elements.

-Calculations are restricted to the operators below and are always done from left to right - more complex formulas require several lines. Tokens must be space separated. If no type or a non-existing type is requested INT is assumed. All calculations are done using 64bit signed integers. If the processor comes across an illegal token it sets the variable to "error".

+You have to select a loop variable. See below for valid choices. The elements of the loop will be repeated for each iteration of the loop variable, this can be zero, one or multiple times.

-Literals (above: "4") must be integers.

+Loops can be nested, but nesting the same loop variable may lead to undesired results. - - - - - - - -
OperatorDescription
+adding
-subtracting
*multiplication
/division
%modulo
- - - - - - - - -
TypeDescription
INTinteger number
MONEYmonetary value (the number is interpreted as cents)
DATEa unix timestamp to be shown as date
TIMEa unix timestamp to be shown as its time component
DATETIMEa unix timestamp to be shown as date plus time
- -

Newline Replacement

- -The #SETNEWLINE statement can be used to create a macro that will replace newline in variables: - -
-#SETNEWLINE:</text:p><text:p text:style-name="Text_20_body">
-
+

Conditional Output

-The default is a single space character, which can be restored by using "#SETNEWLINE:" without parameters. +You can wrap elements in a condition. The condition can be any expression described above, excluding the "@" signs - the expression must yield a value that can be converted to boolean (bool, or numeric result).

-

Generic Variables

+To wrap some elements in a conditional mark them with Shift + Click, then go to the menu and select "Edit" - "Wrap in condition". All elements inside this new condition element will now only appear in the document if the condition expression yields boolean "true".

-There are a few variables that always exist: +You can make some elements appear on "true" and some on "false" if you insert an "else" tag: mark the element directly before the position where you want to insert the "else" tag and then select "Edit" - "Insert else behind current". It is permissible to insert several "else" tag - each one inverting the one that came before it, but this is not recommended, since it can become quite confusing.

- - - - - -
VariableDescription
@TODAY@the current date
@NOW@the current time
@anyloop:ITERATION@for an active loop ("anyloop") the current iteration (0..n)
+

Calculations

-

Localization

+You can insert calculations anywhere in the document. Calculations are formulas that are evaluated, but whose result is not displayed. It makes sense to use them for calculating values that you want to use later on or to split up complex calculations into simpler steps. The syntax is the same as for formulas above, but without the enclosing "@" signs.

-Per default all variables are localized before they get inserted into the document. To suppress localization prefix the variable with a "$"-sign (eg. @$TODAY@ instead of @TODAY@). +Calculations inside conditionals are only executed if visible tags inside the conditional would be displayed (i.e. the condition is "true", or if behind an "else" tag: the condition is "false"). Calculations inside loops are executed for each iteration of the loop.


Event Summary