Allow hidden modules, not generating any documentation.

This is useful when splitting module for dependencies, yet without the desire to expose internal constructors and types. This merely skips the documentation generation; but doesn't prevent the hidden module from being accessible.
This commit is contained in:
KtorZ 2024-08-22 15:29:49 +02:00
parent 7eee3ce63c
commit 44e42d608d
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
2 changed files with 23 additions and 9 deletions

View File

@ -127,6 +127,10 @@ pub fn generate_all(root: &Path, config: &Config, modules: Vec<&CheckedModule>)
let mut search_indexes: Vec<SearchIndex> = vec![]; let mut search_indexes: Vec<SearchIndex> = vec![];
for module in &modules { for module in &modules {
if module.skip_doc_generation() {
continue;
}
let (indexes, file) = generate_module(config, module, &modules_links, &source, &timestamp); let (indexes, file) = generate_module(config, module, &modules_links, &source, &timestamp);
if !indexes.is_empty() { if !indexes.is_empty() {
search_indexes.extend(indexes); search_indexes.extend(indexes);
@ -356,15 +360,16 @@ fn generate_modules_links(modules: &[&CheckedModule]) -> Vec<DocLink> {
let non_empty_modules = modules let non_empty_modules = modules
.iter() .iter()
.filter(|module| { .filter(|module| {
module.ast.definitions.iter().any(|def| { !module.skip_doc_generation()
matches!( && module.ast.definitions.iter().any(|def| {
def, matches!(
Definition::Fn(Function { public: true, .. }) def,
| Definition::DataType(DataType { public: true, .. }) Definition::Fn(Function { public: true, .. })
| Definition::TypeAlias(TypeAlias { public: true, .. }) | Definition::DataType(DataType { public: true, .. })
| Definition::ModuleConstant(ModuleConstant { public: true, .. }) | Definition::TypeAlias(TypeAlias { public: true, .. })
) | Definition::ModuleConstant(ModuleConstant { public: true, .. })
}) )
})
}) })
.sorted_by(|a, b| a.name.cmp(&b.name)) .sorted_by(|a, b| a.name.cmp(&b.name))
.collect_vec(); .collect_vec();

View File

@ -291,6 +291,15 @@ pub struct CheckedModule {
} }
impl CheckedModule { impl CheckedModule {
pub fn skip_doc_generation(&self) -> bool {
self.ast
.docs
.first()
.map(|s| s.as_str().trim())
.unwrap_or_default()
== "@hidden"
}
pub fn to_cbor(&self) -> Vec<u8> { pub fn to_cbor(&self) -> Vec<u8> {
let mut module_bytes = vec![]; let mut module_bytes = vec![];