#1 2023-04-18 09:45:48

edwinsn
Member
Registered: 2010-07-02
Posts: 1,218

A simple demo of mORMot + Sempare Template Engine


Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.

Offline

#2 2023-04-18 16:57:11

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,679
Website

Re: A simple demo of mORMot + Sempare Template Engine

I did not know about this Sempare template engine.
The syntax seems a bit verbose and unreadable to me, in comparison to Mustache  - once you got the Mustache way of thinking, it is very powerful.
But it is nice seeing such new code around.

Note that with the latest mormot.core.mustache versions, we can also access directly dynamic arrays or records as data source: we are not restricted to TDocVariant/JSON input data.
See e.g. https://github.com/synopse/mORMot2/blob … w.pas#L413

Offline

#3 2023-04-19 01:21:14

edwinsn
Member
Registered: 2010-07-02
Posts: 1,218

Re: A simple demo of mORMot + Sempare Template Engine

Mustache is great, especially your Pascal implementation - it's fast.
I think the difference is that Mustache is logic-less, while Sempare template has features like for loop, sometimes it's a must-have, for example in case the logic must be written out side of Pascal/Delphi code.


Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.

Offline

#4 2023-04-19 05:05:52

igors233
Member
Registered: 2012-09-10
Posts: 241

Re: A simple demo of mORMot + Sempare Template Engine

Yes, mustache is powerfull but sometimes it's simplicity is weak link. In some cases it requires creating new variables or additional processing on code side to achive something. I do think an additional MustacheEx or MustachemORM descendant could help in many areas and make it much more powerful.

Offline

#5 2024-11-21 18:18:36

darnocian
Member
From: Amersham, UK
Registered: 2024-11-21
Posts: 1
Website

Re: A simple demo of mORMot + Sempare Template Engine

I thought I'd share that I've been working on an IDE plugin for the Sempare Template Engine.

The plugin exposes a dockable form allowing you to preview templates:
Sempare Template Playground

Above you can also see you can test mock json data against a template, so you don't have to launch an app to test.  Json object's field names just need to map onto fields in records/classes. The preview is available as raw text or can be viewed in an embedded browser (html). When editing templates, errors will also be highlighted as you type (a separate panel show the error message)

Illustrating some of the things with different colors: script tags, keywords, numbers, strings, boolean
Zooming on the template

You can customise some of the settings...
Cusomisation Options

I'm hoping to release this later in the year.

I appreciate some of the comments re the templates looking verbose, but then we could say, why do we write pascal? wink C/C++ is less verbose as well. Anyways, I'm stoking a fire that doesn't need stoking.

The point of the Sempare Template Language was to always be pascal-like, and to make something that Delphi developers would recognise easily, and would not require a manual to interpret. The template language constructs map easily onto already known paradigms from pascal, without having to think differently. Lastly, being the author, I know all the flaws, and yeah, it may not be as fast as DMustache. However, I hope the features make up for it in the way it aids developers with a Delphi native solution.

Besides the lack of features, the simplicity of mustache can be limiting. I'm not critisising the DMustache implementation. I appreciate some people like the simplicity, or it works for the solution they are working on. The sempare template engine is an alternative, and in my opinion, richer - has a parser, compiled AST, and template registry with many features and options - so the tool chest is there if you want to use it, and there are plenty of articles now and a rich set of documentation.

A reminder about the location: https://github.com/sempare/sempare-delp … ate-engine

Last edited by darnocian (2024-11-21 18:59:47)

Offline

Board footer

Powered by FluxBB