Crates.io | yagenerator |
lib.rs | yagenerator |
version | 0.1.3 |
source | src |
created_at | 2020-10-31 20:54:47.960587 |
updated_at | 2020-11-01 21:44:16.04463 |
description | Application that uses tinytemplate engine to generate text files. If you have a set of structured data, and need to generated a bunch of arbitrary types of files from it, this tool can help you to save some time. |
homepage | |
repository | https://gitlab.com/ecruzolivera/yagenerator |
max_upload_size | |
id | 307325 |
size | 232,954 |
Rust application, if you have a set of structured data and need to generated a bunch of arbitrary types of files from it, this tool can help you to save some time. Is a text generation tool, not a code generation one, the difference is subtle but important. It has no knowledge about the semantics of whatever is generating, for the application everything is text.
Is recommended to first read the tiny template documentation in order to understand what that brights to the table.
Can be installed directly with cargo:
cargo install yagenerator
See the examples:
Generate files given:
Example of use:
yagenerator -d data.yaml -c template_config.yaml
It works by passing the data in the data file "as it is" and with the same structure to the template(s). The template syntax must conform with the requirements of the TinyTemplate rust crate.
It uses the unescaped formatter and in addition implements the following custom value formatters:
The documentation of the formatters can be found in the Inflector crate
The data file can be in json or yaml format, is a hashmap (a.k.a dictionary) were each key must be a string, and will serve as the data ID. The values can be arbitrary json or yaml data, and will be passed as is to the templates.
Is a list/array of objects with a well defined schema
Required field per configuration :
$id: http://example.com/example.json
$schema: http://json-schema.org/draft-07/schema
title: The root schema
type: array
additionalItems: true
default: []
items:
$id: '#/items'
anyOf:
- $id: '#/items/anyOf/0'
additionalProperties: true
title: The first anyOf schema
type: object
properties:
data_to_use_id:
$id: '#/items/anyOf/0/properties/data_to_use_id'
default: ''
title: The data_to_use_id schema
type: string
destination_path:
$id: '#/items/anyOf/0/properties/destination_path'
default: ''
title: The destination_path schema
type: string
enabled:
$id: '#/items/anyOf/0/properties/enabled'
default: false
title: The enabled schema
type: boolean
file_path:
$id: '#/items/anyOf/0/properties/file_path'
default: ''
title: The file_path schema
type: string
operation:
$id: '#/items/anyOf/0/properties/operation'
default: ''
title: The operation schema
type: string
required:
- data_to_use_id
- file_path
- destination_path
- operation
- enabled
$id: http://example.com/example.json
$schema: http://json-schema.org/draft-07/schema
additionalItems: true
default: []
description: The root schema comprises the entire JSON document.
examples:
- - data_to_use_id: IODevice
destination_path: /tmp/IODevice.hpp
enabled: true
file_path: ./tests/templates/Interface.hpp.txt
operation: Create
- data_to_use_id: TimeDate
destination_path: /tmp/TimeDate.h
enabled: true
file_path: ./tests/templates/Class.h.txt
operation: Create
items:
$id: '#/items'
anyOf:
- $id: '#/items/anyOf/0'
additionalProperties: true
default: {}
description: An explanation about the purpose of this instance.
examples:
- data_to_use_id: IODevice
destination_path: /tmp/IODevice.hpp
enabled: true
file_path: ./tests/templates/Interface.hpp.txt
operation: Create
properties:
data_to_use_id:
$id: '#/items/anyOf/0/properties/data_to_use_id'
default: ''
description: An explanation about the purpose of this instance.
examples:
- IODevice
title: The data_to_use_id schema
type: string
destination_path:
$id: '#/items/anyOf/0/properties/destination_path'
default: ''
description: An explanation about the purpose of this instance.
examples:
- /tmp/IODevice.hpp
title: The destination_path schema
type: string
enabled:
$id: '#/items/anyOf/0/properties/enabled'
default: false
description: An explanation about the purpose of this instance.
examples:
- true
title: The enabled schema
type: boolean
file_path:
$id: '#/items/anyOf/0/properties/file_path'
default: ''
description: An explanation about the purpose of this instance.
examples:
- ./tests/templates/Interface.hpp.txt
title: The file_path schema
type: string
operation:
$id: '#/items/anyOf/0/properties/operation'
default: ''
description: An explanation about the purpose of this instance.
examples:
- Create
title: The operation schema
type: string
required:
- data_to_use_id
- file_path
- destination_path
- operation
- enabled
title: The first anyOf schema
type: object
title: The root schema
type: array