Skip to content

Commit

Permalink
feat(utils): generate table markdown of permissions (#9019)
Browse files Browse the repository at this point in the history
* generate table

* Create permission-table.md
  • Loading branch information
vasfvitor committed Feb 28, 2024
1 parent 3657ad8 commit 04440ed
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changes/permission-table.md
@@ -0,0 +1,5 @@
---
"tauri-utils": patch:enhance
---

Changed plugin markdown docs generation to table format.
12 changes: 6 additions & 6 deletions core/tauri-utils/src/acl/build.rs
Expand Up @@ -235,33 +235,33 @@ 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
}

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 {
docs.push_str(&docs_from(
&permission.identifier,
permission.description.as_deref(),
));
docs.push_str("\n\n");
docs.push('\n');
}
}

Expand Down

0 comments on commit 04440ed

Please sign in to comment.