Skip to content

fix(html): minor cleanup and fixes #559

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

Merged
merged 1 commit into from
Apr 24, 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
7 changes: 4 additions & 3 deletions examples/ddoc/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use clap::App;
use clap::Arg;
use deno_doc::find_nodes_by_name_recursively;
use deno_doc::html::HrefResolver;
use deno_doc::html::ShortPath;
use deno_doc::html::UrlResolveKind;
use deno_doc::DocNodeKind;
use deno_doc::DocParser;
Expand Down Expand Up @@ -195,8 +194,10 @@ impl HrefResolver for EmptyResolver {
None
}

fn resolve_usage(&self, current_file: &ShortPath) -> Option<String> {
Some(current_file.specifier.to_string())
fn resolve_usage(&self, current_resolve: UrlResolveKind) -> Option<String> {
current_resolve
.get_file()
.map(|current_file| current_file.specifier.to_string())
}

fn resolve_source(&self, location: &deno_doc::Location) -> Option<String> {
Expand Down
3 changes: 1 addition & 2 deletions src/html/jsdoc.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use super::render_context::RenderContext;
use super::util::*;
use crate::html::usage::UsagesCtx;
use crate::html::FileMode;
use crate::html::ShortPath;
use crate::js_doc::JsDoc;
use crate::js_doc::JsDocTag;
Expand Down Expand Up @@ -602,7 +601,7 @@ impl ModuleDocCtx {
(None, None, None)
};

if short_path.is_main && render_ctx.ctx.file_mode == FileMode::SingleDts {
if !short_path.is_main {
let partitions_by_kind =
super::partition::partition_nodes_by_kind(module_doc_nodes, true);

Expand Down
11 changes: 5 additions & 6 deletions src/html/render_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ impl<'ctx> RenderContext<'ctx> {
is_first_symbol: false,
}];

if file.is_main {
if !file.is_main {
parts.push(BreadcrumbCtx {
name: file.display_name(),
href: self
Expand Down Expand Up @@ -320,11 +320,10 @@ mod test {
Some(format!("{src}/{}", symbol.join(".")))
}

fn resolve_usage(
&self,
current_file: &crate::html::ShortPath,
) -> Option<String> {
Some(current_file.specifier.to_string())
fn resolve_usage(&self, current_resolve: UrlResolveKind) -> Option<String> {
current_resolve
.get_file()
.map(|current_file| current_file.specifier.to_string())
}

fn resolve_source(&self, location: &Location) -> Option<String> {
Expand Down
2 changes: 1 addition & 1 deletion src/html/templates/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ summary::-webkit-details-marker {
}

.namespaceSection {
@apply grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-y-3 md:gap-x-3 md:gap-y-8;
@apply grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-y-3 md:gap-x-8 md:gap-y-8;
.namespaceItem {
@apply flex gap-x-2.5;

Expand Down
2 changes: 1 addition & 1 deletion src/html/templates/styles.gen.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/html/usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl UsagesCtx {
let url = ctx
.ctx
.href_resolver
.resolve_usage(ctx.get_current_resolve().get_file()?)?;
.resolve_usage(ctx.get_current_resolve())?;

if let Some(usage_composer) = &ctx.ctx.usage_composer {
let usages = usage_composer(ctx, doc_nodes, url);
Expand Down
2 changes: 1 addition & 1 deletion src/html/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ pub trait HrefResolver {
-> Option<String>;

/// Resolve the URL used in "usage" blocks.
fn resolve_usage(&self, current_file: &ShortPath) -> Option<String>;
fn resolve_usage(&self, current_resolve: UrlResolveKind) -> Option<String>;

/// Resolve the URL used in source code link buttons.
fn resolve_source(&self, location: &crate::Location) -> Option<String>;
Expand Down
6 changes: 4 additions & 2 deletions tests/html_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ impl HrefResolver for EmptyResolver {
None
}

fn resolve_usage(&self, current_file: &ShortPath) -> Option<String> {
Some(current_file.path.clone())
fn resolve_usage(&self, current_resolve: UrlResolveKind) -> Option<String> {
current_resolve
.get_file()
.map(|current_file| current_file.path.to_string())
}

fn resolve_source(&self, _location: &deno_doc::Location) -> Option<String> {
Expand Down
32 changes: 31 additions & 1 deletion tests/testdata/module_doc-syntect.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,37 @@
"sections": {
"id": "module_doc",
"docs": null,
"sections": []
"sections": [
{
"header": {
"title": "Functions",
"href": null,
"doc": null
},
"content": {
"kind": "namespace_section",
"content": [
{
"tags": [],
"doc_node_kind_ctx": [
{
"kind": "Function",
"char": "f",
"title": "Function",
"title_lowercase": "function",
"title_plural": "Functions"
}
],
"origin_name": null,
"href": "../.././foo/~/x.html",
"name": "x",
"docs": null,
"deprecated": false
}
]
}
}
]
}
}
]
32 changes: 31 additions & 1 deletion tests/testdata/module_doc-tree-sitter.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,37 @@
"sections": {
"id": "module_doc",
"docs": null,
"sections": []
"sections": [
{
"header": {
"title": "Functions",
"href": null,
"doc": null
},
"content": {
"kind": "namespace_section",
"content": [
{
"tags": [],
"doc_node_kind_ctx": [
{
"kind": "Function",
"char": "f",
"title": "Function",
"title_lowercase": "function",
"title_plural": "Functions"
}
],
"origin_name": null,
"href": "../.././foo/~/x.html",
"name": "x",
"docs": null,
"deprecated": false
}
]
}
}
]
}
}
]
32 changes: 31 additions & 1 deletion tests/testdata/module_doc.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,37 @@
"sections": {
"id": "module_doc",
"docs": null,
"sections": []
"sections": [
{
"header": {
"title": "Functions",
"href": null,
"doc": null
},
"content": {
"kind": "namespace_section",
"content": [
{
"tags": [],
"doc_node_kind_ctx": [
{
"kind": "Function",
"char": "f",
"title": "Function",
"title_lowercase": "function",
"title_plural": "Functions"
}
],
"origin_name": null,
"href": "../.././foo/~/x.html",
"name": "x",
"docs": null,
"deprecated": false
}
]
}
}
]
}
}
]
54 changes: 6 additions & 48 deletions tests/testdata/symbol_group-syntect.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,6 @@
"is_symbol": false,
"is_first_symbol": false
},
{
"name": "default",
"href": "../",
"is_symbol": false,
"is_first_symbol": false
},
{
"name": "Bar",
"href": "../././~/Bar.html",
Expand Down Expand Up @@ -354,12 +348,6 @@
"is_symbol": false,
"is_first_symbol": false
},
{
"name": "default",
"href": "../",
"is_symbol": false,
"is_first_symbol": false
},
{
"name": "Foo",
"href": "../././~/Foo.html",
Expand Down Expand Up @@ -507,12 +495,6 @@
"is_symbol": false,
"is_first_symbol": false
},
{
"name": "default",
"href": "../",
"is_symbol": false,
"is_first_symbol": false
},
{
"name": "Foobar",
"href": "../././~/Foobar.html",
Expand Down Expand Up @@ -679,12 +661,6 @@
"is_symbol": false,
"is_first_symbol": false
},
{
"name": "default",
"href": "../",
"is_symbol": false,
"is_first_symbol": false
},
{
"name": "Hello",
"href": "../././~/Hello.html",
Expand Down Expand Up @@ -850,12 +826,6 @@
"is_symbol": false,
"is_first_symbol": false
},
{
"name": "default",
"href": "../",
"is_symbol": false,
"is_first_symbol": false
},
{
"name": "Foo",
"href": "../././~/Foo.html",
Expand Down Expand Up @@ -1027,12 +997,6 @@
"is_symbol": false,
"is_first_symbol": false
},
{
"name": "default",
"href": "../",
"is_symbol": false,
"is_first_symbol": false
},
{
"name": "Foo",
"href": "../././~/Foo.html",
Expand Down Expand Up @@ -1210,12 +1174,6 @@
"is_symbol": false,
"is_first_symbol": false
},
{
"name": "default",
"href": "../",
"is_symbol": false,
"is_first_symbol": false
},
{
"name": "Foo",
"href": "../././~/Foo.html",
Expand Down Expand Up @@ -1393,12 +1351,6 @@
"is_symbol": false,
"is_first_symbol": false
},
{
"name": "default",
"href": "../",
"is_symbol": false,
"is_first_symbol": false
},
{
"name": "Hello",
"href": "../././~/Hello.html",
Expand Down Expand Up @@ -1564,6 +1516,12 @@
"is_symbol": false,
"is_first_symbol": false
},
{
"name": "foo",
"href": "../.././foo/~/index.html",
"is_symbol": false,
"is_first_symbol": false
},
{
"name": "x",
"href": "../.././foo/~/x.html",
Expand Down
Loading
Loading