Skip to content

Commit

Permalink
- Updated to TemplatePro 0.7.2 (with related changes)
Browse files Browse the repository at this point in the history
- REmoved some deprecated verloads of "TMVCController.Page" method
  • Loading branch information
danieleteti committed Nov 25, 2024
1 parent 8ecb4a1 commit b7b2556
Show file tree
Hide file tree
Showing 6 changed files with 457 additions and 107 deletions.
12 changes: 6 additions & 6 deletions ideexpert/DMVC.Expert.CodeGen.Commands.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1459,15 +1459,15 @@ procedure TUnitTemplateProHelpersDeclarationCommand.ExecuteImplementation(
.AppendLine('implementation')
.AppendLine
.AppendLine('uses')
.AppendLine(' TemplatePro, System.SysUtils;')
.AppendLine(' System.SysUtils;')
.AppendLine
.AppendLine
.AppendLine('function MyHelper1(const Value: TValue; const Parameters: TArray<string>): TValue;')
.AppendLine('function MyHelper1(const Value: TValue; const Parameters: TArray<TFilterParameter>): TValue;')
.AppendLine('begin')
.AppendLine(' Result := Value.ToString + '' (I''''m The MyHelper1)'';')
.AppendLine('end;')
.AppendLine
.AppendLine('function MyHelper2(const Value: TValue; const Parameters: TArray<string>): TValue;')
.AppendLine('function MyHelper2(const Value: TValue; const Parameters: TArray<TFilterParameter>): TValue;')
.AppendLine('begin')
.AppendLine(' Result := Value.ToString + '' (I''''m The MyHelper2)'';')
.AppendLine('end;')
Expand Down Expand Up @@ -1516,10 +1516,10 @@ procedure TUnitTemplateProHelpersDeclarationCommand.ExecuteInterface(
.AppendLine('interface')
.AppendLine
.AppendLine('uses')
.AppendLine(' System.Rtti;')
.AppendLine(' System.Rtti, TemplatePro;')
.AppendLine
.AppendLine('function MyHelper1(const Value: TValue; const Parameters: TArray<string>): TValue;')
.AppendLine('function MyHelper2(const Value: TValue; const Parameters: TArray<string>): TValue;')
.AppendLine('function MyHelper1(const Value: TValue; const Parameters: TArray<TFilterParameter>): TValue;')
.AppendLine('function MyHelper2(const Value: TValue; const Parameters: TArray<TFilterParameter>): TValue;')
.AppendLine
.AppendLine
.AppendLine('procedure TemplateProContextConfigure;')
Expand Down
1 change: 0 additions & 1 deletion packages/d120/dmvcframeworkRT.dpk
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ contains
MVCFramework.Middleware.ETag in '..\..\sources\MVCFramework.Middleware.ETag.pas',
MVCFramework.ActiveRecord in '..\..\sources\MVCFramework.ActiveRecord.pas',
MVCFramework.ActiveRecordController in '..\..\sources\MVCFramework.ActiveRecordController.pas',
MVCFramework.ApplicationSession in '..\..\sources\MVCFramework.ApplicationSession.pas',
MVCFramework.Cache in '..\..\sources\MVCFramework.Cache.pas',
MVCFramework.Commons in '..\..\sources\MVCFramework.Commons.pas',
MVCFramework.Console in '..\..\sources\MVCFramework.Console.pas',
Expand Down
1 change: 0 additions & 1 deletion packages/d120/dmvcframeworkRT.dproj
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@
<DCCReference Include="..\..\sources\MVCFramework.Middleware.ETag.pas"/>
<DCCReference Include="..\..\sources\MVCFramework.ActiveRecord.pas"/>
<DCCReference Include="..\..\sources\MVCFramework.ActiveRecordController.pas"/>
<DCCReference Include="..\..\sources\MVCFramework.ApplicationSession.pas"/>
<DCCReference Include="..\..\sources\MVCFramework.Cache.pas"/>
<DCCReference Include="..\..\sources\MVCFramework.Commons.pas"/>
<DCCReference Include="..\..\sources\MVCFramework.Console.pas"/>
Expand Down
23 changes: 19 additions & 4 deletions sources/MVCFramework.View.Renderers.TemplatePro.pas
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ implementation

{$WARNINGS OFF}

function GetDataSetOrObjectListCount(const aValue: TValue; const aParameters: TArray<string>): TValue;
function GetDataSetOrObjectListCount(const aValue: TValue; const aParameters: TArray<TFilterParameter>): TValue;
var
lWrappedList: IMVCList;
begin
Expand Down Expand Up @@ -89,7 +89,21 @@ function GetDataSetOrObjectListCount(const aValue: TValue; const aParameters: TA
end;
end;

function DumpAsJSONString(const aValue: TValue; const aParameters: TArray<string>): TValue;
function GetNow(const aValue: TValue; const aParameters: TArray<string>): TValue;
begin
if not aValue.IsEmpty then
begin
Exit('(Error: Now cannot be applied to a value)');
end;
if Length(aParameters) <> 0 then
begin
raise EMVCSSVException.Create('Expected 0 params, got ' + Length(aParameters).ToString);
end;
Result := Now();
end;


function DumpAsJSONString(const aValue: TValue; const aParameters: TArray<TFilterParameter>): TValue;
var
lWrappedList: IMVCList;
begin
Expand Down Expand Up @@ -193,16 +207,17 @@ procedure TMVCTemplateProViewEngine.Execute(const ViewName: string; const Builde
end;
lCompiledTemplate.AddFilter('json', DumpAsJSONString);
lCompiledTemplate.AddFilter('count', GetDataSetOrObjectListCount);
// lCompiledTemplate.AddFilter('now', GetNow);
lCompiledTemplate.AddFilter('fromquery',
function (const aValue: TValue; const aParameters: TArray<string>): TValue
function (const aValue: TValue; const aParameters: TArray<TFilterParameter>): TValue
begin
if not aValue.IsEmpty then
begin
raise ETProRenderException.Create('Filter "fromquery" cannot be applied to a value [HINT] Use {{:|fromquery,"parname"}}');
end;
if Length(aParameters) = 1 then
begin
Result := Self.WebContext.Request.QueryStringParam(aParameters[0]);
Result := Self.WebContext.Request.QueryStringParam(aParameters[0].ParStrText);
end
else
begin
Expand Down
17 changes: 0 additions & 17 deletions sources/MVCFramework.pas
Original file line number Diff line number Diff line change
Expand Up @@ -936,14 +936,6 @@ TMVCController = class(TMVCRenderer)
function Page(const AViewNames: TArray<string>; const UseCommonHeadersAndFooters: Boolean = True; const OnBeforeRenderCallback: TMVCSSVBeforeRenderCallback = nil): string; overload; inline;
function Page(const AViewName: string; const OnBeforeRenderCallback: TMVCSSVBeforeRenderCallback = nil): string; overload;

/// <summary>
/// Page calls GetRenderedView with sensible defaults.
/// Page method with UseCommonHeadersAndFooters = True (default) concatenates
// commonheader_header_views + views + commonfooter_views
/// </summary>
function Page(const AViewNames: TArray<string>; const JSONModel: TJSONObject;
const UseCommonHeadersAndFooters: Boolean = True; const OnBeforeRenderCallback: TMVCSSVBeforeRenderCallback = nil): string; overload; inline;

/// <summary>
/// Load mustache view located in TMVCConfigKey.ViewsPath
/// returns the rendered views and generates output using
Expand Down Expand Up @@ -4423,15 +4415,6 @@ procedure TMVCController.OnBeforeAction(AContext: TWebContext; const AActionName
{ Implement if need be. }
end;

function TMVCController.Page(const AViewNames: TArray<string>;
const JSONModel: TJSONObject; const UseCommonHeadersAndFooters: Boolean; const OnBeforeRenderCallback: TMVCSSVBeforeRenderCallback): string;
begin
if UseCommonHeadersAndFooters then
Result := GetRenderedView(fPageHeaders + AViewNames + fPageFooters, JSONModel, OnBeforeRenderCallback)
else
Result := GetRenderedView(AViewNames, JSONModel, OnBeforeRenderCallback)
end;

function TMVCController.Page(const AViewName: string; const OnBeforeRenderCallback: TMVCSSVBeforeRenderCallback): string;
begin
Result := GetRenderedView([AViewName], nil, OnBeforeRenderCallback);
Expand Down
Loading

0 comments on commit b7b2556

Please sign in to comment.