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

View File

@ -73,7 +73,7 @@
<main class="container-fluid"> <main class="container-fluid">
<div class="parent"> <div class="parent">
<!-- Side Navigation --> <!-- Side Navigation -->
@import partials/sidenav @import sidenav
<!-- Main Content Area --> <!-- Main Content Area -->
<div class="main" id="main"> <div class="main" id="main">
@RenderBody @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> <h1 class="text-2xl font-bold mb-4">Posts</h1>
@foreach (var p in posts){ @foreach (var p in posts){
<p> <p>
<article style="padding: 0.6rem"> <article style="padding: 0.6rem">
<header style="font-size: 140%"> <header style="font-size: 140%">
@p.title @(uppercase(p.title))
</header> </header>
@p.abstract @p.abstract
<footer> <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> <h1 class="text-2xl font-bold mb-4">Users</h1>
<table class="striped"> <table class="striped">
<thead> <thead>
@ -13,7 +12,7 @@
<tr> <tr>
<td>@user.first_name</td> <td>@user.first_name</td>
<td>@user.last_name</td> <td>@user.last_name</td>
<td>@user.email</td> <td>@(lowercase(user.email))</td>
</tr> </tr>
} }

View File

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