Skip to content

Commit

Permalink
updated template pro
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleteti committed Dec 16, 2024
1 parent 7569e13 commit 9ee2f5a
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 100 deletions.
38 changes: 27 additions & 11 deletions sources/MVCFramework.View.Renderers.WebStencils.pas
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ procedure TMVCWebStencilsViewEngine.OnGetValue(Sender: TObject; const AObjectNam
lValue: TValue;
begin
AHandled := False;
if ViewModel.TryGetValue(AObjectName, lValue) then
if (ViewModel <> nil) and ViewModel.TryGetValue(AObjectName, lValue) then
begin
AReplaceText := GetTValueVarAsString(lValue, AObjectName, TWebStencilsProcessor(Sender));
AHandled := True;
Expand Down Expand Up @@ -205,17 +205,33 @@ procedure TMVCWebStencilsViewEngine.RegisterWSFunctions(WSProcessor: TWebStencil
end) as IInvokable,
'json', 'json', '', True, 'Serialize an object to JSON', nil));

TBindingMethodsFactory.RegisterMethod(
TMethodDescription.Create(
MakeInvokable(function(Args: TArray<IValue>): IValue
begin
if Length(Args) <> 1 then
TBindingMethodsFactory.RegisterMethod(
TMethodDescription.Create(
MakeInvokable(function(Args: TArray<IValue>): IValue
begin
raise EWebStencilsException.Create('Expected 1 parameter, got ' + Length(Args).ToString);
end;
Result := TValueWrapper.Create(TMVCWebStencilsViewEngine.GetTValueVarAsString(Args[0].GetValue, '', nil));
end),
'ValueOf', 'ValueOf', '', True, 'ValueOf returns the inner value of a nullable as string - the non-nullable types are returned as-is', nil));
if Length(Args) <> 1 then
begin
raise EWebStencilsException.Create('Expected 1 parameter, got ' + Length(Args).ToString);
end;
Result := TValueWrapper.Create(TMVCWebStencilsViewEngine.GetTValueVarAsString(Args[0].GetValue, '', nil));
end),
'ValueOf', 'ValueOf', '', True, 'ValueOf returns the inner value of a nullable as string - the non-nullable types are returned as-is', nil));

TBindingMethodsFactory.RegisterMethod(
TMethodDescription.Create(
MakeInvokable(function(Args: TArray<IValue>): IValue
begin
if Length(Args) <> 1 then
begin
raise EWebStencilsException.Create('Expected 1 parameter, got ' + Length(Args).ToString);
end;
if (ViewModel <> nil) and ViewModel.ContainsKey(Args[0].GetValue.AsString) then
Result := TValueWrapper.Create(True)
else
Result := TValueWrapper.Create(False);
end),
'Defined', 'Defined', '', True, 'Defined returns true if variable is defined', nil));


finally
TMonitor.Exit(gWSLock);
Expand Down
Loading

0 comments on commit 9ee2f5a

Please sign in to comment.