1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
{ Functions for applyting variables to html templates }
unit replacers;
{$mode ObjFPC}{$H+}
interface
uses
Classes, SysUtils;
{ Sets in HTML template str value of variable to string value }
function applyVar(str, variable, value : string) : string;
{ Writes <img> tag with given source and alt text }
function applyImage(str, variable, source, alt: string): string;
{ Writes <a href with givent source and text }
function applyFileLink(str, variable, source, txt : string) : string;
implementation
function applyVar(str, variable, value: string): string;
begin
Result:=StringReplace(str, '{'+variable+'}', value, [rfReplaceAll]);
end;
function applyImage(str, variable, source, alt: string): string;
begin
Result:=StringReplace(str, '(('+variable+'))',
'<img src="' + source + '" alt="'+alt+'" >', [rfReplaceAll]);
end;
function applyFileLink(str, variable, source, txt: string): string;
begin
Result:=StringReplace(str, '||'+variable+'||',
'<a href="' + source + '" download>'+txt+'</a>', [rfReplaceAll]);
end;
end.
|