All Projects → sempare → sempare-delphi-template-engine

sempare / sempare-delphi-template-engine

Licence: GPL-3.0 license
Sempare Template Engine for Delphi allows for flexible dynamic text generation. It can be used for generating email, html, source code, xml, configuration, etc.

Programming Languages

pascal
1382 projects

Projects that are alternatives of or similar to sempare-delphi-template-engine

Diamond
Diamond is a full-stack web-framework written in The D Programming Language using vibe.d
Stars: ✭ 173 (+118.99%)
Mutual labels:  template-engine
React Ssr
React SSR as a view template engine
Stars: ✭ 200 (+153.16%)
Mutual labels:  template-engine
Himl
HTML-based Indented Markup Language for Ruby
Stars: ✭ 236 (+198.73%)
Mutual labels:  template-engine
Express Es6 Template Engine
Rendering engine for Express that uses ES6 javascript string templates as syntax.
Stars: ✭ 175 (+121.52%)
Mutual labels:  template-engine
Elefant
Elefant, the refreshingly simple PHP CMS and web framework.
Stars: ✭ 188 (+137.97%)
Mutual labels:  template-engine
Fatfree
A powerful yet easy-to-use PHP micro-framework designed to help you build dynamic and robust Web applications - fast!
Stars: ✭ 2,504 (+3069.62%)
Mutual labels:  template-engine
Dwoo
[UNMAINTAINED] php template engine
Stars: ✭ 164 (+107.59%)
Mutual labels:  template-engine
Sailfish
Simple, small, and extremely fast template engine for Rust
Stars: ✭ 242 (+206.33%)
Mutual labels:  template-engine
Yarte
Yarte stands for Yet Another Rust Template Engine
Stars: ✭ 189 (+139.24%)
Mutual labels:  template-engine
Pupa
Simple micro templating
Stars: ✭ 231 (+192.41%)
Mutual labels:  template-engine
Microconfig
Modern tool for microservice configuration management
Stars: ✭ 180 (+127.85%)
Mutual labels:  template-engine
Thymeleaf
Thymeleaf is a modern server-side Java template engine for both web and standalone environments.
Stars: ✭ 2,251 (+2749.37%)
Mutual labels:  template-engine
Flexml
🚀基于Litho的Android高性能动态业务容器。
Stars: ✭ 225 (+184.81%)
Mutual labels:  template-engine
Quicktemplate
Fast, powerful, yet easy to use template engine for Go. Optimized for speed, zero memory allocations in hot paths. Up to 20x faster than html/template
Stars: ✭ 2,287 (+2794.94%)
Mutual labels:  template-engine
Eta
Embedded JS template engine for Node, Deno, and the browser. Lighweight, fast, and pluggable. Written in TypeScript
Stars: ✭ 233 (+194.94%)
Mutual labels:  template-engine
Craftsman
Craftsman is the workhorse behind the Wrapt framework and provides a suite of CLI commands for quickly scaffolding out new files and projects for your .NET Web APIs with simple CLI commands and configuration files.
Stars: ✭ 165 (+108.86%)
Mutual labels:  template-engine
Ructe
Rust Compiled Templates with static-file handling
Stars: ✭ 206 (+160.76%)
Mutual labels:  template-engine
Jade
Jade.go - pug template engine for Go (golang)
Stars: ✭ 251 (+217.72%)
Mutual labels:  template-engine
Sodajs
Light weight but powerful template engine for JavaScript
Stars: ✭ 240 (+203.8%)
Mutual labels:  template-engine
Jte
jte is a secure and lightweight template engine for Java.
Stars: ✭ 228 (+188.61%)
Mutual labels:  template-engine

delphi compatibility platform compatibility license

Sempare Template Engine

Copyright (c) 2019-2023 Sempare Limited

Contact: [email protected]

License: GPL v3.0 or Sempare Limited Commercial License

Open Source: https://github.com/sempare/sempare-delphi-template-engine

Contents

Introduction

Template engines are used often in technology where text needs to be customised by substituting variables with values from a data source. Examples where this may take place:

  • web sites using template engines (for server side scripting)
  • code generation
  • mail merge
  • notification messages

Please review the License section below before including the Sempare Template Engine in commercial products.

The Sempare Template Engine is a small templating engine for Delphi (Object Pascal) that allows for templates to be created easily and efficiently by providing a simple and easy to use API.

Example usage:

program Example;
uses
    Sempare.Template;
type
    TInformation = record
        name: string;
        favourite_sport : string;
        count : integer;
    end;
begin
    var tpl := Template.Parse(
	       'My name is <% name %>.'#13#10 + 
	       'My favourite sport is <% favourite_sport %>.'#13#10 + 
	       'Counting... <% for i := 1 to count %><% i %><% betweenitems %>, <% end %>'
	);
    var info : TInformation;
    info.name := 'conrad';
    info.favourite_sport := 'ultimate';
    info.count := 3;
    writeln(Template.Eval(tpl, info));	
end.

The project uses Run-time Type Information (RTTI) to allow for almost any type to be dereferenced within the template script.

In the example above, you can see that the '<%' start and '%>' end the scripting statement respectively. Within a scripting statement, you can reference variables, assign variables, use conditions, for and while loops, and include other templates.

NOTE In examples in this documentation I may use the latest Delphi syntax, e.g. inline variable declarations. This is not backward compatible as they were introduced in Delphi 10.2 and are used to shorten the code/examples being illustrated in the documentation. The codebase will attempt to be as backward compatible as possible.

Call to action

Please 'star' the project on github.

Quickstart

There are a few ways to get started quickly.

  • Look at the examples on how to do server side scripting using some popular web frameworks:

Try the demo if you want to dive in quick and play with the template engine.

Features

  • statements
    • if, elif, else statements
    • for and while statements
    • include statement
    • extends / block statements
    • with statement
    • function/method calls
  • expressions
    • simple expression evaluation (logical, numerical and string)
    • variable definition
    • functions and methods calls
    • dereference records, custom managed records, classes, arrays, JSON objects, TDataSet descendants and dynamic arrays
    • ternary operator
  • safety
    • max run-time protection
  • customisation
    • custom script token replacement
    • add custom functions
    • strip recurring spaces and new lines
  • lazy template resolution
  • parse time evaluation of expressions/statements
  • allow use of custom encoding (UTF-8 with BOM, UTF-8 without BOM, ASCII, etc)
  • extensibile RTTI interface to easily dereference classes and interfaces (current customisations for ITemplateVariables, TDictionary, TJsonObject)

Objectives

The Sempare Template Engine is not intended to be a fully featured general purpose programming language such as PHP where the script itself could be a self contained programming language (but it does have most of the features).

Sempare Template Engine aims to provide just enough functionality to allow you to easily work with the 'view' aspects of a template. Any enhanced functionality required from the scripting environment should be provided by the custom functions written in Object Pascal.

Requirements

The template engine works with modern versions of Delphi.

Tests currently run using the DUnitX TestFramework.

An attempt has been made not to use the latest features to ease backward compatability. The following versions have been tested:

  • Delphi XE 4 to XE 8
  • Delphi 10.0 Seatle
  • Delphi 10.1 Berlin
  • Delphi 10.2 Tokyo
  • Delphi 10.3.3 Rio
  • Delphi 10.4 Sydney
  • Delphi 11.0 to 11.3 Alexandria

There should be no platform specific restrictions.

Have a look at Sempare.Template.Compiler.inc. The following defines can be defined if appropriate:

  • SEMPARE_TEMPLATE_NO_INDY - if Indy is not present. This is used to access an html encoder if TNetEncoding is not available.
  • SEMPARE_TEMPLATE_CONFIRM_LICENSE - if present, you confirm you understand the conditions.

Installation

GetIt

The Sempare Template Engine for Delphi can be installed via the Embarcadero GetIt manager

This will add the src folder to the search path so you can start working immediately.

Boss

The Sempare Template Engine for Delphi can be installed via the Boss package manager.

Simply run:

boss install sempare/sempare-delphi-template-engine

Delphinus

The Sempare Template Engine for Delphi can be installed via the Delphinus package manager.

This will add the src folder to the search path so you can start working immediately.

Manual Install

Start by adding the src folder to the Delphi search path. Otherwise, there are some projects you can use:

Open Sempare.Template.Engine.Group.groupproj which will include:

  • Sempare.Template.Pkg.dproj

    The core template project. (runtime)

  • Sempare.Template.Tester.dproj

    180+ unit tests

  • demo\SempareTemplatePlayground\Sempare.TemplateEngine.Playground.dproj

    The Sempare Template Playground demo which provides a rich experience for testing the various template language features.

Feedback

You can raise issues on GitHub and they will be addressed based on priority.

Most features have some basic tests in place. If a bug is been discovered, please include a basic test/scenario replicating the issue if possible as this will ease the investigation process.

Contributions

Review contibution terms and conditions to contribute to the project.

License

The Sempare Template Engine is dual-licensed. You may choose to use it under the restrictions of the GPL v3.0 at no cost to you, or you may license it for use under the Sempare Limited Commercial License

The dual-licensing scheme allows you to use and test the library with no restrictions, but subject to the terms of the GPL. A nominal fee is requested to support the maintenance of the library if the product is to be used in commercial products. This support fee binds you to the commercial license, removing any of the GPL restrictions, and allowing you to use the library in your products as you will. The Sempare Template Engine may NOT be included or distributed as part of another commercial library or framework without approval / commercial review.

A commercial licence grants you the right to use Sempare Template Engine in your own applications, royalty free, and without any requirement to disclose your source code nor any modifications to Sempare Template Engine or to any other party. A commercial license lasts into perpetuity, and entitles you to all future updates.

A commercial licence is provided per developer developing applications that uses the Sempare Template Engine. The initial license fee is $70 per developer. For support thereafter, at your discretion, a support fee of $30 per developer per year would be appreciated. The initial site licensing fee is $1,500 and the annual site support licensing fee is $500.

The following payment links allow you to quickly subscribe. Please note that the initial license and support links are seperate.

The following payment links are available for site licenses. Please note that the initial license and support links are seperate.

Please send an e-mail to [email protected] to request an invoice which will contain alternative payment details.

Support and enhancement requests submitted by users that pay for support will be prioritised. New developments may incur additional costs depending on time required for implementation.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].