Skip to content

Commit 3fee96f

Browse files
readme
1 parent f373847 commit 3fee96f

File tree

4 files changed

+259
-0
lines changed

4 files changed

+259
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
````markdown
2+
# Neutral TS IPC Client Go
3+
4+
**IPC Client Go is experimental.**
5+
6+
This package provides a minimal Go client for Neutral TS templates using the IPC server.
7+
8+
The client exposes `NeutralIpcTemplate` which lets you render a template by sending a schema
9+
and template path (or source) to the IPC server and receiving the rendered content.
10+
11+
Example
12+
-------
13+
14+
```go
15+
package main
16+
17+
import (
18+
"encoding/json"
19+
"fmt"
20+
"path/filepath"
21+
"runtime"
22+
"os"
23+
24+
// Import the Neutral IPC client package.
25+
// The client sources are available at:
26+
// https://github.com/FranBarInstance/neutral-ipc/tree/master/clients
27+
// Replace the import path below according to your module layout.
28+
"neutral_ipc_template"
29+
)
30+
31+
func main() {
32+
// The schema contains the data and variables for the template
33+
schema := map[string]interface{}{
34+
"data": map[string]interface{}{
35+
"hello": "Hello World",
36+
},
37+
}
38+
39+
// Convert schema to JSON string
40+
schemaBytes, _ := json.Marshal(schema)
41+
schemaJSON := string(schemaBytes)
42+
43+
// Determine the template full path (template.ntpl should be next to this README)
44+
_, b, _, _ := runtime.Caller(0)
45+
dir := filepath.Dir(b)
46+
template := filepath.Join(dir, "template.ntpl")
47+
48+
// Create a NeutralIpcTemplate instance
49+
ipc := neutral_ipc_template.NewNeutralIpcTemplate(template, schemaJSON)
50+
51+
// Render the template
52+
contents := ipc.Render()
53+
54+
// e.g.: 200
55+
statusCode := ipc.GetStatusCode()
56+
57+
// e.g.: OK
58+
statusText := ipc.GetStatusText()
59+
60+
// empty if no error
61+
statusParam := ipc.GetStatusParam()
62+
63+
// Act according to your framework to display the content
64+
// for this example, simply output
65+
fmt.Println(contents)
66+
}
67+
```
68+
69+
Links
70+
-----
71+
72+
Neutral TS template engine.
73+
74+
- [Template docs](https://github.com/FranBarInstance/neutralts-docs/docs/neutralts/doc/)
75+
- [Repository](https://github.com/FranBarInstance/neutralts)
76+
- [Crate](https://crates.io/crates/neutralts)
77+
- [Examples](https://github.com/FranBarInstance/neutralts-docs/tree/master/examples)
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
Neutral TS IPC Client Node.js
2+
=============================
3+
4+
**IPC Client Node.js is experimental.**
5+
6+
This package provides a minimal Node.js client for Neutral TS templates using the IPC server.
7+
8+
The client exposes `NeutralIpcTemplate` which lets you render a template by sending a schema
9+
and template path (or source) to the IPC server and receiving the rendered content.
10+
11+
Example
12+
-------
13+
14+
```javascript
15+
// Require the client files included in this example
16+
// https://github.com/FranBarInstance/neutral-ipc/tree/master/clients
17+
const NeutralIpcTemplate = require('./neutral_ipc_template/NeutralIpcTemplate');
18+
19+
// The schema contains among other things the data and variables for the template
20+
const schema = {
21+
data: {
22+
hello: 'Hello World'
23+
}
24+
};
25+
26+
// Determine the template full path
27+
const path = require('path');
28+
const template = path.join(__dirname, 'template.ntpl');
29+
30+
// Create an instance of NeutralIpcTemplate (accepts object or JSON string for schema)
31+
const ipcTemplate = new NeutralIpcTemplate(template, schema);
32+
33+
// Render the template (synchronous or asynchronous depending on the client implementation)
34+
// Here we assume a synchronous-style API for simplicity. Consult the implementation in
35+
// `NeutralIpcTemplate.js` for details.
36+
const contents = ipcTemplate.render();
37+
38+
// e.g.: 200
39+
const status_code = ipcTemplate.get_status_code();
40+
41+
// e.g.: OK
42+
const status_text = ipcTemplate.get_status_text();
43+
44+
// empty if no error
45+
const status_param = ipcTemplate.get_status_param();
46+
47+
// Act according to your framework to display the content
48+
// for this example, simply output
49+
console.log(contents);
50+
```
51+
52+
Links
53+
-----
54+
55+
Neutral TS template engine.
56+
57+
- [Template docs](https://github.com/FranBarInstance/neutralts-docs/docs/neutralts/doc/)
58+
- [Repository](https://github.com/FranBarInstance/neutralts)
59+
- [Crate](https://crates.io/crates/neutralts)
60+
- [Examples](https://github.com/FranBarInstance/neutralts-docs/tree/master/examples)
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Neutral TS IPC Client PHP
2+
3+
This package provides a minimal PHP client for Neutral TS templates using the IPC server.
4+
5+
The client exposes `NeutralIpcTemplate` which lets you render a template by sending a schema
6+
and template path (or source) to the IPC server and receiving the rendered content.
7+
8+
Example
9+
-------
10+
11+
```php
12+
// Include NeutralIpcTemplate: https://github.com/FranBarInstance/neutral-ipc/clients
13+
include 'neutral_ipc_template/NeutralIpcTemplate.php';
14+
15+
// The schema contains the data and variables for the template
16+
$schema = [
17+
'data' => [
18+
'hello' => 'Hello World',
19+
],
20+
];
21+
22+
// Determine the template full path
23+
$template = __DIR__ . '/template.ntpl';
24+
25+
// Create an instance of NeutralIpcTemplate (accepts array or JSON string for schema)
26+
$ipc_template = new NeutralIpcTemplate($template, $schema);
27+
28+
// Render the template
29+
$contents = $ipc_template->render();
30+
31+
// e.g.: 200
32+
$status_code = $ipc_template->get_status_code();
33+
34+
// e.g.: OK
35+
$status_text = $ipc_template->get_status_text();
36+
37+
// empty if no error
38+
$status_param = $ipc_template->get_status_param();
39+
40+
// Act according to your framework to display the content
41+
// for this example, simply output
42+
echo $contents;
43+
44+
```
45+
46+
Links
47+
-----
48+
49+
Neutral TS template engine.
50+
51+
- [Template docs](https://github.com/FranBarInstance/neutralts-docs/docs/neutralts/doc/)
52+
- [Repository](https://github.com/FranBarInstance/neutralts)
53+
- [Crate](https://crates.io/crates/neutralts)
54+
- [Examples](https://github.com/FranBarInstance/neutralts-docs/tree/master/examples)
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Neutral TS IPC Client Python
2+
3+
This package provides a minimal Python client for Neutral TS templates using the IPC server.
4+
5+
The client exposes `NeutralIpcTemplate` which lets you render a template by sending a schema
6+
and template path (or source) to the IPC server and receiving the rendered content.
7+
8+
Alternatively, you can use Neutral TS as a package without needing an IPC server:
9+
[pypi.org/project/neutraltemplate/](https://pypi.org/project/neutraltemplate/)
10+
11+
Example
12+
-------
13+
14+
```python
15+
import json # Required to pass the schema as json to NeutralIpcTemplate
16+
import os # Required to determine the path of the .ntpl template
17+
import sys
18+
19+
# Add parent directory to sys.path to find sibling packages
20+
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'))
21+
22+
# Import NeutralIpcTemplate:
23+
# https://github.com/FranBarInstance/neutral-ipc/tree/master/clients
24+
from neutral_ipc_template import NeutralIpcTemplate
25+
26+
# The schema contains among other things the data and variables for the template
27+
schema = {
28+
"data": {
29+
"hello": "Hello World"
30+
}
31+
}
32+
33+
# Determine the template full path
34+
template = os.path.dirname(os.path.abspath(__file__)) + "/template.ntpl"
35+
36+
# Pass the schema as json to NeutralTemplate
37+
schema_json = json.dumps(schema_dict)
38+
39+
# Create an instance of NeutralTemplate
40+
ipc_template = NeutralIpcTemplate(template, schema_json)
41+
42+
# Render the template
43+
contents = ipc_template.render()
44+
45+
# e.g.: 200
46+
status_code = ipc_template.get_status_code()
47+
48+
# e.g.: OK
49+
status_text = ipc_template.get_status_text()
50+
51+
# empty if no error
52+
status_param = ipc_template.get_status_param()
53+
54+
# Act according to your framework to display the content
55+
# for this example, simply output
56+
print(contents)
57+
58+
```
59+
60+
Links
61+
-----
62+
63+
Neutral TS template engine.
64+
65+
- [Template docs](https://github.com/FranBarInstance/neutralts-docs/docs/neutralts/doc/)
66+
- [Repository](https://github.com/FranBarInstance/neutralts)
67+
- [Crate](https://crates.io/crates/neutralts)
68+
- [Examples](https://github.com/FranBarInstance/neutralts-docs/tree/master/examples)

0 commit comments

Comments
 (0)