Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 6b321c53

Von Udo Spallek vor mehr als 18 Jahren hinzugefügt

  • ID 6b321c53c6fe735d29851ae988950ada875ff46e
  • Vorgänger c37ba3b6
  • Nachfolger 5ff43c98

Vorbereitungen zu den Variablenanpassungen.
Die alte Variablensyntax ist nun zentral in der parse_template veraenderbar:
$pre ist die linke Einklammerung vor der Variablen: <%
$suf ist die rechte Einklammerung nach der Variablen: %>
Voreinstellung wie gehabt.

Unterschiede anzeigen:

SL/Form.pm
751 751
  my $sum       = 0;
752 752
  # } Moritz Bunkus
753 753

  
754
  # The old fixed notation of <%variable%> is changed to a new dynamic one.
755
  my ${pre} = '<%'; # Variable Prefix, must be regex save!
756
  my ${suf} = '%>'; # Variable Suffix, must be regex save!
757

  
758

  
754 759
  # Make sure that all *notes* (intnotes, partnotes_*, notes etc) are converted to markup correctly.
755 760
  $self->format_string(grep(/notes/, keys(%{$self})));
756 761

  
......
789 794
  $two_passes = 0;
790 795

  
791 796
  # first we generate a tmpfile
792
  # read file and replace <%variable%>
797
  # read file and replace ${pre}variable${suf}
793 798
  while ($_ = shift) {
794 799

  
795 800
    $par = "";
796 801
    $var = $_;
797 802
 
798
    # Switch <%analyse%> for template checking
799
    # If <%analyse%> is set in the template, you'll find the 
803
    # Switch ${pre}analyse${suf} for template checking
804
    # If ${pre}analyse${suf} is set in the template, you'll find the 
800 805
    # parsed output in the user Directory for analysing
801 806
    # Latex errors
802
    # <%analyse%> is a switch (allways off, on if set), not a Variable
807
    # ${pre}analyse${suf} is a switch (allways off, on if set), not a Variable
803 808
    # Set $form->{analysing}="" for system state: never analyse.
804 809
    # Set $form->{analysing}="1" for system state: ever analyse.
805
    $self->{analysing} = "1" if (/<%analyse%>/ && !defined $self->{analysing});    
810
    $self->{analysing} = "1" if (/${pre}analyse${suf}/ && !defined $self->{analysing});    
806 811
    
807 812
    $two_passes = 1 if (/\\pageref/);
808 813

  
809 814
    # { Moritz Bunkus
810 815
    # detect pagebreak block and its parameters
811
    if (/\s*<%pagebreak ([0-9]+) ([0-9]+) ([0-9]+)%>/) {
816
    if (/\s*${pre}pagebreak ([0-9]+) ([0-9]+) ([0-9]+)${suf}/) {
812 817
      $chars_per_line       = $1;
813 818
      $lines_on_first_page  = $2;
814 819
      $lines_on_second_page = $3;
815 820

  
816 821
      while ($_ = shift) {
817
        last if (/\s*<%end pagebreak%>/);
822
        last if (/\s*${pre}end pagebreak${suf}/);
818 823
        $pagebreak .= $_;
819 824
      }
820 825
    }
821 826

  
822 827
    # } Moritz Bunkus
823

  
824
    if (/\s*<%foreach /) {
828
    
829
    if (/\s*${pre}foreach /) {
825 830

  
826 831
      # this one we need for the count
827 832
      chomp $var;
828
      $var =~ s/\s*<%foreach (.+?)%>/$1/;
833
      $var =~ s/\s*${pre}foreach (.+?)${suf}/$1/;
829 834
      while ($_ = shift) {
830
        last if (/\s*<%end /);
835
        last if (/\s*${pre}end /);
831 836

  
832 837
        # store line in $par
833 838
        $par .= $_;
......
838 843

  
839 844
        # { Moritz Bunkus
840 845
        # Try to detect whether a manual page break is necessary
841
        # but only if there was a <%pagebreak ...%> block before
846
        # but only if there was a ${pre}pagebreak ...${suf} block before
842 847

  
843 848
        if ($chars_per_line) {
844 849
          my $lines =
......
866 871
            ) {
867 872
            my $pb = $pagebreak;
868 873

  
869
            # replace the special variables <%sumcarriedforward%>
870
            # and <%lastpage%>
874
            # replace the special variables ${pre}sumcarriedforward${suf}
875
            # and ${pre}lastpage${suf}
871 876

  
872 877
            my $psum = $self->format_amount($myconfig, $sum, 2);
873
            $pb =~ s/<%sumcarriedforward%>/$psum/g;
874
            $pb =~ s/<%lastpage%>/$current_page/g;
878
            $pb =~ s/${pre}sumcarriedforward${suf}/$psum/g;
879
            $pb =~ s/${pre}lastpage${suf}/$current_page/g;
875 880

  
876 881
            # only "normal" variables are supported here
877
            # (no <%if, no <%foreach, no <%include)
882
            # (no ${pre}if, no ${pre}foreach, no ${pre}include)
878 883

  
879
            $pb =~ s/<%(.+?)%>/$self->{$1}/g;
884
            $pb =~ s/${pre}(.+?)${suf}/$self->{$1}/g;
880 885

  
881 886
            # page break block is ready to rock
882 887
            print(OUT $pb);
......
892 897

  
893 898
        # don't parse par, we need it for each line
894 899
        $_ = $par;
895
        s/<%(.+?)%>/$self->{$1}[$i]/mg;
900
        s/${pre}(.+?)${suf}/$self->{$1}[$i]/mg;
896 901
        print OUT;
897 902
      }
898 903
      next;
899 904
    }
900 905

  
901 906
    # if not comes before if!
902
    if (/\s*<%if not /) {
907
    if (/\s*${pre}if not /) {
903 908

  
904 909
      # check if it is not set and display
905 910
      chop;
906
      s/\s*<%if not (.+?)%>/$1/;
911
      s/\s*${pre}if not (.+?)${suf}/$1/;
907 912

  
908 913
      unless ($self->{$_}) {
909 914
        while ($_ = shift) {
910
          last if (/\s*<%end /);
915
          last if (/\s*${pre}end /);
911 916

  
912 917
          # store line in $par
913 918
          $par .= $_;
......
917 922

  
918 923
      } else {
919 924
        while ($_ = shift) {
920
          last if (/\s*<%end /);
925
          last if (/\s*${pre}end /);
921 926
        }
922 927
        next;
923 928
      }
924 929
    }
925 930

  
926
    if (/\s*<%if /) {
931
    if (/\s*${pre}if /) {
927 932

  
928 933
      # check if it is set and display
929 934
      chop;
930
      s/\s*<%if (.+?)%>/$1/;
935
      s/\s*${pre}if (.+?)${suf}/$1/;
931 936

  
932 937
      if ($self->{$_}) {
933 938
        while ($_ = shift) {
934
          last if (/\s*<%end /);
939
          last if (/\s*${pre}end /);
935 940

  
936 941
          # store line in $par
937 942
          $par .= $_;
......
941 946

  
942 947
      } else {
943 948
        while ($_ = shift) {
944
          last if (/\s*<%end /);
949
          last if (/\s*${pre}end /);
945 950
        }
946 951
        next;
947 952
      }
948 953
    }
949 954

  
950
    # check for <%include filename%>
951
    if (/\s*<%include /) {
955
    # check for ${pre}include filename${suf}
956
    if (/\s*${pre}include /) {
952 957

  
953 958
      # get the directory/filename
954 959
      chomp $var;
955
      $var =~ s/\s*<%include (.+?)%>/$1/;
960
      $var =~ s/\s*${pre}include (.+?)${suf}/$1/;
956 961

  
957 962
      # mangle filename on basedir
958 963
      $var =~ s/^(\/|\.\.)//g;
......
970 975
      next;
971 976
    }
972 977

  
973
    s/<%(.+?)%>/$self->{$1}/g;
978
    s/${pre}(.+?)${suf}/$self->{$1}/g;
974 979
    s/<nobr><\/nobr>/&nbsp;/g;
975 980
    print OUT;
976 981
  }

Auch abrufbar als: Unified diff