Skip to content

Commit

Permalink
Update library definitions, update example comments
Browse files Browse the repository at this point in the history
  • Loading branch information
floatplane committed Mar 16, 2024
1 parent 7038eca commit 735aed2
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 28 deletions.
8 changes: 6 additions & 2 deletions examples/basic/basic.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void setup() {
Serial.begin(115200);
Serial.println("");

// Create a JSON object to hold the data that we'll use in our template
// Create a JsonDocument instance to hold the data that we'll use in our template
JsonDocument data;
data["name"] = "World";
data["value"] = 42;
Expand All @@ -25,7 +25,11 @@ void setup() {
String output = ministache::render(templateString, data);

// Print the result
Serial.println(output); // Prints: Hello, World! The answer is 42.
Serial.println(output);

// Expected output:
//
// Hello, World! The answer is 42.
}

void loop() {
Expand Down
51 changes: 26 additions & 25 deletions examples/partials/partials.ino
Original file line number Diff line number Diff line change
@@ -1,51 +1,52 @@
#include <Ministache.h>

/***************************************************
This is a very basic example for the ministache library
This is an example of how to use Mustache partials with the Ministache library
(https://github.com/floatplane/ministache).
It shows how the library can be used to render a Mustache template with a JSON object.
For more details on Mustache syntax, see http://mustache.github.io/mustache.5.html
****************************************************/

void setup() {
Serial.begin(115200);
Serial.println("");

// Create a JSON object to hold the data that we'll use in our template. It looks like this:
// {
// "Alice": {
// "name": "Alice",
// "role": "Engineer"
// },
// "Bob": {
// "name": "Bob",
// "role": "Intern"
// }
// }
// Create a JsonDocument instance to hold the data that we'll use in our template
const char* json = R"""(
{
"people": [
{
"name": "Alice",
"role": "Engineer"
},
{
"name": "Bob",
"role": "Intern"
}
]
}
)""";
JsonDocument data;
auto people = data["people"].to<JsonArray>();
auto alice = people.add<JsonObject>();
alice["name"] = "Alice";
alice["role"] = "Engineer";
auto bob = people.add<JsonObject>();
bob["name"] = "Bob";
bob["role"] = "Intern";

// Create a template string that renders the data for a single person. This is a partial.
deserializeJson(data, json);

// Create a template string that renders the data for a single person. This is a *partial*.
String personString = "Name: {{name}}\tRole: {{role}}\n";

// Create a template string that renders the data for all people. This is the main template.
// Note that it loops over a field called "people" and includes the partial "person" for each of
// them.
String reportString = "People report:\n{{#people}}{{> person}}{{/people}}";

// Render the template with the data. The third argument is the partials list. This
// defines how to map a partial reference like {{>person }} to a particular template
// (personString).
// defines how to map a partial reference like "person" to a particular template
// ("personString").
String output = ministache::render(reportString, data, {{"person", personString}});

// Print the result
Serial.println(output);

// Expected output:
//
// People report:
// Name: Alice Role: Engineer
// Name: Bob Role: Intern
Expand Down
39 changes: 39 additions & 0 deletions library.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "Ministache",
"version": "1.0.0",
"description": "Ministache is a small, fast and spec-complete implementation of the Mustache templating language for Arduino. All core Mustache tags are supported: interpolation, partials, sections, inverted sections, custom delimiters, and comments.",
"keywords": ["mustache", "moustache", "text", "text processor", "template", "logic-less", "html"],
"repository": {
"type": "git",
"url": "https://github.com/floatplane/ministache"
},
"authors": [
{
"name": "Brian Sharon",
"url": "https://github.com/floatplane",
"maintainer": true
}
],
"license": "MIT",
"platforms": "*",
"headers": "Ministache.h",
"examples": [
{
"name": "Basic",
"base": "examples/basic",
"files": ["basic.ino"]
},
{
"name": "Partials",
"base": "examples/partials",
"files": ["partials.ino"]
}
],
"dependencies": {
"bblanchon/ArduinoJson": "^7.0.0"
},
"build": {
"unflags": "-std=gnu++11",
"flags": "-std=gnu++17"
}
}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version=1.0.0
author=Brian Sharon <[email protected]>
maintainer=Brian Sharon <[email protected]>
sentence=Implementation of the Mustache templating language for Arduino
paragraph=Ministache is a small, fast and complete implementation of the Mustache templating language for Arduino.
paragraph=Ministache is a small, fast and spec-complete implementation of the Mustache templating language for Arduino.
category=Data Processing
url=https://github.com/floatplane/ministache
architectures=*
Expand Down

0 comments on commit 735aed2

Please sign in to comment.