Plugins (dependencies)

This document introduces the plugins involved in the development of GenUI and how to configure them. Plugins play an important role in extending the functionality of GenUI, providing developers with a more flexible development experience.

Plugin Overview

The plugins here refer to the dependency libraries required in the development of GenUI. The official plugins are stored in the GenUI Plugins repository.

The current official plugins include:

  • gen_makepad_http: A plugin that provides HTTP network request support.

Plugin Structure

In the GenUI project, plugins consist of the following two parts:

  1. Plugin source code
  • Responsible for implementing the specific functional logic of the plugin.
  1. Dynamic loading configuration (token.toml file)
  • The configuration file describes the plugin's metadata and dynamic enhancement logic.

Dynamic loading configuration

Each plugin needs to include a file called token.toml. The GenUI compiler provides syntax enhancements for Rust scripts by dynamically loading this file.

Example Configuration File

Here is an example of a complete token.toml configuration file:

token.toml
1[plugin]
2name = "gen_makepad_http"
3authors = ["syf<syf20020816@outlook.com>"]
4version = "0.1.0"
5description = "http support for makepad"
6category = "network"
7repo = { git = "https://github.com/Privoce/genui_plugins/tree/main/projects/gen_makepad_http" }
8
9[macros]
10http_get = { category = "prop_macro", stmts = 'if mac . ident == "http_get" { mac . tokens . push_str (", cx") ; return true; }' }
11http_post = { category = "prop_macro", stmts = 'if mac . ident == "http_post" { mac . tokens . push_str (", cx") ; return true; }' }
12http_put = { category = "prop_macro", stmts = 'if mac . ident == "http_put" { mac . tokens . push_str (", cx") ; return true; }' }
13http_delete = { category = "prop_macro", stmts = 'if mac . ident == "http_delete" { mac . tokens . push_str (", cx") ; return true; }' }
14http_patch = { category = "prop_macro", stmts = 'if mac . ident == "http_patch" { mac . tokens . push_str (", cx") ; return true; }' }
15
16[dependencies]
17serde = "1.0.217"
18lazy_static = "1.5.0"
19serde_json = "1.0.135"

Detailed explanation of configuration items

Basic plugin configuration

The following is the specific configuration of the [plugin] section in the token.toml file:

1[plugin]
2name = "gen_makepad_http"
3authors = ["syf<syf20020816@outlook.com>"]
4version = "0.1.0"
5description = "http support for makepad"
6category = "network"
7repo = { git = "https://github.com/Privoce/genui_plugins/tree/main/projects/gen_makepad_http" }
FieldTypeDescription
nameStringPlugin name (unique identifier).
authorsVec<String>Plugin author list.
versionStringPlugin version number.
descriptionStringPlugin functional description.
categoryStringPlugin category (such as network, UI, etc.).
repoObjectPlugin code repository information.

Dynamic code block

The [macros] section defines the dynamic code block of the plugin. When the GenUI compiler encounters the specified macro, it will call the corresponding code for processing.

Example

1[macros]
2http_get = {
3    category = "prop_macro",
4    stmts = 'if mac . ident == "http_get" { mac . tokens . push_str (", cx") ; return true; }'
5}
FieldTypeDescription
categoryStringIndicates the category of the macro, such as prop_macro.
stmtsStringDynamic code block used to process the logic of the macro.

Functional Description: When the compiler encounters the http_get! macro in the script, it will execute the code in stmts for dynamic processing. The purpose of the above code is to expand a cx parameter to the syntax tree (tt) inside the macro, and return true if the processing is successful.

Plugin Dependencies

The [dependencies] section declares the dependencies of the plugin.

Example

1[dependencies]
2serde = "1.0.217"
3lazy_static = "1.5.0"
4serde_json = "1.0.135"
FieldTypeDescription
serdeStringLibrary for serialization and deserialization.
lazy_staticStringLibrary for defining static variables.
serde_jsonStringLibrary for processing JSON data.

Notes on using plugins

  1. Ensure the completeness of the plugin configuration file:
  • token.toml must contain [plugin], [macros], and [dependencies] sections.
  1. Version management:
  • Ensure that the versions of the plugin and its dependencies are compatible with the version of the project.
  1. Correctness of dynamic code blocks:
  • Ensure that the macro processing logic (stmts) meets the project requirements to avoid potential compilation errors.

Through the above configuration and usage instructions, developers can efficiently integrate and use GenUI's plugin system.