Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions source/RlxRazor.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1100,12 +1100,14 @@ function TRlxRazorProcessor.RazorContentFromStream(AStream: TStream): string;
end
else if SameText (TokenStr, 'ExtraHeader') then
begin
// Parser.SkipToToken('{');
blockAsString := Encoding.GetString
(BytesOf(Parser.SkipToToken('}')));
Parser.SkipToken(True);
// process the block
ParsedExtraHeader := DoBlock(RawByteString(blockAsString), Encoding);
if Parser.Token = '{' then
begin
blockAsString := FindMatchingClosingBrace;
// process the block
ParsedExtraHeader := DoBlock(RawByteString(blockAsString), Encoding);
end
else
AddWarning('missing { after ExtraHeader');
end
else if SameText (TokenStr, 'RenderBody') then
begin
Expand Down
82 changes: 82 additions & 0 deletions test/TestRlxRazor.pas
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ TestTRlxRazorProcessor = class(TTestCase)
procedure TestPermission;
procedure TestWrongPermission;

// 7. extraheader
procedure TestExtraHeader;
procedure TestExtraHeaderNestedIf;
procedure TestExtraHeaderNestedIfWithinIf;
end;

implementation
Expand Down Expand Up @@ -446,6 +450,84 @@ procedure TestTRlxRazorProcessor.TestWrongPermission;
CheckException(RunLoginPermissionScript, ERlxLoginRequired);
end;

procedure TestTRlxRazorProcessor.TestExtraHeader;
var
strBlock: string;
ReturnValue: string;
LRlxRazorEngine: TRlxRazorEngine;
begin
LRlxRazorEngine := TRlxRazorEngine.Create(nil);
try
strBlock := '@LayoutPage testextraheader'#13#10'@ExtraHeader {TestExtraHeader}';
FRlxRazorProcessor.RazorEngine := LRlxRazorEngine;
FRlxRazorProcessor.RazorEngine.TemplatesFolder := '..\..\templates\';
ReturnValue := FRlxRazorProcessor.DoBlock(strBlock);
CheckEquals (' TestExtraHeader', ReturnValue);
finally
FRlxRazorProcessor.RazorEngine := nil;
LRlxRazorEngine.Free;
end;
end;

procedure TestTRlxRazorProcessor.TestExtraHeaderNestedIf;
var
strBlock: string;
ReturnValue: string;
LRlxRazorEngine: TRlxRazorEngine;
simpleObj: TSimpleObj;
begin
simpleObj := TSimpleObj.Create;
try
simpleObj.ABool := True;
FRlxRazorProcessor.AddToDictionary(SampleObjectName, SimpleObj, False);
LRlxRazorEngine := TRlxRazorEngine.Create(nil);
try
strBlock := '@LayoutPage testextraheader'#13#10'@ExtraHeader {@if ' + SampleObjectName + '.' + SampleBoolFieldName
+ '{TestExtraHeaderNestedIf}}';
FRlxRazorProcessor.RazorEngine := LRlxRazorEngine;
FRlxRazorProcessor.RazorEngine.TemplatesFolder := '..\..\templates\';
ReturnValue := FRlxRazorProcessor.DoBlock(strBlock);
FRlxRazorProcessor.DataObjects.Remove(SampleObjectName);
CheckEquals (' TestExtraHeaderNestedIf', ReturnValue);
finally
FRlxRazorProcessor.RazorEngine := nil;
LRlxRazorEngine.Free;
end;
finally
simpleObj.Free;
end;
end;

procedure TestTRlxRazorProcessor.TestExtraHeaderNestedIfWithinIf;
var
strBlock: string;
ReturnValue: string;
LRlxRazorEngine: TRlxRazorEngine;
simpleObj: TSimpleObj;
begin
simpleObj := TSimpleObj.Create;
try
simpleObj.ABool := True;
FRlxRazorProcessor.AddToDictionary(SampleObjectName, SimpleObj, False);
LRlxRazorEngine := TRlxRazorEngine.Create(nil);
try
strBlock := '@LayoutPage testextraheader'#13#10'@ExtraHeader {@if ' + SampleObjectName + '.' + SampleBoolFieldName
+ '{@if ' + SampleObjectName + '.' + SampleBoolFieldName + '{TestExtraHeaderNestedIfWithinIf}}}';
FRlxRazorProcessor.RazorEngine := LRlxRazorEngine;
FRlxRazorProcessor.RazorEngine.TemplatesFolder := '..\..\templates\';
ReturnValue := FRlxRazorProcessor.DoBlock(strBlock);
FRlxRazorProcessor.DataObjects.Remove(SampleObjectName);
CheckEquals (' TestExtraHeaderNestedIfWithinIf', ReturnValue);
finally
FRlxRazorProcessor.RazorEngine := nil;
LRlxRazorEngine.Free;
end;
finally
simpleObj.Free;
end;
end;


{ TSimpleObj }

procedure TSimpleObj.SetABool(const Value: Boolean);
Expand Down
1 change: 1 addition & 0 deletions test/templates/testextraheader.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@RenderHeader