CloudLiquid 2.0.1

dotnet add package CloudLiquid --version 2.0.1
                    
NuGet\Install-Package CloudLiquid -Version 2.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CloudLiquid" Version="2.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CloudLiquid" Version="2.0.1" />
                    
Directory.Packages.props
<PackageReference Include="CloudLiquid" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CloudLiquid --version 2.0.1
                    
#r "nuget: CloudLiquid, 2.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CloudLiquid@2.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CloudLiquid&version=2.0.1
                    
Install as a Cake Addin
#tool nuget:?package=CloudLiquid&version=2.0.1
                    
Install as a Cake Tool

Cloud Liquid Framework

CloudLiquid is a versatile framework designed to facilitate the parsing of data from HTTP content or strings containing JSON, CSV, and XML data into objects that other projects can utilize. Originally developed to work with CloudLiquid and LiquidConsole or Transform-Data-Functions, it plays a crucial role in transforming payloads into suitable formats for various templating engines. For Fluid, it converts payloads into Hash objects (Dictionary<string, object>), and for Scriban, it transforms payloads into ScriptObjects.

Features

  • Data Parsing: Easily parse JSON, CSV, and XML data into Hash objects.
  • Integration with Templating Engines: Expanding Fluid for transforming payloads.
  • Flexible Content Factory: Utilize the ContentFactory module for advanced data handling and transformations.

Getting Started

To get started with CloudLiquid, clone the repository to your local machine:

git clone https://github.com/jcardoso13/CloudLiquid.git

Ensure you have the necessary dependencies installed and follow the setup instructions detailed in the AzureCloudLiquid README.

Using Liquid Templates with CloudLiquid

CloudLiquid enhances the use of Liquid templates, allowing for easy integration and manipulation of data in formats like JSON, CSV, and XML. Here's how to get started with Liquid templates in CloudLiquid:

Basic Example

To render a simple greeting message using a Liquid template:

  1. Create a Liquid Template
Hello, {{ user.name }}!
  1. Parse and Render the Template in CloudLiquid

Assuming you have a JSON string {"name": "John Doe"}, you can parse this JSON and render the template as follows:

using Fluid;
using Microsoft.Extensions.Logging;
using CloudLiquid.Azure.Exceptions;
using CloudLiquid.Core;
using CloudLiquid.ObjectModel;

// Parse the JSON string into a Hash object
var userData = "{\"name\": \"John Doe\"}";



using var loggerFactory = LoggerFactory.Create(builder =>
{
  builder.AddConsole();
}); 

// Create a logger instance for the Program class
var logger = loggerFactory.CreateLogger<Program>();

// Create a new instance of the LiquidProcessor class
var liquidProcessor = new LiquidProcessor(logger, null);

// Get a content reader for JSON data
var contentReader = ContentFactory.GetContentReader("application/json");

// Parse the user data string and run the liquid processor with the parsed data
RunResult result = liquidProcessor.Run(contentReader.ParseString(userData), "Hello, {{ user.name }}!");


Console.WriteLine(result.Output); // Outputs: Hello, John Doe!

Advanced Usage

CloudLiquid also supports more complex scenarios, such as iterating over collections, using conditionals, and incorporating custom filters or tags that you define. Here's an example of iterating over a list of items in a Liquid template:

{%- if content.name != null -%}
{{ content | clear_nulls | json }}
{%- endif -%}

Input of the Liquid Template:

{
    "name": "John Doe",
    "age": null,
    "email": "johndoe@example.com",
    "address": null,
    "isEmployed": true,
    "hobbies": ["reading", "running", "cooking"],
    "favoriteColor": "blue",
    "height": 175.5,
    "weight": 70.2
}

And the corresponding C# code to render this template:

using Fluid;
using Microsoft.Extensions.Logging;
using CloudLiquid.Azure.Exceptions;
using CloudLiquid.Core;
using CloudLiquid.ObjectModel;

// JSON Input
var userData = "{\r\n    \"name\": \"John Doe\",\r\n    \"age\": null,\r\n    \"email\": \"johndoe@example.com\",\r\n    \"address\": null,\r\n    \"isEmployed\": true,\r\n    \"hobbies\": [\"reading\", \"running\", \"cooking\"],\r\n    \"favoriteColor\": \"blue\",\r\n    \"height\": 175.5,\r\n    \"weight\": 70.2\r\n}";



using var loggerFactory = LoggerFactory.Create(builder =>
{
  builder.AddConsole();
}); 

// Create a logger instance for the Program class
var logger = loggerFactory.CreateLogger<Program>();
var json = "{\r\n{% for item in content %}\r\n  {{ item.key | json }}: {{ item.value | json }}\r\n{% endfor %}\r\n}";
// Create a new instance of the LiquidProcessor class
var liquidProcessor = new LiquidProcessor(logger, null);

// Get a content reader for JSON data
var contentReader = ContentFactory.GetContentReader("application/json");

// Parse the user data string and run the liquid processor with the parsed data
RunResult result = liquidProcessor.Run(contentReader.ParseString(userData), json);


Console.WriteLine(result.Output);

This will generate the following output:

{
    "name": "John Doe",
    "email": "johndoe@example.com",
    "isEmployed": true,
    "hobbies": ["reading", "running", "cooking"],
    "favoriteColor": "blue",
    "height": 175.5,
    "weight": 70.2
}

Filter and Tags Documentation

The documentation for CloudLiquid filters and tags can be found in the Filters and Tags files. This comprehensive guide provides detailed information on each filter available in CloudLiquid, including their usage, parameters, and examples. Whether you need to manipulate strings, format dates, or manipulate JSON Objects and Lists, the filter documentation will help you leverage the full power of CloudLiquid's filtering capabilities. Make sure to refer to this documentation whenever you need to apply filters to your CloudLiquid templates.

Contributing

Contributions to CloudLiquid are welcome! If you have any questions, feature requests, or issues, please add an issue on GitHub or contact the repository owner, João Pedro Cardoso (jpcardoso@outlook.pt).

License

CloudLiquid is licensed under the GPLv3 License. Feel free to use, modify, and distribute the code as per the license agreement.

More Information

This README is generated as part of the CloudLiquid framework documentation. For the most up-to-date information, please visit the GitHub repository.

Any Questions or Feature requests, please add an Issue or contact Repo Owner João Pedro Cardoso (jpcardoso@outlook.pt).

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.1 1,593 3/27/2025
2.0.0 522 3/25/2025
1.1.4 190 3/13/2025
1.1.3 168 2/24/2025
1.1.2 210 1/21/2025
1.1.1 306 6/20/2024 1.1.1 is deprecated because it is no longer maintained and has critical bugs.
1.1.0 170 5/13/2024
1.0.4 211 4/18/2024
1.0.3 180 4/17/2024
1.0.2 155 4/17/2024
1.0.1 165 4/17/2024
1.0.0 156 4/4/2024