Skip to content

Commit

Permalink
Improved Lua View Engine
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleteti committed Oct 18, 2023
1 parent a73b634 commit 7774cc0
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions samples/serversideviews_lua/MVCFramework.View.Renderers.Lua.pas
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,16 @@ procedure TMVCLuaViewEngine.Execute(const ViewName: string;
const OutputStream: TStream);
var
Lua: TLuaEngine;
lDataSetName: string;
lDataSetName, lModelName: string;
lLuaFilter: TLuaEmbeddedTextFilter;
lViewFileName: String;
lFileName, lCompiledFileName: string;
lLuaCompiledCode: string;
lStreamReader: TStreamReader;
DecodeJSONStrings: string;
lSer: TMVCJsonDataObjectsSerializer;
lJSONStr: string;
lScriptOutput: TStreamWriter;
lJSON: TJDOJsonObject;
begin
lScriptOutput := TStreamWriter.Create(OutputStream, TEncoding.UTF8);
try
Expand Down Expand Up @@ -130,24 +130,35 @@ procedure TMVCLuaViewEngine.Execute(const ViewName: string;
{ continuare da questo problema }
if Assigned(ViewModel) then
begin
for lDataSetName in ViewModel.Keys do
begin
lJSON := TJDOJsonObject.Create;
try
lSer := TMVCJsonDataObjectsSerializer.Create(nil);
try
if TDuckTypedList.CanBeWrappedAsList(ViewModel[lDataSetName]) then
for lModelName in ViewModel.Keys do
begin
lJSONStr := lSer.SerializeCollection(ViewModel[lDataSetName]);
end
else
begin //PODO
lJSONStr := lSer.SerializeObject(ViewModel[lDataSetName]);
lJSON.Clear;
lSer.TValueToJSONObjectProperty(lJSON, lModelName, ViewModel[lModelName], TMVCSerializationType.stDefault, nil, nil);
// lJSONStr := lSer.SerializeCollection(ViewModel[lDataSetName]);
// if TDuckTypedList.CanBeWrappedAsList(ViewModel[lDataSetName]) then
// begin
// lJSONStr := lSer.SerializeCollection(ViewModel[lDataSetName]);
// end
// else
// begin //PODO
// lJSONStr := lSer.SerializeObject(ViewModel[lDataSetName]);
// end;
if lJSON.Values[lModelName].Typ = jdtArray then
Lua.DeclareGlobalString(lDataSetName, lJSON.A[lModelName].ToJSON())
else
Lua.DeclareGlobalString(lDataSetName, lJSON.O[lModelName].ToJSON());
DecodeJSONStrings := DecodeJSONStrings + sLineBreak + ' ' +
AnsiString(lDataSetName) + ' = json.decode(' + AnsiString(lDataSetName) + ')';
end;
finally
lSer.Free;
end;
Lua.DeclareGlobalString(lDataSetName, lJSONStr);
DecodeJSONStrings := DecodeJSONStrings + sLineBreak + ' ' +
AnsiString(lDataSetName) + ' = json.decode(' + AnsiString(lDataSetName) + ')';
finally
lJSON.Free;
end;
end;
end;
Expand Down

0 comments on commit 7774cc0

Please sign in to comment.