Component Sempare Template Engine

FireWind

Свой
Регистрация
2 Дек 2005
Сообщения
1,957
Реакции
1,199
Credits
4,009
Sempare Template Engine
Template engines are used often in in the 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 (or languages)
  • code generation
  • mail merge
  • notification messages
The Sempare Template Engine is small templating engine for Для просмотра ссылки Войди или Зарегистрируйся (Object Pascal) that allows for templates to be created easily and efficiently by providing a simple and easy to use interface.
  • statements
    • if, elif, else statements
    • for and while statements
    • include statement
    • with statement
    • function/method calls
  • expressions
    • simple expression evaluation (logical, numerical and string)
    • variable definition
    • functions and methods calls
    • dereference 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 IVelocityVariables, TDictionary, TJsonObject)
Код:
program Example;
uses
    Sempare.Template;
type
    TInformation = record
        name: string;
        favourite_sport : string;
    end;
begin
    var tpl := Template.parse('My name is <% name %>. My favourite sport is <% favourite_sport %>.');
    var information : TInformation;
    information.name := 'conrad';
    information.favourite_sport := 'ultimate';
    writeln(Template.eval(tpl, information));  
end.
Home: Для просмотра ссылки Войди или Зарегистрируйся
Copyright © Для просмотра ссылки Войди или Зарегистрируйся
 
Последнее редактирование:

FireWind

Свой
Регистрация
2 Дек 2005
Сообщения
1,957
Реакции
1,199
Credits
4,009
Sempare Template Engine v1.3.0
  • Documented ignorenl block statement and added tests
  • Added double quote support on strings
  • Added escape support in strings
Для просмотра ссылки Войди или Зарегистрируйся
 

FireWind

Свой
Регистрация
2 Дек 2005
Сообщения
1,957
Реакции
1,199
Credits
4,009
Sempare Template Engine v1.4.0
  • NEW: Add NL, CR, TAB, CRNL variables
  • NEW: Add Chr() and Ord(), PadLeft(), PadRight(), Spaces(), Tabs(), NL(), CRNL() helper functions
  • NEW: Provide Context.StartStripToken and Context.EndStripToken to allow for content to be ignored between template statements
  • UPDATE: Documentation updates
  • CHANGE: Context.Options updated to require eoAllowIgnoreNL if ignorenl statement is to be processed
  • FIX: TNewLineStreamWriter fixed to handle carriage return correctly
  • FIX: Fix double free bug on ParseFile
Для просмотра ссылки Войди или Зарегистрируйся