Skip to content

Commit 3987a6b

Browse files
added C#, TS and VB
1 parent e4a0de0 commit 3987a6b

File tree

10 files changed

+18788
-22
lines changed

10 files changed

+18788
-22
lines changed

CS/TextualTemplates.cs

Lines changed: 6143 additions & 0 deletions
Large diffs are not rendered by default.

CS/make.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dotnet build

CS/pbTpl.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>library</OutputType>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
<LangVersion>6</LangVersion>
6+
</PropertyGroup>
7+
</Project>

README.md

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,51 @@
1-
# pbTpl - pb Template Library
2-
A template library available in many programming languages. Goals of this library are to
1+
# pbTpl - pb Templates
2+
A template library available in many programming languages made with progsbase. The goals of this library are to
33

44
1) Have a single library for templating that is stable accross programming languages and over time.
55
2) Is easy to build in any programming language and to include in any project.
66
3) Is easy to use.
77

8+
89
## Available in the Following Languages
910

11+
[TypeScript](TypeScript/) |
1012
[Java](Java/) |
1113
[C](C/) |
1214
[C++](Cpp/) |
1315
[JavaScript](JavaScript/) |
1416
[PHP](PHP/) |
17+
[C#](CS/) |
1518
[Python](Python/) |
16-
[Ruby](Ruby/)
19+
[Ruby](Ruby/) |
20+
[Visual Basic](VisualBasic/)
21+
1722

1823
## Main Function
1924
The library is available in the programming languages above. The main function for using a template is as follows:
2025

2126
```
22-
boolean GenerateDocument(char [] template, Element data, StringReference document, StringReference errorMessage)
27+
boolean GenerateDocument(char [] template, char [] json, StringReference document, StringReference errorMessage);
2328
```
2429

25-
This function takes a template `template` and a parsed JSON structure `data`. It returns true on success or false on failure. On success, `document.string` is set to the result, if not `errorMessage.string` is filled with an error message.
26-
27-
To parse a JSON string into an `Element` structure, use:
30+
This function takes a template string `template` and JSON string `json`. It returns true on success or false on failure. On success, `document.string` is set to the result; on failure `errorMessage.string` is filled with an error message.
2831

29-
```
30-
public static boolean ReadJSON(char [] string, ElementReference elementReference, StringArrayReference errorMessages)
31-
```
3232

33-
Here, `string` is the JSON string. The function returns true on success and false on failure. If success, `elementReference.element` is set to the the result, if not `errorMessages.stringArray` is filled with error messages.
34-
35-
## General User Guide
33+
## General About Templates
3634
A textual template is text with certain parts left out that will be filled in by a generation step. The source for filling in is a data structure generated from a JSON file.
3735

3836
Templates are used for many different things in production systems. Most websites are generated based on a template, be it directly in the front end, such as with Angular, React and Vue, or in the backend. Templates are also used for production of formal documents and emails.
3937

40-
### Tags and Their Functions
4138

42-
#### Print Value
39+
## Tags and Their Functions
40+
41+
### Print Value
4342
```
4443
{print a}
4544
```
4645

4746
Will print the value of a. If it is a JSON object or structure, the JSON repressentation will be printed.
4847

49-
#### Use structure
48+
### Use structure
5049
```
5150
{use a}
5251
{print b}
@@ -55,15 +54,15 @@ Will print the value of a. If it is a JSON object or structure, the JSON repress
5554

5655
This will cause a.b to be printed. Inside the use structure, the variables inside structure a can be used.
5756

58-
#### Iterate
57+
### Iterate
5958
```
6059
{foreach a in b}
6160
{end}
6261
```
6362

6463
This will iterate over all elements of the array `b`. Each element will be known as `a` inside. If `a` is an object, it will automatically be used inside the foreach loop, so there is no need to write `{use a}`.
6564

66-
#### If-else
65+
### If-else
6766
```
6867
{if a}
6968
{else}
@@ -75,16 +74,18 @@ If a is true, the first block is printed, else the else block. The else block is
7574
### Escape
7675
If you want to output `{` followed directly by one of the command strings, use a backslash in front. If the `{` is not followed directly by one of the commands, the text is simply output.
7776

78-
### How to Work with Templates
77+
78+
79+
## How to Work with Templates
7980
There are three main issues with using templates:
8081

81-
#### The data model
82+
### The data model
8283
Generate all the data that is to be filled into the document. This includes decision variables if some information is included or left out based on conditions.
8384

84-
#### Templates
85+
### Templates
8586
Write the template with the tags to fill in information. There is no need for complex logic or formatting commands, as this should be taken care of during data model generation. The reason is that the code should be in the code and not in the template.
8687

87-
#### Locale and Formatting
88+
### Locale and Formatting
8889
Special formatting of numbers should be taken care of during data model generation. This is better as a full fledged programming language is available.
8990

9091

0 commit comments

Comments
 (0)