Skip to content

Commit

Permalink
better enum display
Browse files Browse the repository at this point in the history
  • Loading branch information
jerbly committed Mar 30, 2024
1 parent 49381f3 commit 3a933cc
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/semconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ impl Display for MemberValue {
#[derive(Debug, Deserialize, Clone)]
pub struct Member {
pub value: MemberValue,
pub brief: Option<String>,
}

#[derive(Debug, Deserialize, Clone)]
Expand All @@ -35,6 +36,12 @@ pub struct ComplexType {
pub members: Vec<Member>,
}

impl ComplexType {
pub fn has_briefs(&self) -> bool {
self.members.iter().any(|member| member.brief.is_some())
}
}

impl Display for ComplexType {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
if self.allow_custom_values {
Expand Down
4 changes: 2 additions & 2 deletions templates/node.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ <h3>
{% match val.deprecated %}
{% when Some with (deprecated) %}
<s><b>{{ node.name }}</b></s>
{% when None %}
{% when None %}
<mark><b>{{ node.name }}</b></mark>
{% endmatch %}
{% else %}
Expand All @@ -41,7 +41,7 @@ <h3>

{% match val.type %}
{% when Some with (_type) %}
<small><i>{{ _type }}</i></small>
{% include "type.html" %}
{% when None %}
{% endmatch %}

Expand Down
35 changes: 35 additions & 0 deletions templates/type.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{% match _type %}
{% when semconv::Type::Simple with (_) %}
<small><i>{{ _type }}</i></small>
{% when semconv::Type::Complex with (enum) %}
<small><i>
{% if enum.allow_custom_values %}
open enum:
{% else %}
enum:
{% endif %}
{% if enum.has_briefs() %}
<ul>
{% for member in enum.members %}
<li><code>{{ member.value }}</code>
{% match member.brief %}
{% when Some with (brief) %}
- {{ brief }}
{% when None %}
{% endmatch %}
</li>
{% endfor %}
</ul>
{% else %}
{% for member in enum.members %}
<code>{{ member.value }}</code>
{% if !loop.last %}
,
{% endif %}
{% endfor %}
{% endif %}
</i></small>
{% endmatch %}



0 comments on commit 3a933cc

Please sign in to comment.