htmx_web_site using webstencils
Some checks failed
TOC Generator / TOC Generator (push) Has been cancelled

This commit is contained in:
Daniele Teti 2024-10-11 18:12:02 +02:00
parent 82312c6c49
commit 92c4bf9f0c
14 changed files with 43 additions and 51 deletions

View File

@ -9,9 +9,6 @@ uses
type
[MVCPath]
TMyController = class(TMVCController)
protected
procedure OnBeforeAction(AContext: TWebContext; const AActionName: string;
var AHandled: Boolean); override;
public
[MVCPath]
[MVCHTTPMethod([httpGET])]
@ -40,7 +37,7 @@ begin
var lCustomers := GetPeople();
try
ViewData['customers'] := lCustomers;
Result := Page(['pages/customers']);
Result := Page('customers' + IfThen(Context.Request.IsHTMX, '_body'))
finally
lCustomers.Free;
end;
@ -48,14 +45,7 @@ end;
function TMyController.Home: String;
begin
Result := Page(['pages/home']);
end;
procedure TMyController.OnBeforeAction(AContext: TWebContext;
const AActionName: string; var AHandled: Boolean);
begin
inherited;
ViewData['ispage'] := not AContext.Request.IsHTMX;
Result := Page('home' + IfThen(Context.Request.IsHTMX, '_body'))
end;
function TMyController.Posts: String;
@ -63,7 +53,7 @@ begin
var lPosts := GetPosts(20);
try
ViewData['posts'] := lPosts;
Result := Page(['pages/posts']);
Result := Page('posts' + IfThen(Context.Request.IsHTMX, '_body'))
finally
lPosts.Free;
end;
@ -74,7 +64,7 @@ begin
var lUsers := GetUsers();
try
ViewData['users'] := lUsers;
Result := Page(['pages/users']);
Result := Page('users' + IfThen(Context.Request.IsHTMX, '_body'));
finally
lUsers.Free;
end;

View File

@ -73,7 +73,7 @@
<main class="container-fluid">
<div class="parent">
<!-- Side Navigation -->
@import partials/sidenav
@import sidenav
<!-- Main Content Area -->
<div class="main" id="main">
@RenderBody

View File

@ -0,0 +1,2 @@
@layoutpage baselayout
@import customers_body

View File

@ -0,0 +1,23 @@
<h1 class="text-2xl font-bold mb-4">Customers</h1>
<table class="striped">
<thead>
<tr>
<th>Code</th>
<th>First Name</th>
<th>Last Name</th>
<th>Country</th>
<th>DOB</th>
</tr>
</thead>
<tbody>
@foreach(var cust in customers){
<tr>
<td>@cust.code</td>
<td>@cust.first_name</td>
<td>@cust.last_name</td>
<td>@cust.country</td>
<td>@cust.dob @if (FormatDateTime("yyyy/mm/dd", cust.dob) >= "2000/01/01") {&#128197;}</td>
</tr>
}
</tbody>
</table>

View File

@ -0,0 +1,2 @@
@LayoutPage baselayout
@import home_body

View File

@ -0,0 +1,3 @@
<h1 class="text-2xl font-bold mb-4">HTMX WebSite</h1>
<p>Powered by DMVCFramework, WebStencils and HTMX</p>
<p><small>More info about WebStencils <a target="_blank" href="https://docwiki.embarcadero.com/RADStudio/en/WebStencils">here</a></small></p>

View File

@ -1,28 +0,0 @@
{{extends "../baselayout.html"}}
{{block "body"}}
<h1 class="text-2xl font-bold mb-4">Customers</h1>
<table class="striped">
<thead>
<tr>
<th>Code</th>
<th>First Name</th>
<th>Last Name</th>
<th>Country</th>
<th>DOB</th>
</tr>
</thead>
<tbody>
{{if customers}}
{{for cust in customers}}
<tr>
<td>{{:cust.code|lpad,3,"0"}}</td>
<td>{{:cust.first_name}}</td>
<td>{{:cust.last_name}}</td>
<td>{{:cust.country|capitalize}}</td>
<td>{{:cust.dob}}{{if cust.dob|ge,"2000/01/01"}}📅{{endif}}</td>
</tr>
{{endfor}}
{{endif}}
</tbody>
</table>
{{endblock}}

View File

@ -1,3 +0,0 @@
@LayoutPage baselayout
<h1 class="text-2xl font-bold mb-4">HTMX WebSite</h1>
<p>Powered by DMVCFramework, TemplatePro and HTMX</p>

View File

@ -0,0 +1,2 @@
@layoutpage baselayout
@import posts_body

View File

@ -1,10 +1,9 @@
@layoutpage baselayout
<h1 class="text-2xl font-bold mb-4">Posts</h1>
@foreach (var p in posts){
<p>
<article style="padding: 0.6rem">
<header style="font-size: 140%">
@p.title
@(uppercase(p.title))
</header>
@p.abstract
<footer>

View File

@ -0,0 +1,2 @@
@layoutpage baselayout
@import users_body

View File

@ -1,4 +1,3 @@
@layoutpage baselayout
<h1 class="text-2xl font-bold mb-4">Users</h1>
<table class="striped">
<thead>
@ -13,7 +12,7 @@
<tr>
<td>@user.first_name</td>
<td>@user.last_name</td>
<td>@user.email</td>
<td>@(lowercase(user.email))</td>
</tr>
}

View File

@ -179,8 +179,9 @@ begin
try
RegisterWSFunctions(lWebStencilsProcessor);
try
lWebStencilsProcessor.OnFile := Self.OnFile;
//lWebStencilsProcessor.OnFile := Self.OnFile;
lWebStencilsProcessor.InputFileName := lViewFileName;
lWebStencilsProcessor.PathTemplate := TPath.GetDirectoryName(lViewFileName);
if Assigned(ViewModel) then
begin
for lPair in ViewModel do