From 92c4bf9f0ca726aff809965ad855343635e563ed Mon Sep 17 00:00:00 2001 From: Daniele Teti Date: Fri, 11 Oct 2024 18:12:02 +0200 Subject: [PATCH] htmx_web_site using webstencils --- .../ControllerU.pas | 18 +++--------- .../bin/templates/baselayout.html | 2 +- .../bin/templates/customers.html | 2 ++ .../bin/templates/customers_body.html | 23 +++++++++++++++ .../bin/templates/home.html | 2 ++ .../bin/templates/home_body.html | 3 ++ .../bin/templates/pages/customers.html | 28 ------------------- .../bin/templates/pages/home.html | 3 -- .../bin/templates/posts.html | 2 ++ .../{pages/posts.html => posts_body.html} | 3 +- .../bin/templates/{partials => }/sidenav.html | 0 .../bin/templates/users.html | 2 ++ .../{pages/users.html => users_body.html} | 3 +- ...VCFramework.View.Renderers.WebStencils.pas | 3 +- 14 files changed, 43 insertions(+), 51 deletions(-) create mode 100644 samples/htmx_website_with_webstencils/bin/templates/customers.html create mode 100644 samples/htmx_website_with_webstencils/bin/templates/customers_body.html create mode 100644 samples/htmx_website_with_webstencils/bin/templates/home.html create mode 100644 samples/htmx_website_with_webstencils/bin/templates/home_body.html delete mode 100644 samples/htmx_website_with_webstencils/bin/templates/pages/customers.html delete mode 100644 samples/htmx_website_with_webstencils/bin/templates/pages/home.html create mode 100644 samples/htmx_website_with_webstencils/bin/templates/posts.html rename samples/htmx_website_with_webstencils/bin/templates/{pages/posts.html => posts_body.html} (91%) rename samples/htmx_website_with_webstencils/bin/templates/{partials => }/sidenav.html (100%) create mode 100644 samples/htmx_website_with_webstencils/bin/templates/users.html rename samples/htmx_website_with_webstencils/bin/templates/{pages/users.html => users_body.html} (88%) diff --git a/samples/htmx_website_with_webstencils/ControllerU.pas b/samples/htmx_website_with_webstencils/ControllerU.pas index bf67c603..fb5912f0 100644 --- a/samples/htmx_website_with_webstencils/ControllerU.pas +++ b/samples/htmx_website_with_webstencils/ControllerU.pas @@ -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; diff --git a/samples/htmx_website_with_webstencils/bin/templates/baselayout.html b/samples/htmx_website_with_webstencils/bin/templates/baselayout.html index 83feff79..227c9577 100644 --- a/samples/htmx_website_with_webstencils/bin/templates/baselayout.html +++ b/samples/htmx_website_with_webstencils/bin/templates/baselayout.html @@ -73,7 +73,7 @@
- @import partials/sidenav + @import sidenav
@RenderBody diff --git a/samples/htmx_website_with_webstencils/bin/templates/customers.html b/samples/htmx_website_with_webstencils/bin/templates/customers.html new file mode 100644 index 00000000..6d8bc223 --- /dev/null +++ b/samples/htmx_website_with_webstencils/bin/templates/customers.html @@ -0,0 +1,2 @@ +@layoutpage baselayout +@import customers_body \ No newline at end of file diff --git a/samples/htmx_website_with_webstencils/bin/templates/customers_body.html b/samples/htmx_website_with_webstencils/bin/templates/customers_body.html new file mode 100644 index 00000000..0abc0657 --- /dev/null +++ b/samples/htmx_website_with_webstencils/bin/templates/customers_body.html @@ -0,0 +1,23 @@ +

Customers

+ + + + + + + + + + + + @foreach(var cust in customers){ + + + + + + + + } + +
CodeFirst NameLast NameCountryDOB
@cust.code@cust.first_name@cust.last_name@cust.country@cust.dob @if (FormatDateTime("yyyy/mm/dd", cust.dob) >= "2000/01/01") {📅}
\ No newline at end of file diff --git a/samples/htmx_website_with_webstencils/bin/templates/home.html b/samples/htmx_website_with_webstencils/bin/templates/home.html new file mode 100644 index 00000000..096e8530 --- /dev/null +++ b/samples/htmx_website_with_webstencils/bin/templates/home.html @@ -0,0 +1,2 @@ +@LayoutPage baselayout +@import home_body \ No newline at end of file diff --git a/samples/htmx_website_with_webstencils/bin/templates/home_body.html b/samples/htmx_website_with_webstencils/bin/templates/home_body.html new file mode 100644 index 00000000..6d56f37c --- /dev/null +++ b/samples/htmx_website_with_webstencils/bin/templates/home_body.html @@ -0,0 +1,3 @@ +

HTMX WebSite

+

Powered by DMVCFramework, WebStencils and HTMX

+

More info about WebStencils here

\ No newline at end of file diff --git a/samples/htmx_website_with_webstencils/bin/templates/pages/customers.html b/samples/htmx_website_with_webstencils/bin/templates/pages/customers.html deleted file mode 100644 index 74915a80..00000000 --- a/samples/htmx_website_with_webstencils/bin/templates/pages/customers.html +++ /dev/null @@ -1,28 +0,0 @@ -{{extends "../baselayout.html"}} -{{block "body"}} -

Customers

- - - - - - - - - - - - {{if customers}} - {{for cust in customers}} - - - - - - - - {{endfor}} - {{endif}} - -
CodeFirst NameLast NameCountryDOB
{{:cust.code|lpad,3,"0"}}{{:cust.first_name}}{{:cust.last_name}}{{:cust.country|capitalize}}{{:cust.dob}}{{if cust.dob|ge,"2000/01/01"}}📅{{endif}}
-{{endblock}} \ No newline at end of file diff --git a/samples/htmx_website_with_webstencils/bin/templates/pages/home.html b/samples/htmx_website_with_webstencils/bin/templates/pages/home.html deleted file mode 100644 index 59078084..00000000 --- a/samples/htmx_website_with_webstencils/bin/templates/pages/home.html +++ /dev/null @@ -1,3 +0,0 @@ -@LayoutPage baselayout -

HTMX WebSite

-

Powered by DMVCFramework, TemplatePro and HTMX

\ No newline at end of file diff --git a/samples/htmx_website_with_webstencils/bin/templates/posts.html b/samples/htmx_website_with_webstencils/bin/templates/posts.html new file mode 100644 index 00000000..1ebcf882 --- /dev/null +++ b/samples/htmx_website_with_webstencils/bin/templates/posts.html @@ -0,0 +1,2 @@ +@layoutpage baselayout +@import posts_body diff --git a/samples/htmx_website_with_webstencils/bin/templates/pages/posts.html b/samples/htmx_website_with_webstencils/bin/templates/posts_body.html similarity index 91% rename from samples/htmx_website_with_webstencils/bin/templates/pages/posts.html rename to samples/htmx_website_with_webstencils/bin/templates/posts_body.html index ba22a1cd..a78aacc1 100644 --- a/samples/htmx_website_with_webstencils/bin/templates/pages/posts.html +++ b/samples/htmx_website_with_webstencils/bin/templates/posts_body.html @@ -1,10 +1,9 @@ -@layoutpage baselayout

Posts

@foreach (var p in posts){

- @p.title + @(uppercase(p.title))
@p.abstract