Skip to content

Commit 5048e1b

Browse files
authored
refactor(html): various cleanups (#555)
1 parent 7bdbb2d commit 5048e1b

File tree

14 files changed

+567
-302
lines changed

14 files changed

+567
-302
lines changed

examples/ddoc/main.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use clap::Arg;
55
use deno_doc::find_nodes_by_name_recursively;
66
use deno_doc::html::HrefResolver;
77
use deno_doc::html::ShortPath;
8+
use deno_doc::html::UrlResolveKind;
89
use deno_doc::DocNodeKind;
910
use deno_doc::DocParser;
1011
use deno_doc::DocParserOptions;
@@ -54,7 +55,7 @@ async fn run() -> anyhow::Result<()> {
5455
.arg(
5556
Arg::with_name("html")
5657
.long("html")
57-
.requires_all(&["name", "output"]),
58+
.requires_all(&["output"]),
5859
)
5960
.arg(Arg::with_name("name").long("name").takes_value(true))
6061
.arg(
@@ -74,9 +75,9 @@ async fn run() -> anyhow::Result<()> {
7475
let source_files = matches.values_of("source_files").unwrap();
7576
let html = matches.is_present("html");
7677
let name = if html {
77-
matches.value_of("name").unwrap().to_string()
78+
matches.value_of("name").map(|name| name.to_string())
7879
} else {
79-
"".to_string()
80+
None
8081
};
8182
let main_entrypoint = if html {
8283
matches.value_of("main_entrypoint").map(|main_entrypoint| {
@@ -174,6 +175,14 @@ fn main() {
174175
struct EmptyResolver();
175176

176177
impl HrefResolver for EmptyResolver {
178+
fn resolve_path(
179+
&self,
180+
current: UrlResolveKind,
181+
target: UrlResolveKind,
182+
) -> String {
183+
deno_doc::html::href_path_resolve(current, target)
184+
}
185+
177186
fn resolve_global_symbol(&self, _symbol: &[String]) -> Option<String> {
178187
None
179188
}
@@ -200,7 +209,7 @@ impl HrefResolver for EmptyResolver {
200209
}
201210

202211
fn generate_docs_directory(
203-
name: String,
212+
package_name: Option<String>,
204213
output_dir: String,
205214
main_entrypoint: Option<ModuleSpecifier>,
206215
doc_nodes_by_url: IndexMap<ModuleSpecifier, Vec<deno_doc::DocNode>>,
@@ -214,15 +223,14 @@ fn generate_docs_directory(
214223
}
215224

216225
let options = deno_doc::html::GenerateOptions {
217-
package_name: Some(name),
226+
package_name,
218227
main_entrypoint,
219228
href_resolver: Rc::new(EmptyResolver()),
220229
usage_composer: None,
221230
rewrite_map: Some(index_map),
222-
hide_module_doc_title: false,
223-
sidebar_flatten_namespaces: false,
231+
composable_output: true,
224232
};
225-
let html = deno_doc::html::generate(options.clone(), doc_nodes_by_url)?;
233+
let html = deno_doc::html::generate(options, doc_nodes_by_url)?;
226234

227235
let path = &output_dir_resolved;
228236
let _ = std::fs::remove_dir_all(path);

src/html/jsdoc.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,8 @@ pub struct ExampleCtx {
479479
}
480480

481481
impl ExampleCtx {
482+
pub const TEMPLATE: &'static str = "example";
483+
482484
pub fn new(render_ctx: &RenderContext, example: &str, i: usize) -> Self {
483485
let id = name_to_id("example", &i.to_string());
484486

@@ -511,6 +513,8 @@ pub struct ModuleDocCtx {
511513
}
512514

513515
impl ModuleDocCtx {
516+
pub const TEMPLATE: &'static str = "module_doc";
517+
514518
pub fn new(
515519
render_ctx: &RenderContext,
516520
specifier: &ModuleSpecifier,

0 commit comments

Comments
 (0)