Skip to content

Commit

Permalink
Start checking namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
ja-he committed Jan 18, 2024
1 parent e01c1a8 commit 5d56311
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 20 deletions.
19 changes: 13 additions & 6 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,18 @@
text-decoration: underline #770000 0.2em;
background-color: #ffbbbb;
}
.explanation-icon.verified { color: #007700; }
.explanation-icon.ok { color: #002266; }
.explanation-icon.valid { color: #777700; }
.explanation-icon.invalid { color: #770000; }
.explanation-box-wrapper {
align-self: start;
justify-self: center;
display: flex;
flex-flow: column;
align-items: center;
justify-items: center;
gap: 0.5em;
}
.explanation-box {
padding: 1em;
border-radius: 0.5em;
align-self: start;
justify-self: center;
width: 20em;
display: grid;
column-gap: 0.5em;
Expand All @@ -215,6 +218,10 @@
grid-template-areas: "icon headline"
"icon explanation"
}
.explanation-icon.verified { color: #007700; }
.explanation-icon.ok { color: #002266; }
.explanation-icon.valid { color: #777700; }
.explanation-icon.invalid { color: #770000; }
.explanation-box.verified { background-color: #bbffbb; }
.explanation-box.ok { background-color: #aaddff; }
.explanation-box.valid { background-color: #ffffbb; }
Expand Down
37 changes: 26 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,10 @@ fn MainContent() -> impl IntoView {
}
});

let get_explanation_box_class =
let get_type_explanation_box_class =
move || format!("explanation-box {result}", result = eval_type_result());
let get_namespace_explanation_box_class =
move || format!("explanation-box {result}", result = eval_namespace_result());

view! {
<div id="input-form">
Expand Down Expand Up @@ -223,16 +225,29 @@ fn MainContent() -> impl IntoView {
subpath={subpath}
/>

<div class={get_explanation_box_class}>
{move || match eval_type_result().as_str() {
"verified" => view!{<phosphor_leptos::Checks class="explanation-icon verified" weight=phosphor_leptos::IconWeight::Bold />},
"ok" => view!{<phosphor_leptos::Check class="explanation-icon ok" weight=phosphor_leptos::IconWeight::Bold />} ,
"valid" => view!{<phosphor_leptos::Question class="explanation-icon valid" weight=phosphor_leptos::IconWeight::Bold />} ,
"invalid" => view!{<phosphor_leptos::Warning class="explanation-icon invalid" weight=phosphor_leptos::IconWeight::Bold />},
_ => view!{<phosphor_leptos::Warning class="explanation-icon error" weight=phosphor_leptos::IconWeight::Duotone />},
}}
<span class="headline">{eval_type_result}</span>
<span class="explanation">{eval_type_result_explanation}</span>
<div class="explanation-box-wrapper">
<div class={get_type_explanation_box_class}>
{move || match eval_type_result().as_str() {
"verified" => view!{<phosphor_leptos::Checks class="explanation-icon verified" weight=phosphor_leptos::IconWeight::Bold />},
"ok" => view!{<phosphor_leptos::Check class="explanation-icon ok" weight=phosphor_leptos::IconWeight::Bold />} ,
"valid" => view!{<phosphor_leptos::Question class="explanation-icon valid" weight=phosphor_leptos::IconWeight::Bold />} ,
"invalid" => view!{<phosphor_leptos::Warning class="explanation-icon invalid" weight=phosphor_leptos::IconWeight::Bold />},
_ => view!{<phosphor_leptos::Warning class="explanation-icon error" weight=phosphor_leptos::IconWeight::Duotone />},
}}
<span class="headline">{eval_type_result}</span>
<span class="explanation">{eval_type_result_explanation}</span>
</div>
<div class={get_namespace_explanation_box_class}>
{move || match eval_namespace_result().as_str() {
"verified" => view!{<phosphor_leptos::Checks class="explanation-icon verified" weight=phosphor_leptos::IconWeight::Bold />},
"ok" => view!{<phosphor_leptos::Check class="explanation-icon ok" weight=phosphor_leptos::IconWeight::Bold />} ,
"valid" => view!{<phosphor_leptos::Question class="explanation-icon valid" weight=phosphor_leptos::IconWeight::Bold />} ,
"invalid" => view!{<phosphor_leptos::Warning class="explanation-icon invalid" weight=phosphor_leptos::IconWeight::Bold />},
_ => view!{<phosphor_leptos::Warning class="explanation-icon error" weight=phosphor_leptos::IconWeight::Duotone />},
}}
<span class="headline">{eval_namespace_result}</span>
<span class="explanation">{eval_namespace_result_explanation}</span>
</div>
</div>
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/purl_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,9 @@ pub trait PurlComponent {

impl PurlComponent for PurlNamespace {
fn new_naive(s: &str) -> Self {
if s.is_empty() {
return vec![];
}
s.split('/').map(|s| s.to_string()).collect()
}

Expand Down
14 changes: 11 additions & 3 deletions src/purl_eval.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::purl_data::{PurlType, PurlTypeStatus};
use crate::purl_data::{self, PurlComponent, PurlType, PurlTypeStatus};

lazy_static! {
pub static ref TYPE_REGEX: regex::Regex =
Expand Down Expand Up @@ -51,6 +51,14 @@ pub fn eval_purl_type(purl_type: PurlType) -> EvalResult {
}
}

pub fn eval_purl_namespace(purl_namespace: Vec<String>) -> EvalResult {
EvalResult::Verified("fake".to_string())
pub fn eval_purl_namespace(purl_namespace: purl_data::PurlNamespace) -> EvalResult {
// TODO: regex check

if purl_namespace.len() != purl_namespace.as_canonical().len() {
return EvalResult::AtLeastValid(
"had to remove leading or trailing empty segments from namespace".to_string(),
);
}

EvalResult::ProbablyOk("I see no issue...".to_string())
}

0 comments on commit 5d56311

Please sign in to comment.