### Executing SpiderMonkey Build Source: https://github.com/synopse/mormot/blob/master/SyNode/mozjs/BuildInstructionSM52.md After successful configuration, this command starts the actual compilation and linking process using the mozmake build tool. Upon completion, the resulting binary files, including the required DLLs, will be located in the `dist\bin` subdirectory within the build directory. ```console mozmake.exe ``` -------------------------------- ### Initializing and Updating Git Submodules (Shell) Source: https://github.com/synopse/mormot/blob/master/SQLite3/Samples/22 - JavaScript HTTPApi web server/mustache.md These Git commands are used to set up and fetch the content of submodules defined in the repository. Specifically, they are needed to get the Mustache specifications required by the test suite. ```Shell git submodule init git submodule update ``` -------------------------------- ### Compiling SpiderMonkey Library - Bash Source: https://github.com/synopse/mormot/blob/master/SyNode/mozjs/BuildInstructionSM52-linux.md This command initiates the compilation process using the `make` build tool. It compiles the SpiderMonkey source code based on the configuration generated by the preceding `./configure` step. A C/C++ compiler and other build dependencies must be installed for this step to succeed. ```bash make ``` -------------------------------- ### Installing Resource Compilation Tools (Bash) Source: https://github.com/synopse/mormot/blob/master/SyNode/README.md This snippet provides the command to install the necessary `mingw-w64` toolchain on a Debian/Ubuntu-based Linux system. These tools, specifically `windres`, are used in a subsequent step to compile Windows resource script files (`.rc`) into binary resource files (`.res`). This step is required for embedding JavaScript files into the final executable. ```bash sudo apt install mingw-w64 mingw-w64-tools ``` -------------------------------- ### Installing MinGW-w64 Cross-Compiler - Bash Source: https://github.com/synopse/mormot/blob/master/SQLite3/amalgamation/ReadMe.md Installs the MinGW-w64 cross-compiler package on a Debian/Ubuntu system. This toolchain allows compiling applications targeting Windows (both 32-bit and 64-bit) from a Linux host, which is necessary for generating the static `.obj` files used by Delphi/FPC on Windows. ```Bash sudo apt install mingw-w64 ``` -------------------------------- ### Adding i386 Architecture Support - Bash Source: https://github.com/synopse/mormot/blob/master/SQLite3/amalgamation/ReadMe.md Adds the i386 architecture to the system's dpkg configuration on Debian/Ubuntu. This allows installing packages for the 32-bit architecture alongside the native architecture (multiarch support), which is required before installing i386-specific development libraries. ```Bash dpkg --add-architecture i386 ``` -------------------------------- ### Installing Mocha Test Runner Globally with npm (Shell) Source: https://github.com/synopse/mormot/blob/master/SQLite3/Samples/22 - JavaScript HTTPApi web server/mustache.md This command utilizes npm (Node Package Manager) to install the Mocha JavaScript test framework globally on the system. This is a prerequisite for running the mustache.js test suite. ```Shell npm install -g mocha ``` -------------------------------- ### Installing Linux i386 Cross-Compile Dependencies - Bash Source: https://github.com/synopse/mormot/blob/master/SQLite3/amalgamation/ReadMe.md Installs the necessary 32-bit development libraries (`libc6-dev`) on a Debian/Ubuntu system for cross-compiling applications targeting i386 architecture from an x86_64 host. This is a prerequisite for using FPC cross-compilers and relies on the i386 architecture already being added. ```Bash sudo apt install libc6-dev:i386 ``` -------------------------------- ### Running Mustache.js Test Suite with Mocha (Shell) Source: https://github.com/synopse/mormot/blob/master/SQLite3/Samples/22 - JavaScript HTTPApi web server/mustache.md This command executes the test suite for mustache.js using the globally installed Mocha test runner. It runs both unit and integration tests defined within the project's test directory. ```Shell mocha test ``` -------------------------------- ### Defining VCL Form for Service Client Components in Delphi Source: https://github.com/synopse/mormot/blob/master/SQLite3/Samples/ThirdPartyDemos/EMartin/TSynRestDataset/ReadMe.md Defines the same TForm class (TForm3) structure as in Example 1, including TDBGrid, TDBNavigator, TButton, TEdit, and TDataSource components, event handlers, and the private fRestDS field. This setup is generic for using TSynRestDataset regardless of whether it connects to a table or a service. ```Delphi type TForm3 = class(TForm) DBGrid1: TDBGrid; DBNavigator1: TDBNavigator; btnOpen: TButton; edtURL: TEdit; dsRest: TDataSource; procedure FormCreate(Sender: TObject); procedure btnOpenClick(Sender: TObject); procedure DBNavigator1Click(Sender: TObject; Button: TNavigateBtn); private { Private declarations } fRestDS: TSynRestDataset; public { Public declarations } end; ``` -------------------------------- ### Initializing TSynRestDataset for Service Client in Delphi Source: https://github.com/synopse/mormot/blob/master/SQLite3/Samples/ThirdPartyDemos/EMartin/TSynRestDataset/ReadMe.md Implements the FormCreate event handler for TForm3 in the service client example. It initializes TSynRestDataset and creates a TSQLModel based on TSQLRecordServiceName_OperationName, linking it to the TDataSource. This configures the dataset to expect data formatted according to the service's output structure. ```Delphi procedure TForm3.FormCreate(Sender: TObject); begin fRestDS := TSynRestDataset.Create(Self); fRestDS.Dataset.SQLModel := TSQLModel.Create([TSQLRecordServiceName_OperationName], 'root'); dsRest.Dataset := fRestDS; end; ``` -------------------------------- ### Opening TSynRestDataset with Table Endpoint URL in Delphi Source: https://github.com/synopse/mormot/blob/master/SQLite3/Samples/ThirdPartyDemos/EMartin/TSynRestDataset/ReadMe.md Implements the btnOpenClick event handler for the 'Open' button. It closes the existing dataset, sets the CommandText property of TSynRestDataset to a REST URL fetched from edtURL (targeting a specific table endpoint like '/root/Test/select=*'), and then calls Open to retrieve data from the mORMot server. Commented lines show examples for applying 'where' conditions and named parameters. ```Delphi procedure TForm3.btnOpenClick(Sender: TObject); begin fRestDS.Close; fRestDS.CommandText := edtURL.Text; // edtURL.Text = 'http://localhost:8888/root/Test/select=* fRestDS.Open; // you can filter by // where: fRestDS.CommandText := edtURL.Text; // edtURL.Text = 'http://localhost:8888/root/Test/select=*&where=CONDITION // fRestDS.Open; // named parameter: fRestDS.CommandText := edtURL.Text; // edtURL.Text = 'http://localhost:8888/root/Test/select=*&where=:PARAMNAME // fRestDS.Params.ParamByName('PARAMNAME').Value := XXX // fRestDS.Open; end; ``` -------------------------------- ### Attempting Updates via TDBNavigator Click on Service Data in Delphi Source: https://github.com/synopse/mormot/blob/master/SQLite3/Samples/ThirdPartyDemos/EMartin/TSynRestDataset/ReadMe.md Implements the DBNavigator1Click event handler for the service client example. It calls ApplyUpdates if the 'Post' button is clicked. This action is noted to raise an error ("Cannot update data from a service"), highlighting a limitation of TSynRestDataset when bound to data fetched from a mORMot service operation rather than a direct table endpoint. ```Delphi procedure TForm3.DBNavigator1Click(Sender: TObject; Button: TNavigateBtn); begin if (Button = nbPost) then fRestDS.ApplyUpdates(0); // raise an error "Cannot update data from a service" end; ``` -------------------------------- ### Opening TSynRestDataset with Service Endpoint URL in Delphi Source: https://github.com/synopse/mormot/blob/master/SQLite3/Samples/ThirdPartyDemos/EMartin/TSynRestDataset/ReadMe.md Implements the btnOpenClick event handler for the 'Open' button in the service client example. It closes the dataset, sets the CommandText to a service endpoint URL from edtURL (like '/root/ServiceName.OperationName?aParamName=XXX'), and calls Open to fetch data by invoking the specified service operation via REST. A commented line shows how to use a named parameter for the service call. ```Delphi procedure TForm3.btnOpenClick(Sender: TObject); begin fRestDS.Close; fRestDS.CommandText := edtURL.Text; // edtURL.Text = 'http://localhost:8888/root/ServiceName.OperationName?aParamName=XXX fRestDS.Open; // you can filter by named parameter: // fRestDS.CommandText := edtURL.Text; // 'http://localhost:8888/root/ServiceName.OperationName?aParamName=:aParamName // fRestDS.Params.ParamByName('aParamName').Value := XXX // fRestDS.Open; end; ``` -------------------------------- ### Generating Object Property Assignment (Delphi) Source: https://github.com/synopse/mormot/blob/master/SQLite3/Samples/ThirdPartyDemos/AntonE/CSV2ORM/ReadMe.md This snippet shows example generated Delphi code for assigning values from a TClientDataSet (CDS) to properties of a mORMot TSQLRecord object. It illustrates how string fields with a defined size are handled differently (using StringToRAWUTF8) compared to other field types. ```Delphi Obj.Code :=StringToRAWUTF8(CDSCode.AsString); Obj.Cost := CDSCost.AsInteger; ``` -------------------------------- ### Defining TSQLRecord for Service Operation Output in Delphi Source: https://github.com/synopse/mormot/blob/master/SQLite3/Samples/ThirdPartyDemos/EMartin/TSynRestDataset/ReadMe.md Defines a simple TSQLRecord class (TSQLRecordServiceName_OperationName) used in Example 2. This record's structure maps to the expected JSON output format returned by a specific service operation. It only includes a 'Text' field and is named following a 'ServiceName_OperationName' convention for clarity. ```Delphi TSQLRecordServiceName_OperationName = class(TSQLRecord) private fText: RawUTF8; published property Text: RawUTF8 index 255 read fText write fText; end; ``` -------------------------------- ### Creating and Entering Build Artifacts Directory - Bash Source: https://github.com/synopse/mormot/blob/master/SyNode/mozjs/BuildInstructionSM52-linux.md These commands first create a directory named `_OPT.OBJ` and then change the current directory into it. It is recommended to use this specific directory name as it is often configured to be ignored by source control (like via .gitignore), keeping the main source tree clean. Build output files will be placed here. ```bash mkdir _OPT.OBJ cd _OPT.OBJ ``` -------------------------------- ### Running Autoconf for Build Configuration - Bash Source: https://github.com/synopse/mormot/blob/master/SyNode/mozjs/BuildInstructionSM52-linux.md This command executes the `autoconf2.13` tool. Autoconf is used to process configuration files and generate the necessary `configure` script. This script will later be run to prepare the source code for compilation on the specific build environment, ensuring compatibility and enabling desired features. ```bash autoconf2.13 ``` -------------------------------- ### Creating and Entering Build Directory Source: https://github.com/synopse/mormot/blob/master/SyNode/mozjs/BuildInstructionSM52.md These console commands create a subdirectory within the source directory (e.g., 'obj' or 'obj64') specifically for placing the build output files. Changing into this directory ensures that the build process doesn't clutter the source tree. ```console mkdir obj cd obj ``` -------------------------------- ### Configuring SpiderMonkey Build Options - Bash Source: https://github.com/synopse/mormot/blob/master/SyNode/mozjs/BuildInstructionSM52-linux.md This command runs the generated `configure` script from the parent directory (`..`) with specific options required for building the library for SyNode. Key options include enabling C types (`--enable-ctypes`), disabling jemalloc (`--disable-jemalloc`), enabling NSPR build (`--enable-nspr-build`), and disabling debug symbols (`--disable-debug-symbols`). ```bash ../configure --enable-ctypes --disable-jemalloc --enable-nspr-build --disable-debug-symbols ``` -------------------------------- ### Navigating to SpiderMonkey Source Directory Source: https://github.com/synopse/mormot/blob/master/SyNode/mozjs/BuildInstructionSM52.md These console commands are used within the MozillaBuild shell to change the current directory to the location where the SpiderMonkey source code was downloaded. This is the first step before preparing the build environment. ```console cd d: cd mozilla-releases\mozilla-esr52 cd js\src ``` -------------------------------- ### Calling Synopse mORMot REST Service - Java Source: https://github.com/synopse/mormot/blob/master/SQLite3/Samples/ThirdPartyDemos/KroKodil/README.md This snippet demonstrates the basic usage of the SynClient Java library to connect to a mORMot server, authenticate, prepare parameters using JSONArray, call a specific remote method (e.g., Calculator.Add), and process the returned JSONObject response before logging out. It requires a running mORMot server and the SynClient library dependency. ```Java SynClient client = new SynClient("127.0.0.1", 8080, "service", false); if (client.login("User", "synopse")) { JSONArray params = new JSONArray().put(2).put(3); // Add(2, 3) JSONObject response = client.call("Calculator.Add", params); System.out.println("Summ: " + response); client.logout(); } ``` -------------------------------- ### Navigating to SpiderMonkey Source Directory - Bash Source: https://github.com/synopse/mormot/blob/master/SyNode/mozjs/BuildInstructionSM52-linux.md This command changes the current working directory to the `js/src` subdirectory within the cloned gecko-dev repository. This directory contains the core source code for the SpiderMonkey engine, and subsequent configuration and build commands will be executed from this location. ```bash cd js/src ``` -------------------------------- ### Configuring FPC Static Library Path Source: https://github.com/synopse/mormot/blob/master/static/ReadMe.txt To utilize the static binary files in this folder, the path to the compiled libraries must be specified in the FPC project options. This setting is typically configured under 'Libraries -fFl', pointing the compiler to the location of the architecture-specific static files. ```FPC Configuration ..\static\$(TargetCPU)-$(TargetOS) ``` -------------------------------- ### Changing Directory and Checking Out ESR52 Branch - Bash Source: https://github.com/synopse/mormot/blob/master/SyNode/mozjs/BuildInstructionSM52-linux.md These commands navigate into the newly cloned `gecko-dev` directory and then switch the current branch to `esr52`. It is crucial to use the `esr52` branch specifically for building the required v52 version of SpiderMonkey; using the `master` branch is not recommended for this purpose. ```bash cd gecko-dev git checkout esr52 ``` -------------------------------- ### Configuring SpiderMonkey Build Shell Source: https://github.com/synopse/mormot/blob/master/SyNode/mozjs/BuildInstruction.md This shell command is used to configure the SpiderMonkey build process. It enables the ctypes foreign function interface and disables the jemalloc memory allocator, influencing the resulting library's features and dependencies. ```shell ../configure --enable-ctypes --disable-jemalloc ``` -------------------------------- ### Compiling JavaScript Modules Resource File (Bash) Source: https://github.com/synopse/mormot/blob/master/SyNode/README.md This series of bash commands automates the process of creating a resource file (`.res`) containing the core JavaScript modules. It utilizes a project-specific tool (`core_res`) to gather the necessary files and generate a resource definition, followed by the `windres` tool from the mingw-w64 toolchain to perform the actual compilation into the binary resource format, ready for embedding into the application. ```bash cd SyNode ./tools/core_res -i ./core_modules/ -o ./.resources/ cd ./resources x86_64-w64-mingw32-windres ./core_res.rc ../core_modules.res ``` -------------------------------- ### Cloning Mozilla Gecko-Dev Repository - Bash Source: https://github.com/synopse/mormot/blob/master/SyNode/mozjs/BuildInstructionSM52-linux.md This command clones the entire Mozilla gecko-dev source repository from GitHub. This repository contains the source code for various Mozilla projects, including SpiderMonkey, and is a prerequisite for building the library from source. The process can take a significant amount of time depending on network speed and system performance. ```bash git clone https://github.com/mozilla/gecko-dev.git ``` -------------------------------- ### Configuring SpiderMonkey Build (64-bit) Source: https://github.com/synopse/mormot/blob/master/SyNode/mozjs/BuildInstructionSM52.md This command configures the build for a 64-bit target. In addition to enabling ctypes and disabling jemalloc, it specifies the host and target architecture as x86_64-pc-mingw32 for a 64-bit build within the MinGW-w64 environment provided by MozillaBuild. ```console ..\configure --enable-ctypes --disable-jemalloc [--disable-sm-promise] --host=x86_64-pc-mingw32 --target=x86_64-pc-mingw32 ``` -------------------------------- ### Applying SyNode Specific Patch - Bash Source: https://github.com/synopse/mormot/blob/master/SyNode/mozjs/BuildInstructionSM52-linux.md This command applies a patch file provided by SyNode (`esr52-git.patch`) to the SpiderMonkey source code within the gecko-dev repository. This patch likely contains modifications necessary for the library to work correctly with the SyNode project. The placeholder `` must be replaced with the actual path to the root directory of the mORMot sources. ```bash git apply /SyNode/mozjs/esr52-git.patch ``` -------------------------------- ### Running Specific Mustache Rendering Test Case with Mocha (Shell) Source: https://github.com/synopse/mormot/blob/master/SQLite3/Samples/22 - JavaScript HTTPApi web server/mustache.md This command runs the test/render_test.js file using Mocha, but sets the TEST environment variable to target a specific test case defined by corresponding files (e.g., mytest.mustache, mytest.js, mytest.txt). ```Shell TEST=mytest mocha test/render_test.js ``` -------------------------------- ### Renaming and Patching SONAME of Library - Bash Source: https://github.com/synopse/mormot/blob/master/SyNode/mozjs/BuildInstructionSM52-linux.md These commands are executed on the successfully built `libmozjs-52.so` library located in the `dist/bin` subdirectory. The first command uses the `patchelf` utility (version 0.9+) to change the internal Shared Object Name (SONAME) to `libsynmozjs52.so`. The second command renames the file itself to match the new SONAME, helping to avoid conflicts with potentially pre-installed versions of the library. ```bash patchelf --set-soname libsynmozjs52.so libmozjs-52.so mv libmozjs-52.so libsynmozjs52.so ``` -------------------------------- ### Configuring SpiderMonkey Build (32-bit) Source: https://github.com/synopse/mormot/blob/master/SyNode/mozjs/BuildInstructionSM52.md This command executes the configuration script for a 32-bit build. It enables ctypes (Foreign Function Interface) and disables jemalloc (memory allocator) to avoid conflicts with other memory managers like FastMM, which might be used by Delphi applications. `--disable-sm-promise` is optional and might cause build failures. ```console ..\configure --enable-ctypes --disable-jemalloc [--disable-sm-promise] ``` -------------------------------- ### Rendering a Mustache Template in JavaScript Source: https://github.com/synopse/mormot/blob/master/SQLite3/Samples/22 - JavaScript HTTPApi web server/mustache.md Demonstrates the basic usage of the Mustache.render function in JavaScript. It takes a view object containing data and functions and a template string, returning the rendered output string. ```JavaScript var view = { title: "Joe", calc: function () { return 2 + 4; } }; var output = Mustache.render("{{title}} spends {{calc}}", view); ``` -------------------------------- ### Including Partials in Mustache Templates Source: https://github.com/synopse/mormot/blob/master/SQLite3/Samples/22 - JavaScript HTTPApi web server/mustache.md Illustrates the use of partials (`{{> partial_name}}`) to include content from other templates. Partials inherit the current context and are rendered at runtime, allowing for modular and reusable template structures. ```Mustache Template base.mustache:

Names

{{#names}} {{> user}} {{/names}} ``` ```Mustache Template user.mustache: {{name}} ``` ```Mustache Template

Names

{{#names}} {{name}} {{/names}} ``` -------------------------------- ### Building Mustache.js Library Plugins with Rake (Shell) Source: https://github.com/synopse/mormot/blob/master/SQLite3/Samples/22 - JavaScript HTTPApi web server/mustache.md These commands use the Rake build tool to compile mustache.js specifically for integration with different JavaScript libraries. Each command triggers a build target corresponding to the specified library. ```Shell rake jquery rake mootools rake dojo rake yui3 rake qooxdoo ``` -------------------------------- ### Compiling Mustache Partials in JavaScript Source: https://github.com/synopse/mormot/blob/master/SQLite3/Samples/22 - JavaScript HTTPApi web server/mustache.md Describes how to compile template partials using `Mustache.compilePartial`. Compiled partials are registered and can be used by both `Mustache.render` and compiled template functions. ```JavaScript Mustache.compilePartial('partial-name', stringTemplate); ``` -------------------------------- ### Initializing TSynRestDataset on Form Creation in Delphi Source: https://github.com/synopse/mormot/blob/master/SQLite3/Samples/ThirdPartyDemos/EMartin/TSynRestDataset/ReadMe.md Implements the FormCreate event handler for TForm3. This procedure initializes the TSynRestDataset component, creates a TSQLModel based on TSQLRecordTest, and assigns the dataset to the TDataSource component (dsRest) for data binding to VCL controls. ```Delphi procedure TForm3.FormCreate(Sender: TObject); begin fRestDS := TSynRestDataset.Create(Self); fRestDS.Dataset.SQLModel := TSQLModel.Create([TSQLRecordTest], 'root'); dsRest.Dataset := fRestDS; end; ``` -------------------------------- ### Applying Updates via TDBNavigator Click in Delphi Source: https://github.com/synopse/mormot/blob/master/SQLite3/Samples/ThirdPartyDemos/EMartin/TSynRestDataset/ReadMe.md Implements the DBNavigator1Click event handler. This procedure is triggered when a button on the TDBNavigator is clicked. If the clicked button is 'nbPost' (Post), it calls the ApplyUpdates method on the TSynRestDataset to send any pending changes from the client dataset back to the mORMot server. ```Delphi procedure TForm3.DBNavigator1Click(Sender: TObject; Button: TNavigateBtn); begin if (Button = nbPost) then fRestDS.ApplyUpdates(0); end; ``` -------------------------------- ### Setting Cross-Compiler Path - Bash Source: https://github.com/synopse/mormot/blob/master/SQLite3/amalgamation/ReadMe.md Defines the `CROSS` environment variable, typically used in compilation scripts (`.sh`), to specify the directory containing the cross-compiler executables for the target architecture (`$ARCH`). This ensures the script uses the correct compiler when building for different platforms. ```Bash CROSS=/home/ab/fpcup/cross/bin/$ARCH ``` -------------------------------- ### Compiling Mustache Templates for Performance in JavaScript Source: https://github.com/synopse/mormot/blob/master/SQLite3/Samples/22 - JavaScript HTTPApi web server/mustache.md Shows how to compile a Mustache template string into a reusable JavaScript function using `Mustache.compile`. The compiled function can then be called directly with data to render the template efficiently. ```JavaScript var compiledTemplate = Mustache.compile(stringTemplate); ``` ```JavaScript var templateOutput = compiledTemplate(templateData); ``` -------------------------------- ### Implementing Server-Side Service Operation in Delphi Source: https://github.com/synopse/mormot/blob/master/SQLite3/Samples/ThirdPartyDemos/EMartin/TSynRestDataset/ReadMe.md Implements the server-side OperationName service method. This method takes an input parameter (aParamName) and returns data in the aData output parameter. It sets aResult to OK (indicating success) and populates aData with a hardcoded JSON string representing an array of simple objects, demonstrating how a service can return data consumable by TSynRestDataset. ```Delphi function TServiceName.OperationName(const aParamName: RawUTF8; out aData: RawUTF8): Integer; begin Result := OK; aData := '[{"text":"test"},{"text":"test1"}]'; end; ``` -------------------------------- ### Using Rendering Functions in Mustache Sections Source: https://github.com/synopse/mormot/blob/master/SQLite3/Samples/22 - JavaScript HTTPApi web server/mustache.md Details how functions associated with a section key are called with the section's un-rendered block and a special rendering function as arguments. This allows custom processing and rendering of the block content. ```JavaScript { "name": "Tater", "bold": function () { return function (text, render) { return "" + render(text) + ""; } } } ``` ```Mustache Template {{#bold}}Hi {{name}}.{{/bold}} ``` ```HTML Hi Tater. ``` -------------------------------- ### Using Variable Tags in Mustache Templates Source: https://github.com/synopse/mormot/blob/master/SQLite3/Samples/22 - JavaScript HTTPApi web server/mustache.md Illustrates how variable tags (`{{name}}`) are replaced by corresponding values from the view context. It shows default HTML escaping and how to render unescaped HTML using triple mustaches (`{{{html}}}`) or the ampersand (`{{&html}}`). ```JSON { "name": "Chris", "company": "GitHub" } ``` ```Mustache Template * {{name}} * {{age}} * {{company}} * {{{company}}} * {{&company}} ``` ```Plain Text * Chris * * <b>GitHub</b> * GitHub * GitHub ``` -------------------------------- ### Rendering Sections Conditionally or Iteratively Source: https://github.com/synopse/mormot/blob/master/SQLite3/Samples/22 - JavaScript HTTPApi web server/mustache.md Explains how sections (`{{#section}}...{{/section}}`) control rendering based on the view value. If the value is falsy (false, null, undefined) or an empty list, the block is skipped. ```JSON { "person": false } ``` ```Mustache Template Shown. {{#person}} Never shown! {{/person}} ``` ```Plain Text Shown. ``` -------------------------------- ### Changing Delimiters in Mustache Templates Source: https://github.com/synopse/mormot/blob/master/SQLite3/Samples/22 - JavaScript HTTPApi web server/mustache.md Explains how to use Set Delimiter tags (`{{=<% %>=}}`) to change the characters used for defining tags from the default `{{` and `}}` to custom strings within a template. ```Mustache Template * {{ default_tags }} {{=<% %>=}} * <% erb_style_tags %> <%={{ }}=%> * {{ default_tags_again }} ``` -------------------------------- ### Iterating Over Lists with Mustache Sections Source: https://github.com/synopse/mormot/blob/master/SQLite3/Samples/22 - JavaScript HTTPApi web server/mustache.md Demonstrates how sections iterate over non-empty lists in the view. The block is rendered once for each item, with the context updated to the current item, allowing access to item properties. ```JSON { "stooges": [ { "name": "Moe" }, { "name": "Larry" }, { "name": "Curly" } ] } ``` ```Mustache Template {{#stooges}} {{name}} {{/stooges}} ``` ```HTML Moe Larry Curly ``` -------------------------------- ### Defining VCL Form with TSynRestDataset Client Components in Delphi Source: https://github.com/synopse/mormot/blob/master/SQLite3/Samples/ThirdPartyDemos/EMartin/TSynRestDataset/ReadMe.md Defines a TForm class (TForm3) representing the client-side VCL application window. It includes components like TDBGrid, TDBNavigator, TButton, TEdit, and TDataSource to display and interact with data, along with event handlers and a private field (fRestDS) to manage the TSynRestDataset instance. ```Delphi type TForm3 = class(TForm) DBGrid1: TDBGrid; DBNavigator1: TDBNavigator; btnOpen: TButton; edtURL: TEdit; dsRest: TDataSource; procedure FormCreate(Sender: TObject); procedure btnOpenClick(Sender: TObject); procedure DBNavigator1Click(Sender: TObject; Button: TNavigateBtn); private { Private declarations } fRestDS: TSynRestDataset; public { Public declarations } end; ``` -------------------------------- ### Using Inverted Sections in Mustache Templates Source: https://github.com/synopse/mormot/blob/master/SQLite3/Samples/22 - JavaScript HTTPApi web server/mustache.md Explains inverted sections (`{{^section}}...{{/section}}`), which render their block only if the corresponding view value is falsy (null, undefined, false) or an empty list. This provides a way to handle 'else' conditions or empty states. ```JSON { "repos": [] } ``` ```Mustache Template {{#repos}}{{name}}{{/repos}} {{^repos}}No repos :({{/repos}} ``` ```Plain Text No repos :( ``` -------------------------------- ### Adding Comments in Mustache Templates Source: https://github.com/synopse/mormot/blob/master/SQLite3/Samples/22 - JavaScript HTTPApi web server/mustache.md Shows how to add comments (`{{! comment }}`) to a Mustache template. Comments are ignored during the rendering process and do not appear in the final output. ```Mustache Template

Today{{! ignore me }}.

``` ```HTML

Today.

``` -------------------------------- ### Calling Functions in List Contexts within Sections Source: https://github.com/synopse/mormot/blob/master/SQLite3/Samples/22 - JavaScript HTTPApi web server/mustache.md Explains how functions defined in the view can be called for each item when iterating over a list. The function is called in the context of the current list item, allowing access to its properties via `this`. ```JavaScript { "beatles": [ { "firstName": "John", "lastName": "Lennon" }, { "firstName": "Paul", "lastName": "McCartney" }, { "firstName": "George", "lastName": "Harrison" }, { "firstName": "Ringo", "lastName": "Starr" } ], "name": function () { return this.firstName + " " + this.lastName; } } ``` ```Mustache Template {{#beatles}} * {{name}} {{/beatles}} ``` ```Plain Text * John Lennon * Paul McCartney * George Harrison * Ringo Starr ``` -------------------------------- ### Accessing Nested Variables with Dot Notation Source: https://github.com/synopse/mormot/blob/master/SQLite3/Samples/22 - JavaScript HTTPApi web server/mustache.md Shows how to access properties of nested objects within the view using dot notation (`{{parent.child}}`). This allows navigating through object structures to retrieve values for variable tags. ```JSON { "name": { "first": "Michael", "last": "Jackson" }, "age": "RIP" } ``` ```Mustache Template * {{name.first}} {{name.last}} * {{age}} ``` ```Plain Text * Michael Jackson * RIP ``` -------------------------------- ### Accessing Current Item in Array of Strings Section Source: https://github.com/synopse/mormot/blob/master/SQLite3/Samples/22 - JavaScript HTTPApi web server/mustache.md Shows how to reference the current item when iterating over a simple array of strings using the dot (`{{.}}`) tag within a section block. This provides access to the primitive value itself. ```JSON { "musketeers": ["Athos", "Aramis", "Porthos", "D'Artagnan"] } ``` ```Mustache Template {{#musketeers}} * {{.}} {{/musketeers}} ``` ```Plain Text * Athos * Aramis * Porthos * D'Artagnan ``` -------------------------------- ### Defining Server-Side Service Implementation Class in Delphi Source: https://github.com/synopse/mormot/blob/master/SQLite3/Samples/ThirdPartyDemos/EMartin/TSynRestDataset/ReadMe.md Defines the server-side class (TServiceName) that implements a mORMot service interface (IServiceName). It inherits from TInterfacedObjectWithCustomCreate and includes the definition for a service operation method, OperationName, which is exposed via REST. ```Delphi TServiceName =class(TInterfacedObjectWithCustomCreate, IServiceName) public ... // this function can also be function OperationName(const aParamName: RawUTF8): RawUTF8; function OperationName(const aParamName: RawUTF8; out aData: RawUTF8): Integer; ... end; ``` -------------------------------- ### Implementing ComputeFieldsBeforeWrite for TSQLRecord in Delphi Source: https://github.com/synopse/mormot/blob/master/SQLite3/Samples/ThirdPartyDemos/EMartin/TSynRestDataset/ReadMe.md Implements the ComputeFieldsBeforeWrite method for TSQLRecordTest. This method is called before a record is written to the database, allowing for calculations or setting default values. In this implementation, it sets the Date_Time field to the current time using the Now function. ```Delphi procedure TSQLRecordTest.ComputeFieldsBeforeWrite(aRest: TSQLRest; aOccasion: TSQLEvent); begin inherited; fDateTime := Now; end; ``` -------------------------------- ### Defining TSQLRecord for Table Access in Delphi Source: https://github.com/synopse/mormot/blob/master/SQLite3/Samples/ThirdPartyDemos/EMartin/TSynRestDataset/ReadMe.md Defines a TSQLRecord class (TSQLRecordTest) mapping to a database table structure. It includes private fields for data, published properties, and overrides for InternalDefineModel (defining validation/filtering) and ComputeFieldsBeforeWrite (setting default values before writing). This record definition is essential for TSynRestDataset to understand the data structure when connecting to a direct table endpoint. ```Delphi TSQLRecordTest = class(TSQLRecord) private fDecimal: Double; fNumber: Double; fTestID: Integer; fText: RawUTF8; fDateTime: TDateTime; protected class procedure InternalDefineModel(Props: TSQLRecordProperties); override; public procedure ComputeFieldsBeforeWrite(aRest: TSQLRest; aOccasion: TSQLEvent); override; published property Test_ID: Integer read fTestID write fTestID; property Text: RawUTF8 index 255 read fText write fText; property Date_Time: TDateTime read fDateTime write fDateTime; property Number: Double read fNumber write fNumber; property Decimal_: Double read fDecimal write fDecimal; end; ``` -------------------------------- ### Defining Model Validations/Filters for TSQLRecord in Delphi Source: https://github.com/synopse/mormot/blob/master/SQLite3/Samples/ThirdPartyDemos/EMartin/TSynRestDataset/ReadMe.md Implements the InternalDefineModel method for TSQLRecordTest. This class procedure is used to define constraints, validations, or filters for the record's fields. Here, it adds validation rules ensuring the 'Text' field is not void and non-null. ```Delphi class procedure TSQLRecordTest.InternalDefineModel(Props: TSQLRecordProperties); begin AddFilterNotVoidText(['Text']); AddFilterOrValidate('Text', TSynValidateNonNull.Create); end; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.