Added sample for nested and internal partials with Mustache

This commit is contained in:
Daniele Teti 2024-05-23 15:30:50 +02:00
parent cf08f46555
commit 1f06210979
7 changed files with 30 additions and 14 deletions

View File

@ -82,7 +82,7 @@ begin
RunServer(dotEnv.Env('dmvc.server.port', 8080));
except
on E: Exception do
LogI(E.ClassName + ': ' + E.Message);
LogE(E.ClassName + ': ' + E.Message);
end;
end.

View File

@ -177,6 +177,7 @@
<Platforms>
<Platform value="Android">False</Platform>
<Platform value="Android64">True</Platform>
<Platform value="Linux64">False</Platform>
<Platform value="Win32">True</Platform>
<Platform value="Win64">False</Platform>
</Platforms>

View File

@ -6,6 +6,7 @@ uses
System.SysUtils,
MVCFramework,
MVCFramework.Signal,
MVCFramework.Logger,
{$IFDEF MSWINDOWS}
Winapi.ShellAPI,
Winapi.Windows,
@ -29,7 +30,7 @@ var
LServer: TIdHTTPWebBrokerBridge;
begin
ReportMemoryLeaksOnShutdown := True;
Writeln(Format('Starting HTTP Server on port %d', [APort]));
LogI(Format('Starting HTTP Server on port %d', [APort]));
LServer := TIdHTTPWebBrokerBridge.Create(nil);
try
LServer.DefaultPort := APort;
@ -37,7 +38,7 @@ begin
{$IFDEF MSWINDOWS}
ShellExecute(0, 'open', PChar('http://localhost:' + inttostr(APort)), nil, nil, SW_SHOW);
{$ENDIF}
Write('Ctrl+C to stop the server');
LogI('Ctrl+C to stop the server');
WaitForTerminationSignal;
EnterInShutdownState;
LServer.Active := False;
@ -62,7 +63,7 @@ begin
RunServer(8080);
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
LogE(E.ClassName + ': ' + E.Message);
end;
end.

View File

@ -0,0 +1 @@
Nested Partial >> {{>partial_person}}

View File

@ -70,13 +70,34 @@ This page is a showcase for all the mustache features usable from DMVCFramework
</div>
</div>
{{<internal_partial}}
{{first_name}}, {{last_name}} (this is an internal partial (extension of dmustache))
{{/internal_partial}}
<div>
<h2 class="section">Handling partials</h2>
<div>
<h2><pre>Using >partial_person.mustache</pre></h2>
<ul>
{{#people}}
<li>{{>partial_person}}</li>
{{/people}}
</ul>
</div>
<div>
<h2><pre>Using >partial_person2.mustache</pre></h2>
<ul>
{{#people}}
<li>{{>partial_person2}}</li>
{{/people}}
</ul>
</div>
<div>
<h2><pre>Using &lt;internal_partial</pre></h2>
<ul>
{{#people}}
<li>{{>internal_partial}}</li>
{{/people}}
</ul>
</div>
</div>

View File

@ -1872,14 +1872,14 @@ begin
begin
if not Assigned(GdotEnvDelegate) then
begin
LogI('dotEnvConfigure not called, a default dotEnv instance will be created');
LogI('Initializing default dotEnv instance');
GdotEnv := NewDotEnv
.UseStrategy(TMVCDotEnvPriority.FileThenEnv)
.UseProfile('test')
.UseProfile('prod')
.UseLogger(procedure(LogItem: String)
begin
LogD('dotEnv: ' + LogItem);
LogI('dotEnv: ' + LogItem);
end)
.Build();
end

View File

@ -252,14 +252,6 @@ begin
TMVCJsonDataObjectsSerializer(lSer).TValueToJSONObjectProperty(lJSONModel, DataObj.Key, DataObj.Value, TMVCSerializationType.stDefault, nil, nil);
end;
end;
// if Assigned(ViewDataSets) then
// begin
// for lDSPair in ViewDataSets do
// begin
// TMVCJsonDataObjectsSerializer(lSer).DataSetToJsonArray(lDSPair.Value, lJSONModel.A[lDSPair.Key], TMVCNameCase.ncAsIs, nil);
// end;
// end;
FJSONModelAsString := lJSONModel.ToJSON(False);
finally
lJSONModel.Free;