@@ -176,6 +176,19 @@ TUnitTemplateProHelpersDeclarationCommand = class(TCustomCommand)
176176 ); override;
177177 end ;
178178
179+ TUnitWebStencilsHelpersDeclarationCommand = class (TCustomCommand)
180+ public
181+ procedure ExecuteInterface (
182+ Section: TStringBuilder;
183+ Model: TJSONObject
184+ ); override;
185+ procedure ExecuteImplementation (
186+ Section: TStringBuilder;
187+ Model: TJsonObject
188+ ); override;
189+ end ;
190+
191+
179192
180193
181194 TUnitFooterCommand = class (TCustomCommand)
@@ -319,21 +332,18 @@ procedure TUnitProgramCommand.ExecuteInterface(
319332 .AppendLine(' MVCFramework.Commons,' )
320333 .AppendLine(' MVCFramework.Serializer.Commons,' );
321334
322- if Model.B[TConfigKey.program_ssv_templatepro] then
323- begin
324- Section
325- .AppendLine(' MVCFramework.View.Renderers.TemplatePro,' );
326- end ;
327335 if Model.B[TConfigKey.program_ssv_mustache] then
328336 begin
337+ { The Mustache units are required in the "program" because the mustache helpers are declared there.
338+ Should we create an external unit as we do in templatepro and webstencils }
329339 Section
330- .AppendLine(' MVCFramework.View.Renderers.Mustache,' )
331- .AppendLine(' mormot.core.mustache,' );
340+ .AppendLine(' MVCFramework.View.Renderers.Mustache,' )
341+ .AppendLine(' mormot.core.mustache,' );
332342 end ;
333343 if Model.B[TConfigKey.program_service_container_generate] then
334344 begin
335345 Section
336- .AppendLine(' MVCFramework.Container,' )
346+ .AppendLine(' MVCFramework.Container,' )
337347 end ;
338348 Section
339349 .AppendLine(' MVCFramework.Signal;' )
@@ -786,6 +796,13 @@ procedure TUnitWebModuleDeclarationCommand.ExecuteImplementation(
786796 .AppendLine(' MVCFramework.View.Renderers.TemplatePro,' )
787797 end ;
788798
799+ if Model.B[TConfigKey.program_ssv_webstencils] then
800+ begin
801+ Section
802+ .AppendLine(' MVCFramework.View.Renderers.WebStencils,' )
803+ end ;
804+
805+
789806 if Model.B[TConfigKey.program_ssv_mustache] then
790807 begin
791808 Section
@@ -846,6 +863,15 @@ procedure TUnitWebModuleDeclarationCommand.ExecuteImplementation(
846863 .AppendLine;
847864 end ;
848865
866+ if Model.B[TConfigKey.program_ssv_webstencils] then
867+ begin
868+ Section
869+ .AppendLine(' // Server Side View' )
870+ .AppendLine(' FMVC.SetViewEngine(TMVCWebStencilsViewEngine);' )
871+ .AppendLine(' // Server Side View - END' )
872+ .AppendLine;
873+ end ;
874+
849875 if Model.B[TConfigKey.program_ssv_mustache] then
850876 begin
851877 Section
@@ -1097,6 +1123,18 @@ procedure TUnitMainBeginEndCommand.ExecuteImplementation(Section: TStringBuilder
10971123 .AppendLine(' {$ENDIF}' )
10981124 .AppendLine;
10991125
1126+ if Model.B[TConfigKey.program_ssv_templatepro] then
1127+ begin
1128+ Section
1129+ .AppendLine(' TemplateProContextConfigure;' );
1130+ end ;
1131+
1132+ if Model.B[TConfigKey.program_ssv_webstencils] then
1133+ begin
1134+ Section
1135+ .AppendLine(' WebStencilsProcessorConfigure;' );
1136+ end ;
1137+
11001138 if Model.B[TConfigKey.program_ssv_mustache] then
11011139 begin
11021140 Section
@@ -1175,7 +1213,7 @@ procedure TUnitRunServerProcBody.ExecuteImplementation(Section: TStringBuilder;
11751213 .AppendLine(' LServer.MaxConnections := dotEnv.Env('' dmvc.webbroker.max_connections'' , 0);' )
11761214 .AppendLine(' LServer.ListenQueue := dotEnv.Env('' dmvc.indy.listen_queue'' , 500);' )
11771215 .AppendLine(' LServer.Active := True;' )
1178- .AppendLine(' LogI('' Listening on port '' + APort.ToString);' )
1216+ .AppendLine(' LogI('' Listening on http://localhost: '' + APort.ToString);' )
11791217 .AppendLine(' LogI('' Application started. Press Ctrl+C to shut down.'' );' )
11801218 .AppendLine(' WaitForTerminationSignal;' )
11811219 .AppendLine(' EnterInShutdownState;' )
@@ -1442,7 +1480,7 @@ procedure TUnitTemplateProHelpersDeclarationCommand.ExecuteInterface(
14421480 Section: TStringBuilder; Model: TJSONObject);
14431481begin
14441482 inherited ;
1445- CheckFor(TConfigKey.program_ssv_mustache , Model);
1483+ CheckFor(TConfigKey.program_ssv_templatepro , Model);
14461484 CheckFor(TConfigKey.templatepro_helpers_unit_name, Model);
14471485 Section
14481486 .AppendLine(' unit ' + Model[TConfigKey.templatepro_helpers_unit_name] + ' ;' )
@@ -1460,4 +1498,77 @@ procedure TUnitTemplateProHelpersDeclarationCommand.ExecuteInterface(
14601498 .AppendLine;
14611499end ;
14621500
1501+ { TUnitWebStencilsHelpersDeclarationCommand }
1502+
1503+ procedure TUnitWebStencilsHelpersDeclarationCommand.ExecuteImplementation (Section: TStringBuilder; Model: TJsonObject);
1504+ begin
1505+ inherited ;
1506+ Section
1507+ .AppendLine(' implementation' )
1508+ .AppendLine(' ' )
1509+ .AppendLine(' uses' )
1510+ .AppendLine(' System.SysUtils, MVCFramework.View.Renderers.WebStencils, System.Bindings.Methods, Web.Stencils;' )
1511+ .AppendLine(' ' )
1512+ .AppendLine(' ' )
1513+ .AppendLine(' function MyHelper1(const Parameters: TArray<IValue>): TValue;' )
1514+ .AppendLine(' begin' )
1515+ .AppendLine(' Result := Parameters[0].GetValue.ToString + '' (I'''' m The MyHelper1)'' ;' )
1516+ .AppendLine(' end;' )
1517+ .AppendLine(' ' )
1518+ .AppendLine(' function MyHelper2(const Parameters: TArray<IValue>): TValue;' )
1519+ .AppendLine(' begin' )
1520+ .AppendLine(' Result := Parameters[0].GetValue.ToString + '' (I'''' m The MyHelper2)'' ;' )
1521+ .AppendLine(' end;' )
1522+ .AppendLine(' ' )
1523+ .AppendLine(' procedure WebStencilsProcessorConfigure;' )
1524+ .AppendLine(' begin' )
1525+ .AppendLine(' TBindingMethodsFactory.RegisterMethod(' )
1526+ .AppendLine(' TMethodDescription.Create(' )
1527+ .AppendLine(' MakeInvokable(function(Args: TArray<IValue>): IValue' )
1528+ .AppendLine(' begin' )
1529+ .AppendLine(' Result := TValueWrapper.Create(MyHelper1(Args));' )
1530+ .AppendLine(' end),' )
1531+ .AppendLine(' '' MyHelper1'' , '' MyHelper1'' , '''' , True, '' MyHelper1 is just a sample'' , nil));' )
1532+ .AppendLine(' ' )
1533+ .AppendLine(' ' )
1534+ .AppendLine(' TBindingMethodsFactory.RegisterMethod(' )
1535+ .AppendLine(' TMethodDescription.Create(' )
1536+ .AppendLine(' MakeInvokable(function(Args: TArray<IValue>): IValue' )
1537+ .AppendLine(' begin' )
1538+ .AppendLine(' Result := TValueWrapper.Create(MyHelper2(Args));' )
1539+ .AppendLine(' end),' )
1540+ .AppendLine(' '' MyHelper2'' , '' MyHelper2'' , '''' , True, '' MyHelper2 is just a sample'' , nil));' )
1541+ .AppendLine(' ' )
1542+ .AppendLine(' TMVCWebStencilsConfiguration.OnProcessorConfiguration :=' )
1543+ .AppendLine(' procedure(const WebStencilsProcessor: TWebStencilsProcessor)' )
1544+ .AppendLine(' begin' )
1545+ .AppendLine(' //custom configuration for TWebStencilsProcessor (executed for each view)' )
1546+ .AppendLine(' end;' )
1547+ .AppendLine(' ' )
1548+ .AppendLine(' end;' )
1549+ .AppendLine(' ' )
1550+ .AppendLine(' end.' )
1551+ end ;
1552+
1553+ procedure TUnitWebStencilsHelpersDeclarationCommand.ExecuteInterface (Section: TStringBuilder; Model: TJSONObject);
1554+ begin
1555+ inherited ;
1556+ CheckFor(TConfigKey.program_ssv_webstencils, Model);
1557+ CheckFor(TConfigKey.webstencils_helpers_unit_name, Model);
1558+ Section
1559+ .AppendLine(' unit ' + Model[TConfigKey.webstencils_helpers_unit_name] + ' ;' )
1560+ .AppendLine
1561+ .AppendLine(' interface' )
1562+ .AppendLine
1563+ .AppendLine(' uses' )
1564+ .AppendLine(' System.Rtti, System.Bindings.EvalProtocol;' )
1565+ .AppendLine
1566+ .AppendLine(' function MyHelper1(const Parameters: TArray<IValue>): TValue;' )
1567+ .AppendLine(' function MyHelper2(const Parameters: TArray<IValue>): TValue;' )
1568+ .AppendLine
1569+ .AppendLine
1570+ .AppendLine(' procedure WebStencilsProcessorConfigure;' )
1571+ .AppendLine;
1572+ end ;
1573+
14631574end .
0 commit comments