[open-ils-commits] r20138 - branches/rel_2_1/Open-ILS/xul/staff_client/chrome/content/util (phasefx)

svn at svn.open-ils.org svn at svn.open-ils.org
Sun Apr 17 15:26:10 EDT 2011


Author: phasefx
Date: 2011-04-17 15:26:05 -0400 (Sun, 17 Apr 2011)
New Revision: 20138

Modified:
   branches/rel_2_1/Open-ILS/xul/staff_client/chrome/content/util/print.js
Log:
Add new macros for print templates.

%-TRIM%
Trims whitespace before the macro

%TRIM-%
Trims whitespace after the macro

%SUBSTR(#)%...%SUBSTR_END%
Take substring starting at position # to end of string.
If # is negative count backwards from end of string.

%SUBSTR(#,#)%...%SUBSTR_END%
Same as previous, but limit to second provided number characters after start point.
If second number is negative, count backwards instead of forwards.

TRIM macros inside of SUBSTR will be replaced first, then SUBSTR, then TRIM outside of SUBSTR.

Author: Thomas Berezansky <tsbere at mvlc.org>
Signed-off-by: Thomas Berezansky <tsbere at mvlc.org>
Signed-off-by: Jason Etheridge <jason at esilibrary.com>


Modified: branches/rel_2_1/Open-ILS/xul/staff_client/chrome/content/util/print.js
===================================================================
--- branches/rel_2_1/Open-ILS/xul/staff_client/chrome/content/util/print.js	2011-04-17 19:25:38 UTC (rev 20137)
+++ branches/rel_2_1/Open-ILS/xul/staff_client/chrome/content/util/print.js	2011-04-17 19:26:05 UTC (rev 20138)
@@ -292,6 +292,35 @@
                 }
             } catch(E) { dump(E+'\n'); }
 
+            // Substrings
+            try {
+                var match;
+                // Pre-trim inside of substrings, and only inside of them
+                // This keeps the trim commands from being truncated
+                var substr_trim_patt=/(%SUBSTR\(-?\d+,?\s*(-?\d+)?\)%.*?)(\s*%-TRIM%|%TRIM-%\s*)(.*?%SUBSTR_END%)/;
+                while(match = substr_trim_patt.exec(s))
+                    s = s.replace(match[0], match[1] + match[4]);
+                // Then do the substrings themselves
+                var substr_patt=/%SUBSTR\((-?\d+),?\s*(-?\d+)?\)%(.*?)%SUBSTR_END%/;
+                while(match = substr_patt.exec(s)) {
+                    var substring_start = parseInt(match[1]);
+                    if(substring_start < 0) substring_start = match[3].length + substring_start;
+                    var substring_length = parseInt(match[2]);
+                    if(substring_length > 0)
+                        s = s.replace(match[0], match[3].substring(substring_start, substring_start + substring_length));
+                    else if(substring_length < 0)
+                        s = s.replace(match[0], match[3].substring(substring_start + substring_length, substring_start));
+                    else
+                        s = s.replace(match[0], match[3].substring(substring_start));
+                }
+            } catch(E) { dump(E+'\n'); }
+
+            // Cleanup unwanted whitespace
+            try {
+                s = s.replace(/%TRIM-%\s*/g,'');
+                s = s.replace(/\s*%-TRIM%/g,'');
+            } catch(E) { dump(E+'\n'); }
+
             return s;
         } catch(E) {
             alert('Error in print.js, template_sub(): ' + E);



More information about the open-ils-commits mailing list