Skip to content

Commit 49572e0

Browse files
Merge remote-tracking branch 'origin/develop' into develop
2 parents ad527dd + ed2ddc7 commit 49572e0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1390
-1158
lines changed

Hyperbee.Templating.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hyperbee.Templating.Benchma
3434
EndProject
3535
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "docs", "docs\docs.shproj", "{8409DDE0-C540-4A94-BF7F-9403888BEDAC}"
3636
EndProject
37+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hyperbee.Templating.Provider.XS", "src\Hyperbee.Templating.Provider.XS\Hyperbee.Templating.Provider.XS.csproj", "{EA264696-D88A-288E-0D8E-C834780D5F9E}"
38+
EndProject
3739
Global
3840
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3941
Debug|Any CPU = Debug|Any CPU
@@ -52,6 +54,10 @@ Global
5254
{EB7D2A85-3C82-444A-84CD-D245DCF951CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
5355
{EB7D2A85-3C82-444A-84CD-D245DCF951CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
5456
{EB7D2A85-3C82-444A-84CD-D245DCF951CE}.Release|Any CPU.Build.0 = Release|Any CPU
57+
{EA264696-D88A-288E-0D8E-C834780D5F9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
58+
{EA264696-D88A-288E-0D8E-C834780D5F9E}.Debug|Any CPU.Build.0 = Debug|Any CPU
59+
{EA264696-D88A-288E-0D8E-C834780D5F9E}.Release|Any CPU.ActiveCfg = Release|Any CPU
60+
{EA264696-D88A-288E-0D8E-C834780D5F9E}.Release|Any CPU.Build.0 = Release|Any CPU
5561
EndGlobalSection
5662
GlobalSection(SolutionProperties) = preSolution
5763
HideSolutionNode = FALSE

README.md

Lines changed: 41 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# Hyperbee Templating
22

33
Hyperbee Templating is a lightweight templating and variable substitution syntax engine. The library supports value replacements,
4-
code expressions, token nesting, in-line definitions, conditional flow, and looping. It is designed to be lightweight and fast,
5-
and does not rely on any external dependencies.
4+
code expressions, token nesting, in-line definitions, conditional flow, and looping. It is designed to be lightweight and fast.
65

76
## Features
87

@@ -33,34 +32,32 @@ dotnet add package Hyperbee.Templating
3332
You can use the `TemplateParser` to perform variable substitutions.
3433

3534
```csharp
36-
var parser = new TemplateParser
35+
var template = "hello {{name}}.";
36+
37+
var result = Template.Render(template, new()
3738
{
3839
Variables =
3940
{
4041
["name"] = "me"
4142
}
42-
};
43-
44-
var template = "hello {{name}}.";
43+
});
4544

46-
var result = parser.Render(template);
4745
Console.WriteLine(result); // Output: hello me.
4846
```
4947

5048
### Expression Substitution
5149

5250
```csharp
53-
var parser = new TemplateParser
51+
var template = "hello {{x => x.name.ToUpper()}}.";
52+
53+
var result = Template.Render(template, new()
5454
{
5555
Variables =
5656
{
5757
["name"] = "me"
5858
}
59-
};
60-
61-
var template = "hello {{x => x.name.ToUpper()}}.";
59+
});
6260

63-
var result = parser.Render(template);
6461
Console.WriteLine(result); // Output: hello ME.
6562
```
6663

@@ -69,19 +66,18 @@ Console.WriteLine(result); // Output: hello ME.
6966
Token values can contain other tokens.
7067

7168
```csharp
72-
var parser = new TemplateParser
69+
var template = "hello {{fullname}}.";
70+
71+
var result = Template.Render(template, new()
7372
{
7473
Variables =
7574
{
7675
["fullname"] = "{{first}} {{last}}",
7776
["first"] = "Hari",
7877
["last"] = "Seldon"
7978
}
80-
};
81-
82-
var template = "hello {{fullname}}.";
79+
});
8380

84-
var result = parser.Render(template);
8581
Console.WriteLine(result); // Output: hello Hari Seldon.
8682
```
8783

@@ -90,35 +86,33 @@ Console.WriteLine(result); // Output: hello Hari Seldon.
9086
You can use conditional tokens to control the flow based on conditions.
9187

9288
```csharp
93-
var parser = new TemplateParser
89+
var template = "{{#if condition}}hello {{name}}.{{/if}}";
90+
91+
var result = Template.Render(template, new()
9492
{
9593
Variables =
9694
{
9795
["condition"] = "true",
9896
["name"] = "me"
9997
}
100-
};
101-
102-
var template = "{{#if condition}}hello {{name}}.{{/if}}";
98+
});
10399

104-
var result = parser.Render(template);
105100
Console.WriteLine(result); // Output: hello me.
106101
```
107102

108103
```csharp
109-
var parser = new TemplateParser
104+
var template = "hello {{#if condition}}{{name1}}{{else}}{{name2}}{{/if}}.";
105+
106+
var result = Template.Render(template, new()
110107
{
111108
Variables =
112109
{
113110
["condition"] = "false",
114111
["name1"] = "me",
115112
["name2"] = "you",
116113
}
117-
};
118-
119-
var template = "hello {{#if condition}}{{name1}}{{else}}{{name2}}{{/if}}.";
114+
});
120115

121-
var result = parser.Render(template);
122116
Console.WriteLine(result); // Output: hello you.
123117
```
124118

@@ -127,17 +121,16 @@ Console.WriteLine(result); // Output: hello you.
127121
You can use a while statement to repeat a block of text while a condition is true.
128122

129123
```csharp
130-
var parser = new TemplateParser
124+
var template = "{{while x => x.counter<int> < 3}}{{counter}}{{counter:{{x => x.counter<int> + 1}}}}{{/while}}";
125+
126+
var result = Template.Render(template, new()
131127
{
132128
Variables =
133129
{
134130
["counter"] = "0"
135131
}
136-
};
137-
138-
var template = "{{while x => x.counter<int> < 3}}{{counter}}{{counter:{{x => x.counter<int> + 1}}}}{{/while}}";
132+
});
139133

140-
var result = parser.Render(template);
141134
Console.WriteLine(result); // Output: 012.
142135
```
143136

@@ -146,30 +139,31 @@ Console.WriteLine(result); // Output: 012.
146139
```csharp
147140
var template = "{{each n:x => x.list.Split( \",\" )}}World {{n}},{{/each}}";
148141

149-
var parser = new TemplateParser
142+
var result = Template.Render(template, new()
150143
{
151-
Variables = { ["list"] = "John,James,Sarah" }
152-
};
144+
Variables =
145+
{
146+
["list"] = "John,James,Sarah"
147+
}
148+
});
153149

154-
var result = parser.Render(template);
155150
Console.WriteLine(result); // hello World John,World James,World Sarah,.
156151
```
157152

158153
```csharp
159154

160155
var template = "{{each n:x => x.Where( t => Regex.IsMatch( t.Key, \"people*\" ) ).Select( t => t.Value )}}hello {{n}}. {{/each}}";
161156

162-
var parser = new TemplateParser
157+
var result = Template.Render(template, new()
163158
{
164159
Variables =
165-
{
166-
["people[0]"] = "John",
167-
["people[1]"] = "Jane",
168-
["people[2]"] = "Doe"
169-
}
170-
};
171-
172-
var result = parser.Render(template);
160+
{
161+
["people[0]"] = "John",
162+
["people[1]"] = "Jane",
163+
["people[2]"] = "Doe"
164+
}
165+
});
166+
173167
Console.WriteLine(result); // hello John. hello Jane. hello Doe.
174168
```
175169

@@ -182,11 +176,10 @@ var options = new TemplateOptions()
182176
.AddVariable("name", "me")
183177
.AddMethod("ToUpper").Expression<string,string>( value => value.ToUpper() );
184178

185-
var parser = new TemplateParser( options );
186-
187179
var template = "hello {{x => x.ToUpper( x.name )}}.";
188180

189-
var result = parser.Render(template);
181+
var result = Template.Render(template, options);
182+
190183
Console.WriteLine(result); // Output: hello ME.
191184
```
192185

docs/index.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,18 @@ dotnet add package Hyperbee.Templating
3434
### Basic Example: Variable Substitution
3535

3636
```csharp
37-
var parser = new TemplateParser
37+
var template = "hello {{fullname}}.";
38+
39+
var result = Template.Render(template, new()
3840
{
3941
Variables =
4042
{
4143
["fullname"] = "{{first}} {{last}}",
4244
["first"] = "Hari",
4345
["last"] = "Seldon"
4446
}
45-
};
46-
47-
var template = "hello {{fullname}}.";
47+
});
4848

49-
var result = parser.Render(template);
5049
Console.WriteLine(result); // Output: hello Hari Seldon.
5150
```
5251

docs/syntax/configuration.md

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,16 @@ Templating can be configured directly at `TemplateParser` construction or throug
3636
If you are performing simple variable substitution you can configure the `TemplateParser` directly.
3737

3838
```csharp
39-
var parser = new TemplateParser
39+
const string template = "hello {{who}}.";
40+
41+
var result = Template.Render(template, new()
4042
{
4143
Variables =
4244
{
4345
["who"] = "you"
4446
}
45-
};
46-
47-
const string template = "hello {{who}}.";
47+
});
4848

49-
var result = parser.Render(template);
5049
Console.WriteLine(result); // Output: hello you.
5150
```
5251

@@ -68,11 +67,9 @@ var options = new TemplateOptions()
6867
)
6968
.AddMethod("ToUpper", (string input) => input.ToUpper());
7069

71-
var parser = new TemplateParser(options);
72-
7370
const string template = "{{greeting}} {{name.ToUpper()}}!";
7471

75-
var result = parser.Render(template);
72+
var result = Template.Render(template, options);
7673
Console.WriteLine(result); // Output: Hello JOHN!
7774
```
7875

@@ -90,11 +87,9 @@ var options = new TemplateOptions()
9087
}
9188
);
9289

93-
var parser = new TemplateParser(options);
94-
9590
const string template = "{{greeting}} {{name}}, good {{timeOfDay}} from {{location}}!";
9691

97-
var result = parser.Render(template);
92+
var result = Template.Render(template, options);
9893
Console.WriteLine(result); // Output: Hello John, good morning from world!
9994
```
10095

@@ -104,23 +99,10 @@ Console.WriteLine(result); // Output: Hello John, good morning from world!
10499
var options = new TemplateOptions()
105100
.AddMethod("Format").Expression<string,string,string>((format, arg1, arg2) => string.Format(format, arg1, arg2));
106101

107-
var parser = new TemplateParser(options);
108-
109102
const string template = "{{Format('{0} and {1}', 'Alice', 'Bob')}}";
110103

111-
var result = parser.Render(template);
104+
var result = Template.Render(template, options);
112105
Console.WriteLine(result); // Output: Alice and Bob
113106
```
114107

115-
#### Example: Setting Token Style and Depth
116-
117-
```csharp
118-
var options = new TemplateOptions()
119-
.SetTokenStyle(TokenStyle.CurlyBraces)
120-
.SetMaxTokenDepth(10);
121-
122-
var parser = new TemplateParser(options);
123-
```
124-
125-
126108
{% endraw %}

0 commit comments

Comments
 (0)