-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodules.translationcontroller.pas
More file actions
71 lines (60 loc) · 2.15 KB
/
Copy pathmodules.translationcontroller.pas
File metadata and controls
71 lines (60 loc) · 2.15 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
unit modules.translationcontroller;
interface
uses
System.SysUtils,
System.IOutils,
Web.HTTPApp,
Web.Stencils;
type
TTranslationController = class
private
FWebStencilsProcessor: TWebStencilsProcessor;
FWebStencilsEngine: TWebStencilsEngine;
function RenderTemplate(ATemplate: string): string;
procedure AddRouting;
public
procedure TranslateText(Sender: TObject; Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
constructor Create(AWebStencilsEngine: TWebStencilsEngine);
destructor Destroy; override;
end;
implementation
function TTranslationController.RenderTemplate(ATemplate: string): string;
begin
FWebStencilsProcessor.InputFileName := TPath.Combine(FWebStencilsEngine.rootDirectory, 'customers/' + ATemplate + '.html');
Result := FWebStencilsProcessor.Content;
end;
procedure TTranslationController.AddRouting;
begin
// AddRoutes([TRoute.Create(mtDelete, '/tasks', FTasksController.DeleteTask),
// TRoute.Create(mtPost, '/tasks/add', FTasksController.CreateTask),
// TRoute.Create(mtGet, '/tasks/edit', FTasksController.GetEditTask),
// TRoute.Create(mtPut, '/tasks/toggleCompleted', FTasksController.TogglecompletedTask),
// TRoute.Create(mtPut, '/tasks', FTasksController.EditTask),
// // Customers routes
// TRoute.Create(mtGet, '/bigtable', FCustomersController.GetAllCustomers),
// TRoute.Create(mtGet, '/pagination', FCustomersController.GetCustomers)
// ]);
end;
constructor TTranslationController.Create(AWebStencilsEngine: TWebStencilsEngine);
begin
inherited Create;
try
FWebStencilsEngine := AWebStencilsEngine;
FWebStencilsProcessor := TWebStencilsProcessor.Create(nil);
FWebStencilsProcessor.Engine := FWebStencilsEngine;
except
on E: Exception do
WriteLn('TTranslationController.Create: ' + E.Message);
end;
end;
destructor TTranslationController.Destroy;
begin
FWebStencilsProcessor.Free;
inherited;
end;
procedure TTranslationController.TranslateText(Sender: TObject; Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
begin
Response.Content := RenderTemplate('bigtable');
Handled := True;
end;
end.