CloudLiquid 2.0.1
dotnet add package CloudLiquid --version 2.0.1
NuGet\Install-Package CloudLiquid -Version 2.0.1
<PackageReference Include="CloudLiquid" Version="2.0.1" />
<PackageVersion Include="CloudLiquid" Version="2.0.1" />
<PackageReference Include="CloudLiquid" />
paket add CloudLiquid --version 2.0.1
#r "nuget: CloudLiquid, 2.0.1"
#:package CloudLiquid@2.0.1
#addin nuget:?package=CloudLiquid&version=2.0.1
#tool nuget:?package=CloudLiquid&version=2.0.1
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:
- Create a Liquid Template
Hello, {{ user.name }}!
- 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 | Versions 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. |
-
net8.0
- Azure.Storage.Blobs (>= 12.21.2)
- DotLiquid (>= 2.2.692)
- Fluid.Core (>= 2.19.0)
- Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
- Microsoft.Azure.WebJobs.Extensions.Storage (>= 5.3.0)
- Microsoft.Extensions.Configuration.UserSecrets (>= 8.0.0)
- Microsoft.NET.Test.Sdk (>= 17.10.0)
- Moq (>= 4.20.70)
- System.Configuration.ConfigurationManager (>= 6.0.0)
- System.Data.SqlClient (>= 4.8.6)
- System.Diagnostics.DiagnosticSource (>= 8.0.1)
- xunit (>= 2.8.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.