Skip to content

Commit

Permalink
Enum display improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
jerbly committed Mar 31, 2024
1 parent 3a933cc commit fa34324
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 40 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# 0.1.9

- Enums are now displayed in two ways:
- If any brief is defined, the enum is displayed as a list of variants with their brief.
- Otherwise, the compact form just showing the values is displayed.
- Examples for enums are now hidden since they're just repeats of the enum.
- Improvements to the display for clarity:
- All branches are now shown before all leaves rather than mixed together.
- Horizontal rules to separate attribute definitions.
- Rework of Type with Examples on the same line.

# 0.1.8

- Pulling in improvements from [honeycomb-client](https://github.com/jerbly/honeycomb-client) 0.2.1
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "honey-explore"
version = "0.1.8"
version = "0.1.9"
edition = "2021"
authors = ["Jeremy Blythe <[email protected]>"]
repository = "https://github.com/jerbly/honey-explore"
Expand Down
4 changes: 4 additions & 0 deletions src/semconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ impl Attribute {
| Some(Type::Simple(PrimitiveType::TemplateOfArrayOfBoolean))
)
}

pub fn is_complex_type(&self) -> bool {
matches!(&self.r#type, Some(Type::Complex(_)))
}
}

#[derive(Debug, Deserialize)]
Expand Down
79 changes: 46 additions & 33 deletions templates/node.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,26 @@ <h3>
<ul>
{% for node in nodes %}
{% let attribute = level.clone() + "." + node.name.as_str() %}
<li>

{% match node.value %}
{% when Some with (_) %}
{% when None %}
<li>
{% if level == "root" %}
<a href="#" hx-get="/node/{{ node.name }}" hx-target="#list" hx-swap="outerHTML" hx-push-url="true">{{ node.name }}</a>
{% else %}
{{ level }}.<a href="#" hx-get="/node/{{ attribute }}" hx-target="#list" hx-swap="outerHTML" hx-push-url="true">{{ node.name }}</a>
{% endif %}
</li>
{% endmatch %}
{% endfor %}

{% for node in nodes %}
{% let attribute = level.clone() + "." + node.name.as_str() %}
{% match node.value %}
{% when Some with (val) %}
<hr/>
<li>
{% if level == "root" %}
{% match val.deprecated %}
{% when Some with (deprecated) %}
Expand All @@ -39,15 +56,9 @@ <h3>
{% when None %}
{% endmatch %}

{% match val.type %}
{% when Some with (_type) %}
{% include "type.html" %}
{% when None %}
{% endmatch %}

{% match val.deprecated %}
{% when Some with (deprecated) %}
<small><i>{{ deprecated|markdown }}</i></small>
<i>{{ deprecated|markdown }}</i>
{% when None %}
{% endmatch %}

Expand All @@ -57,23 +68,31 @@ <h3>
{% when None %}
{% endmatch %}

{% match val.examples %}
{% when Some with (examples) %}
e.g.
{% match examples %}
{% when Examples::SimpleType with (ex) %}
<code>{{ ex }}</code>
{% when Examples::ArrayType with (exs) %}
{% for ex in exs %}
<code>{{ ex }}</code>
{% if !loop.last %}
,
{% endif %}
{% endfor %}
{% endmatch %}
{% match val.type %}
{% when Some with (_type) %}
{% include "type.html" %}
{% when None %}
{% endmatch %}

{% if !val.is_complex_type() %}
{% match val.examples %}
{% when Some with (examples) %}
<small>e.g.</small>
{% match examples %}
{% when Examples::SimpleType with (ex) %}
<code>{{ ex }}</code>
{% when Examples::ArrayType with (exs) %}
{% for ex in exs %}
<code>{{ ex }}</code>
{% if !loop.last %}
,
{% endif %}
{% endfor %}
{% endmatch %}
{% when None %}
{% endmatch %}
{% endif %}

{% match val.note %}
{% when Some with (note) %}
<blockquote>{{ note|markdown }}</blockquote>
Expand All @@ -83,7 +102,7 @@ <h3>
{% if val.is_template_type() %}
{% match val.template_suffixes %}
{% when Some with (suffixes) %}
<p><small><b>keys</b>:<br/>
<p><b>keys</b>:<small><br/>
{% for (suffix,datasets) in suffixes.iter() %}
<mark>{{ suffix }}</mark>:
{% if datasets.len() < 10 %}
Expand All @@ -100,24 +119,18 @@ <h3>
{% match val.used_by %}
{% when Some with (datasets) %}
{% if datasets.len() < 10 %}
<p><small><b>used by</b>:
<p><b>used by</b>:<small>
{% include "usedby.html" %}
</small></p>
{% else %}
<p><small><b>used by</b>: <a href="#" hx-get="/usedby/{{ attribute }}" hx-swap="outerHTML">10+ datasets</a></small></p>
<p><b>used by</b>:<small> <a href="#" hx-get="/usedby/{{ attribute }}" hx-swap="outerHTML">10+ datasets</a></small></p>
{% endif %}
{% when None %}
{% endmatch %}
{% endif %}

</li>
{% when None %}
{% if level == "root" %}
<a href="#" hx-get="/node/{{ node.name }}" hx-target="#list" hx-swap="outerHTML" hx-push-url="true">{{ node.name }}</a>
{% else %}
{{ level }}.<a href="#" hx-get="/node/{{ attribute }}" hx-target="#list" hx-swap="outerHTML" hx-push-url="true">{{ node.name }}</a>
{% endif %}
{% endmatch %}
</li>
{% endmatch %}
{% endfor %}
</ul>
</div>
8 changes: 3 additions & 5 deletions templates/type.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{% match _type %}
{% when semconv::Type::Simple with (_) %}
<small><i>{{ _type }}</i></small>
<b>{{ _type }}</b>
{% when semconv::Type::Complex with (enum) %}
<small><i>
{% if enum.allow_custom_values %}
open enum:
<b>open enum</b>:
{% else %}
enum:
<b>enum</b>:
{% endif %}
{% if enum.has_briefs() %}
<ul>
Expand All @@ -28,7 +27,6 @@
{% endif %}
{% endfor %}
{% endif %}
</i></small>
{% endmatch %}


Expand Down

0 comments on commit fa34324

Please sign in to comment.