Ver Fonte

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

* generate table

* Create permission-table.md
Vitor Ayres há 1 ano atrás
pai
commit
04440edce8
2 ficheiros alterados com 11 adições e 6 exclusões
  1. 5 0
      .changes/permission-table.md
  2. 6 6
      core/tauri-utils/src/acl/build.rs

+ 5 - 0
.changes/permission-table.md

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

+ 6 - 6
core/tauri-utils/src/acl/build.rs

@@ -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');
     }
   }