Die Variable "ranking" für Zahlungsbedinungen konnte nirgends konfiguriert werden...
[kivitendo-erp.git] / SL / Template.pm
index 3d4b8f9..297c025 100644 (file)
@@ -158,8 +158,6 @@ sub substitute_vars {
     my ($var, @options) = split(/\s+/, $1);
     my $value = $form->{$var};
 
-    $main::lxdebug->message(0, "REPL var: $1");
-
     for (my $i = 0; $i < scalar(@indices); $i++) {
       last unless (ref($value) eq "ARRAY");
       $value = $value->[$indices[$i]];
@@ -402,6 +400,52 @@ sub parse_first_line {
   return 1;
 }
 
+sub _parse_config_option {
+  my $self = shift;
+  my $line = shift;
+
+  $line =~ s/^\s*//;
+  $line =~ s/\s*$//;
+
+  my ($key, $value) = split m/\s*=\s*/, $line, 2;
+
+  if ($key eq 'tag-style') {
+    $self->set_tag_style(split(m/\s+/, $value, 2));
+  }
+}
+
+sub _parse_config_lines {
+  my $self  = shift;
+  my $lines = shift;
+
+  my ($comment_start, $comment_end) = ("", "");
+
+  if (ref $self eq 'LaTeXTemplate') {
+    $comment_start = '\s*%';
+  } elsif (ref $self eq 'HTMLTemplate') {
+    $comment_start = '\s*<!--';
+    $comment_end   = '>\s*';
+  } else {
+    $comment_start = '\s*\#';
+  }
+
+  my $num_lines = scalar @{ $lines };
+  my $i         = 0;
+
+  while ($i < $num_lines) {
+    my $line = $lines->[$i];
+
+    if ($line !~ m/^${comment_start}\s*config\s*:(.*)${comment_end}$/i) {
+      $i++;
+      next;
+    }
+
+    $self->_parse_config_option($1);
+    splice @{ $lines }, $i, 1;
+    $num_lines--;
+  }
+}
+
 sub parse {
   my $self = $_[0];
   local *OUT = $_[1];
@@ -414,7 +458,7 @@ sub parse {
   my @lines = <IN>;
   close(IN);
 
-  return 0 if (!$self->parse_first_line($lines[0]));
+  $self->_parse_config_lines(\@lines);
 
   my $contents = join("", @lines);
 
@@ -459,7 +503,7 @@ sub convert_to_postscript {
     return 0;
   }
 
-  $form->{tmpfile} =~ s/$userspath\///g;
+  $form->{tmpfile} =~ s/\Q$userspath\E\///g;
 
   for (my $run = 1; $run <= 2; $run++) {
     system("latex --interaction=nonstopmode $form->{tmpfile} " .
@@ -498,7 +542,7 @@ sub convert_to_pdf {
     return 0;
   }
 
-  $form->{tmpfile} =~ s/$userspath\///g;
+  $form->{tmpfile} =~ s/\Q$userspath\E\///g;
 
   for (my $run = 1; $run <= 2; $run++) {
     system("pdflatex --interaction=nonstopmode $form->{tmpfile} " .
@@ -606,7 +650,7 @@ sub convert_to_postscript {
     return 0;
   }
 
-  $form->{"tmpfile"} =~ s/$userspath\///g;
+  $form->{"tmpfile"} =~ s/\Q$userspath\E\///g;
   my $psfile = $form->{"tmpfile"};
   $psfile =~ s/.html/.ps/;
   if ($psfile eq $form->{"tmpfile"}) {
@@ -639,7 +683,7 @@ sub convert_to_pdf {
     return 0;
   }
 
-  $form->{"tmpfile"} =~ s/$userspath\///g;
+  $form->{"tmpfile"} =~ s/\Q$userspath\E\///g;
   my $pdffile = $form->{"tmpfile"};
   $pdffile =~ s/.html/.pdf/;
   if ($pdffile eq $form->{"tmpfile"}) {