Revision f623b721
Von Moritz Bunkus vor mehr als 10 Jahren hinzugefügt
SL/Template/Plugin/KiviLatex.pm | ||
---|---|---|
1 |
package SL::Template::Plugin::KiviLatex; |
|
2 |
|
|
3 |
use strict; |
|
4 |
use parent qw( Template::Plugin::Filter ); |
|
5 |
|
|
6 |
my $cached_instance; |
|
7 |
|
|
8 |
sub new { |
|
9 |
my $class = shift; |
|
10 |
|
|
11 |
return $cached_instance ||= $class->SUPER::new(@_); |
|
12 |
} |
|
13 |
|
|
14 |
sub init { |
|
15 |
my $self = shift; |
|
16 |
|
|
17 |
$self->install_filter($self->{ _ARGS }->[0] || 'KiviLatex'); |
|
18 |
|
|
19 |
return $self; |
|
20 |
} |
|
21 |
|
|
22 |
sub filter { |
|
23 |
my ($self, $text, $args) = @_; |
|
24 |
return $::locale->quote_special_chars('Template/LaTeX', $text); |
|
25 |
} |
|
26 |
|
|
27 |
my %html_replace = ( |
|
28 |
'</p>' => "\n\n", |
|
29 |
'<ul>' => "\\begin{itemize} ", |
|
30 |
'</ul>' => "\\end{itemize} ", |
|
31 |
'<ol>' => "\\begin{enumerate} ", |
|
32 |
'</ol>' => "\\end{enumerate} ", |
|
33 |
'<li>' => "\\item ", |
|
34 |
'</li>' => " ", |
|
35 |
'<b>' => "\\textbf{", |
|
36 |
'</b>' => "}", |
|
37 |
'<strong>' => "\\textbf{", |
|
38 |
'</strong>' => "}", |
|
39 |
'<i>' => "\\textit{", |
|
40 |
'</i>' => "}", |
|
41 |
'<em>' => "\\textit{", |
|
42 |
'</em>' => "}", |
|
43 |
'<u>' => "\\underline{", |
|
44 |
'</u>' => "}", |
|
45 |
'<s>' => "\\sout{", |
|
46 |
'</s>' => "}", |
|
47 |
'<sub>' => "\\textsubscript{", |
|
48 |
'</sub>' => "}", |
|
49 |
'<sup>' => "\\textsuperscript{", |
|
50 |
'</sup>' => "}", |
|
51 |
'<br/>' => "\\newline ", |
|
52 |
'<br>' => "\\newline ", |
|
53 |
); |
|
54 |
|
|
55 |
sub filter_html { |
|
56 |
my ($self, $text, $args) = @_; |
|
57 |
|
|
58 |
$text =~ s{ \r+ }{}gx; |
|
59 |
$text =~ s{ \n+ }{ }gx; |
|
60 |
$text =~ s{ (?:\ |\s)+ }{ }gx; |
|
61 |
|
|
62 |
my @parts = map { |
|
63 |
if (substr($_, 0, 1) eq '<') { |
|
64 |
s{ +}{}g; |
|
65 |
$html_replace{$_} || ''; |
|
66 |
|
|
67 |
} else { |
|
68 |
$::locale->quote_special_chars('Template/LaTeX', HTML::Entities::decode_entities($_)); |
|
69 |
} |
|
70 |
} split(m{(<.*?>)}x, $text); |
|
71 |
|
|
72 |
return join('', @parts); |
|
73 |
} |
|
74 |
|
|
75 |
return 'SL::Template::Plugin::KiviLatex'; |
SL/Template/Plugin/LxLatex.pm | ||
---|---|---|
1 |
package SL::Template::Plugin::LxLatex; |
|
2 |
|
|
3 |
use strict; |
|
4 |
use parent qw( Template::Plugin::Filter ); |
|
5 |
|
|
6 |
my $cached_instance; |
|
7 |
|
|
8 |
sub new { |
|
9 |
my $class = shift; |
|
10 |
|
|
11 |
return $cached_instance ||= $class->SUPER::new(@_); |
|
12 |
} |
|
13 |
|
|
14 |
sub init { |
|
15 |
my $self = shift; |
|
16 |
|
|
17 |
$self->install_filter($self->{ _ARGS }->[0] || 'LxLatex'); |
|
18 |
|
|
19 |
return $self; |
|
20 |
} |
|
21 |
|
|
22 |
sub filter { |
|
23 |
my ($self, $text, $args) = @_; |
|
24 |
return $::locale->quote_special_chars('Template/LaTeX', $text); |
|
25 |
} |
|
26 |
|
|
27 |
my %html_replace = ( |
|
28 |
'</p>' => "\n\n", |
|
29 |
'<ul>' => "\\begin{itemize} ", |
|
30 |
'</ul>' => "\\end{itemize} ", |
|
31 |
'<ol>' => "\\begin{enumerate} ", |
|
32 |
'</ol>' => "\\end{enumerate} ", |
|
33 |
'<li>' => "\\item ", |
|
34 |
'</li>' => " ", |
|
35 |
'<b>' => "\\textbf{", |
|
36 |
'</b>' => "}", |
|
37 |
'<strong>' => "\\textbf{", |
|
38 |
'</strong>' => "}", |
|
39 |
'<i>' => "\\textit{", |
|
40 |
'</i>' => "}", |
|
41 |
'<em>' => "\\textit{", |
|
42 |
'</em>' => "}", |
|
43 |
'<u>' => "\\underline{", |
|
44 |
'</u>' => "}", |
|
45 |
'<s>' => "\\sout{", |
|
46 |
'</s>' => "}", |
|
47 |
'<sub>' => "\\textsubscript{", |
|
48 |
'</sub>' => "}", |
|
49 |
'<sup>' => "\\textsuperscript{", |
|
50 |
'</sup>' => "}", |
|
51 |
'<br/>' => "\\newline ", |
|
52 |
'<br>' => "\\newline ", |
|
53 |
); |
|
54 |
|
|
55 |
sub filter_html { |
|
56 |
my ($self, $text, $args) = @_; |
|
57 |
|
|
58 |
$text =~ s{ \r+ }{}gx; |
|
59 |
$text =~ s{ \n+ }{ }gx; |
|
60 |
$text =~ s{ (?:\ |\s)+ }{ }gx; |
|
61 |
|
|
62 |
my @parts = map { |
|
63 |
if (substr($_, 0, 1) eq '<') { |
|
64 |
s{ +}{}g; |
|
65 |
$html_replace{$_} || ''; |
|
66 |
|
|
67 |
} else { |
|
68 |
$::locale->quote_special_chars('Template/LaTeX', HTML::Entities::decode_entities($_)); |
|
69 |
} |
|
70 |
} split(m{(<.*?>)}x, $text); |
|
71 |
|
|
72 |
return join('', @parts); |
|
73 |
} |
|
74 |
|
|
75 |
return 'SL::Template::Plugin::LxLatex'; |
templates/print/Standard/requirement_spec.tex | ||
---|---|---|
1 | 1 |
% config: use-template-toolkit=1 |
2 | 2 |
% config: tag-style=$( )$ |
3 |
$( USE LxLatex )$
|
|
3 |
$( USE KiviLatex )$
|
|
4 | 4 |
$( USE P )$ |
5 | 5 |
\documentclass{scrartcl} |
6 | 6 |
|
... | ... | |
14 | 14 |
\renewcommand{\kivitendosecondfoot}{% |
15 | 15 |
\parbox{12cm}{% |
16 | 16 |
\defaultfont\scriptsize% |
17 |
$( LxLatex.filter(rspec.displayable_name) )$\\
|
|
17 |
$( KiviLatex.filter(rspec.displayable_name) )$\\
|
|
18 | 18 |
$( !rspec.version ? "Arbeitskopie ohne Version" : "Version " _ rspec.version.version_number _ " vom " _ rspec.version.itime.to_kivitendo(precision='minute') )$ |
19 | 19 |
|
20 | 20 |
\vspace*{0.2cm}% |
... | ... | |
35 | 35 |
\put(3.5,-5){% |
36 | 36 |
\begin{minipage}[t][6cm]{12cm} |
37 | 37 |
\Large |
38 |
\textcolor{kivitendodarkred}{$( LxLatex.filter(rspec.type.description) )$}
|
|
38 |
\textcolor{kivitendodarkred}{$( KiviLatex.filter(rspec.type.description) )$}
|
|
39 | 39 |
|
40 | 40 |
\huge |
41 |
$( LxLatex.filter(rspec.customer.name) )$
|
|
41 |
$( KiviLatex.filter(rspec.customer.name) )$
|
|
42 | 42 |
|
43 | 43 |
\vspace*{0.5cm} |
44 | 44 |
\Large |
45 |
$( LxLatex.filter(rspec.title) )$
|
|
45 |
$( KiviLatex.filter(rspec.title) )$
|
|
46 | 46 |
\normalsize |
47 | 47 |
%$( IF rspec.version )$ |
48 | 48 |
|
49 |
Version $( LxLatex.filter(rspec.version.version_number) )$
|
|
49 |
Version $( KiviLatex.filter(rspec.version.version_number) )$
|
|
50 | 50 |
%$( END )$ |
51 | 51 |
\end{minipage}% |
52 | 52 |
} |
... | ... | |
77 | 77 |
\small Beschreibung\\ |
78 | 78 |
\hline |
79 | 79 |
%$( FOREACH versioned_copy = versioned_copies )$ |
80 |
\multicolumn{1}{|r}{\small $( LxLatex.filter(versioned_copy.version.version_number) )$} &
|
|
81 |
\multicolumn{1}{|r|}{\small $( LxLatex.filter(versioned_copy.version.itime.to_kivitendo(precision='minute')) )$} &
|
|
82 |
\small $( LxLatex.filter(versioned_copy.version.description) )$\\
|
|
80 |
\multicolumn{1}{|r}{\small $( KiviLatex.filter(versioned_copy.version.version_number) )$} &
|
|
81 |
\multicolumn{1}{|r|}{\small $( KiviLatex.filter(versioned_copy.version.itime.to_kivitendo(precision='minute')) )$} &
|
|
82 |
\small $( KiviLatex.filter(versioned_copy.version.description) )$\\
|
|
83 | 83 |
%$( END )$ |
84 | 84 |
\hline |
85 | 85 |
\end{longtable} |
... | ... | |
92 | 92 |
\centering |
93 | 93 |
\includegraphics[width=$( width_cm )$cm,keepaspectratio]{$( picture.print_file_name )$} |
94 | 94 |
|
95 |
\mbox{Abbildung $( picture.number )$: $( LxLatex.filter(picture.description ? picture.description : picture.picture_file_name) )$}
|
|
95 |
\mbox{Abbildung $( picture.number )$: $( KiviLatex.filter(picture.description ? picture.description : picture.picture_file_name) )$}
|
|
96 | 96 |
\end{figure} |
97 | 97 |
%$( END )$ |
98 | 98 |
|
... | ... | |
106 | 106 |
|
107 | 107 |
% $( FOREACH text_block = text_blocks )$ |
108 | 108 |
|
109 |
\subsection{$( LxLatex.filter(text_block.title) )$}
|
|
109 |
\subsection{$( KiviLatex.filter(text_block.title) )$}
|
|
110 | 110 |
|
111 |
$( LxLatex.filter_html(text_block.text_as_restricted_html) )$
|
|
111 |
$( KiviLatex.filter_html(text_block.text_as_restricted_html) )$
|
|
112 | 112 |
|
113 | 113 |
% $( FOREACH picture = text_block.pictures_sorted.as_list )$ |
114 | 114 |
$( PROCESS picture_outputter picture=picture )$ |
... | ... | |
131 | 131 |
|
132 | 132 |
%$( FOREACH top_item = rspec.sections_sorted )$ |
133 | 133 |
|
134 |
\subsection{Abschnitt $( LxLatex.filter(top_item.fb_number) )$: $( LxLatex.filter(top_item.title) )$}
|
|
134 |
\subsection{Abschnitt $( KiviLatex.filter(top_item.fb_number) )$: $( KiviLatex.filter(top_item.title) )$}
|
|
135 | 135 |
|
136 | 136 |
% $( IF top_item.description )$ |
137 |
$( LxLatex.filter_html(top_item.description_as_restricted_html.replace('\r', '').replace('\n+\Z', '')) )$
|
|
137 |
$( KiviLatex.filter_html(top_item.description_as_restricted_html.replace('\r', '').replace('\n+\Z', '')) )$
|
|
138 | 138 |
|
139 | 139 |
\vspace{0.5cm} |
140 | 140 |
% $( END )$ |
... | ... | |
142 | 142 |
\parbox[t]{1.0cm}{\textcolor{kivitendodarkred}{$>>>$}}% |
143 | 143 |
\parbox[t]{15.0cm}{% |
144 | 144 |
\begin{longtable}{p{2.8cm}p{11.7cm}} |
145 |
Funktionsblock & $( LxLatex.filter(item.fb_number) )$\\
|
|
146 |
Beschreibung & $( LxLatex.filter_html(item.description_as_restricted_html) )$\\
|
|
147 |
Abhängigkeiten & $( LxLatex.filter(P.requirement_spec_item_dependency_list(item)) )$
|
|
145 |
Funktionsblock & $( KiviLatex.filter(item.fb_number) )$\\
|
|
146 |
Beschreibung & $( KiviLatex.filter_html(item.description_as_restricted_html) )$\\
|
|
147 |
Abhängigkeiten & $( KiviLatex.filter(P.requirement_spec_item_dependency_list(item)) )$
|
|
148 | 148 |
\end{longtable}} |
149 | 149 |
|
150 | 150 |
% $( FOREACH sub_item = item.children_sorted )$ |
... | ... | |
152 | 152 |
\hspace*{1.0cm}% |
153 | 153 |
\parbox[t]{15.0cm}{% |
154 | 154 |
\begin{longtable}{p{2.8cm}p{11.7cm}} |
155 |
Unterfunktionsblock & $( LxLatex.filter(sub_item.fb_number) )$\\
|
|
156 |
Beschreibung & $( LxLatex.filter_html(sub_item.description_as_restricted_html) )$\\
|
|
157 |
Abhängigkeiten & $( LxLatex.filter(P.requirement_spec_item_dependency_list(sub_item)) )$
|
|
155 |
Unterfunktionsblock & $( KiviLatex.filter(sub_item.fb_number) )$\\
|
|
156 |
Beschreibung & $( KiviLatex.filter_html(sub_item.description_as_restricted_html) )$\\
|
|
157 |
Abhängigkeiten & $( KiviLatex.filter(P.requirement_spec_item_dependency_list(sub_item)) )$
|
|
158 | 158 |
\end{longtable}} |
159 | 159 |
|
160 | 160 |
% $( END )$ |
Auch abrufbar als: Unified diff
Plugin LxLatex in KiviLatex umbenannt