feat(utils): generate table markdown of permissions (#9019)

* generate table

* Create permission-table.md
This commit is contained in:
Vitor Ayres 2024-02-28 13:15:44 -03:00 committed by GitHub
parent 3657ad82f8
commit 04440edce8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 6 deletions

View File

@ -0,0 +1,5 @@
---
"tauri-utils": patch:enhance
---
Changed plugin markdown docs generation to table format.

View File

@ -235,12 +235,12 @@ pub fn generate_schema<P: AsRef<Path>>(
/// Generate a markdown documentation page containing the list of permissions of the plugin.
pub fn generate_docs(permissions: &[PermissionFile], out_dir: &Path) -> Result<(), Error> {
let mut docs = "# Permissions\n\n".to_string();
let mut docs = "| Permission | Description |\n|------|-----|\n".to_string();
fn docs_from(id: &str, description: Option<&str>) -> String {
let mut docs = format!("## {id}");
let mut docs = format!("|`{id}`");
if let Some(d) = description {
docs.push_str(&format!("\n\n{d}"));
docs.push_str(&format!("|{d}|"));
}
docs
}
@ -248,12 +248,12 @@ pub fn generate_docs(permissions: &[PermissionFile], out_dir: &Path) -> Result<(
for permission in permissions {
for set in &permission.set {
docs.push_str(&docs_from(&set.identifier, Some(&set.description)));
docs.push_str("\n\n");
docs.push('\n');
}
if let Some(default) = &permission.default {
docs.push_str(&docs_from("default", default.description.as_deref()));
docs.push_str("\n\n");
docs.push('\n');
}
for permission in &permission.permission {
@ -261,7 +261,7 @@ pub fn generate_docs(permissions: &[PermissionFile], out_dir: &Path) -> Result<(
&permission.identifier,
permission.description.as_deref(),
));
docs.push_str("\n\n");
docs.push('\n');
}
}