Skip to content

Commit 1616df4

Browse files
authored
Merge pull request #193 from sempare/dev
Update 1.7.7
2 parents 59dc87c + d6a782b commit 1616df4

File tree

7 files changed

+272
-33
lines changed

7 files changed

+272
-33
lines changed

demo/WebReporting/WebReporting.dpr

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ type
2020
HighScores: TArray<TPerson>;
2121
end;
2222

23+
TWebReportingFunctions = class
24+
public
25+
class function JoinNames(const APerson: TPerson): string; static;
26+
27+
end;
28+
2329
{ TPerson }
2430

2531
constructor TPerson.Create(const AFN, ALN: string; const AScore: integer);
@@ -29,8 +35,17 @@ begin
2935
Score := AScore;
3036
end;
3137

38+
{ TWebReportingFunctions }
39+
40+
class function TWebReportingFunctions.JoinNames(const APerson: TPerson): string;
41+
begin
42+
exit(format('%s %s', [APerson.FirstName, APerson.LastName]));
43+
end;
44+
3245
begin
3346
try
47+
Template.Resolver.Context.Functions.AddFunctions(TWebReportingFunctions);
48+
3449
THorse.Get('/',
3550
procedure(Req: THorseRequest; Res: THorseResponse)
3651
var

demo/WebReporting/WebReporting.dproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@
211211
<MainSource>MainSource</MainSource>
212212
</DelphiCompile>
213213
<None Include="templates\index.tpl"/>
214+
<None Include="templates\layout.tpl"/>
214215
<BuildConfiguration Include="Base">
215216
<Key>Base</Key>
216217
</BuildConfiguration>
@@ -265,6 +266,12 @@
265266
<Overwrite>true</Overwrite>
266267
</Platform>
267268
</DeployFile>
269+
<DeployFile LocalName="templates\layout.tpl" Configuration="Debug" Class="ProjectFile">
270+
<Platform Name="Win32">
271+
<RemoteDir>.\</RemoteDir>
272+
<Overwrite>true</Overwrite>
273+
</Platform>
274+
</DeployFile>
268275
<DeployClass Name="AdditionalDebugSymbols">
269276
<Platform Name="iOSSimulator">
270277
<Operation>1</Operation>

demo/WebReporting/templates/index.tpl

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1+
<% extends 'layout' %>
2+
<% block 'header' %>
3+
<title>The high scores for the Dev Days 2024 demo</title>
4+
<% end %>
5+
<% block 'body' %>
6+
<h1>High Scores</h1>
7+
8+
<% for person of HighScores %>
9+
<tr>
10+
<td><% JoinNames(person) %></td>
11+
<td><% person.score %></td>
12+
</tr>
13+
<% onbegin %>
14+
<table>
15+
<% onend %>
16+
</table>
17+
<% onempty %>
18+
19+
There are no high scores available.
20+
<% end %>
21+
<% end %>
122

2-
<h1>High Scores</h1>
323

4-
5-
6-
7-
<% for person of HighScores %>
8-
<tr>
9-
<td><% person.firstname %></td>
10-
<td><% person.lastname %></td>
11-
<td><% person.score %></td>
12-
</tr>
13-
<% onbegin %>
14-
<table>
15-
<% onend %>
16-
</table>
17-
<% onempty %>
18-
19-
There are no high scores available.
2024
<% end %>
21-
22-
23-
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<html>
2+
<header>
3+
<% block 'header' %>
4+
<title>This is the web reporting demo</title>
5+
<% end %>
6+
</header>
7+
<body>
8+
<% block 'body' %>
9+
This is a placeholder for content
10+
<% end %>
11+
</body>
12+
</html>

docs/statements.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,22 @@ begin
590590

591591
include() can also take a second parameter, allowing for improved scoping of variables, similar to the _with_ statement.
592592

593+
We have a 'functional' include syntax:
594+
```
595+
<% template 'button' %>
596+
<button text="<% text %>">
597+
<% end %>
598+
599+
<% button { text="add" } %>
600+
601+
or
602+
603+
<% button text="remove" %>
604+
```
605+
606+
Above we can see we don't need to use the explict 'include' statement.
607+
608+
593609
<a name="require"><h3>require</h3></a>
594610

595611
![require](./images/stmt_require.svg)

0 commit comments

Comments
 (0)