Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/permission-table.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -233,33 +233,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
Loading