Skip to content

Commit

Permalink
Highlight type identifier status
Browse files Browse the repository at this point in the history
visual PoC
  • Loading branch information
ja-he committed Jan 16, 2024
1 parent 64212d0 commit 979349c
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 89 deletions.
13 changes: 11 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,21 @@
max-width: 16em;
}

.proposed-type {
.option-proposed {
font-size: 1em;
}
.well-known-type {
.option-well-known {
font-size: 2em;
}

.identifier-well-known {
text-decoration: underline #007700 0.2em;
background-color: #bbffbb;
}
.identifier-proposed {
text-decoration: underline #777700 0.2em;
background-color: #ffffbb;
}
</style>

</head>
Expand Down
20 changes: 12 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ fn MainContent() -> impl IntoView {
}>
{
purl_data::PURL_TYPES.iter()
.map(|(type_option, choice_well_known)| view! {
<PurlTypeOption typestr is=type_option well_known=*choice_well_known/>
.map(|(type_option, choice_status)| view! {
<PurlTypeOption typestr is=type_option status=*choice_status/>
})
.collect_view()
}
Expand Down Expand Up @@ -112,14 +112,14 @@ fn MainContent() -> impl IntoView {
pub fn PurlTypeOption(
is: &'static str,
typestr: ReadSignal<String>,
well_known: bool,
status: purl_data::PurlTypeStatus,
) -> impl IntoView {
view! {
<option
class={ if well_known {
"well-known-type"
} else {
"proposed-type"
class={ match status {
purl_data::PurlTypeStatus::WellKnown => "option-well-known",
purl_data::PurlTypeStatus::Proposed => "option-proposed",
purl_data::PurlTypeStatus::Other => "option-other", // this case would not happen, normally
}}
value=is
selected=move || typestr() == is
Expand All @@ -143,7 +143,11 @@ fn Purl(
<div class="purl">
<span class="purl-scheme">"pkg"</span>
<span class="purl-sep">:</span>
<span class="purl-type">{typestr}</span>
<span class={ move || format!("{t} {status}", t="purl-type", status=match purl_data::get_purl_type_status(&typestr.get()) {
purl_data::PurlTypeStatus::WellKnown => "identifier-well-known",
purl_data::PurlTypeStatus::Proposed => "identifier-proposed",
purl_data::PurlTypeStatus::Other => "identifier-other",
})}>{typestr}</span>
<span class="purl-sep">/</span>
<span class="purl-namespace">{namespace}</span>
<span class="purl-sep">/</span>
Expand Down
172 changes: 93 additions & 79 deletions src/purl_data.rs
Original file line number Diff line number Diff line change
@@ -1,81 +1,95 @@
pub const PURL_TYPES: &[(&str, bool)] = &[
("alpm", true),
("android", false),
("apache", false),
("apk", true),
("atom", false),
("bitbucket", true),
("bitnami", true),
("bower", false),
("brew", false),
("buildroot", false),
("cargo", true),
("carthage", false),
("chef", false),
("chocolatey", false),
("clojars", false),
("cocoapods", true),
("composer", true),
("conan", true),
("conda", true),
("coreos", false),
("cpan", false),
("cran", true),
("crystal", false),
("ctan", false),
("deb", true),
("docker", true),
("drupal", false),
("dtype", false),
("dub", false),
("ebuild", false),
("eclipse", false),
("elm", false),
("gem", true),
("generic", true),
("gitea", false),
("github", true),
("gitlab", false),
("golang", true),
("gradle", false),
("guix", false),
("hackage", true),
("haxe", false),
("helm", false),
("hex", true),
("huggingface", true),
("julia", false),
("lua", false),
("maven", true),
("melpa", false),
("meteor", false),
("mlflow", true),
("nim", false),
("nix", false),
("npm", true),
("nuget", true),
("oci", true),
("opam", false),
("openwrt", false),
("osgi", false),
("p2", false),
("pear", false),
("pecl", false),
("perl6", false),
("platformio", false),
("pub", true),
("puppet", false),
("pypi", true),
("qpkg", true),
("rpm", true),
("sourceforge", false),
("sublime", false),
("swid", true),
("swift", true),
("terraform", false),
("vagrant", false),
("vim", false),
("wordpress", false),
("yocto", false),
pub const PURL_TYPES: &[(&str, PurlTypeStatus)] = &[
("alpm", PurlTypeStatus::WellKnown),
("android", PurlTypeStatus::Proposed),
("apache", PurlTypeStatus::Proposed),
("apk", PurlTypeStatus::WellKnown),
("atom", PurlTypeStatus::Proposed),
("bitbucket", PurlTypeStatus::WellKnown),
("bitnami", PurlTypeStatus::WellKnown),
("bower", PurlTypeStatus::Proposed),
("brew", PurlTypeStatus::Proposed),
("buildroot", PurlTypeStatus::Proposed),
("cargo", PurlTypeStatus::WellKnown),
("carthage", PurlTypeStatus::Proposed),
("chef", PurlTypeStatus::Proposed),
("chocolatey", PurlTypeStatus::Proposed),
("clojars", PurlTypeStatus::Proposed),
("cocoapods", PurlTypeStatus::WellKnown),
("composer", PurlTypeStatus::WellKnown),
("conan", PurlTypeStatus::WellKnown),
("conda", PurlTypeStatus::WellKnown),
("coreos", PurlTypeStatus::Proposed),
("cpan", PurlTypeStatus::Proposed),
("cran", PurlTypeStatus::WellKnown),
("crystal", PurlTypeStatus::Proposed),
("ctan", PurlTypeStatus::Proposed),
("deb", PurlTypeStatus::WellKnown),
("docker", PurlTypeStatus::WellKnown),
("drupal", PurlTypeStatus::Proposed),
("dtype", PurlTypeStatus::Proposed),
("dub", PurlTypeStatus::Proposed),
("ebuild", PurlTypeStatus::Proposed),
("eclipse", PurlTypeStatus::Proposed),
("elm", PurlTypeStatus::Proposed),
("gem", PurlTypeStatus::WellKnown),
("generic", PurlTypeStatus::WellKnown),
("gitea", PurlTypeStatus::Proposed),
("github", PurlTypeStatus::WellKnown),
("gitlab", PurlTypeStatus::Proposed),
("golang", PurlTypeStatus::WellKnown),
("gradle", PurlTypeStatus::Proposed),
("guix", PurlTypeStatus::Proposed),
("hackage", PurlTypeStatus::WellKnown),
("haxe", PurlTypeStatus::Proposed),
("helm", PurlTypeStatus::Proposed),
("hex", PurlTypeStatus::WellKnown),
("huggingface", PurlTypeStatus::WellKnown),
("julia", PurlTypeStatus::Proposed),
("lua", PurlTypeStatus::Proposed),
("maven", PurlTypeStatus::WellKnown),
("melpa", PurlTypeStatus::Proposed),
("meteor", PurlTypeStatus::Proposed),
("mlflow", PurlTypeStatus::WellKnown),
("nim", PurlTypeStatus::Proposed),
("nix", PurlTypeStatus::Proposed),
("npm", PurlTypeStatus::WellKnown),
("nuget", PurlTypeStatus::WellKnown),
("oci", PurlTypeStatus::WellKnown),
("opam", PurlTypeStatus::Proposed),
("openwrt", PurlTypeStatus::Proposed),
("osgi", PurlTypeStatus::Proposed),
("p2", PurlTypeStatus::Proposed),
("pear", PurlTypeStatus::Proposed),
("pecl", PurlTypeStatus::Proposed),
("perl6", PurlTypeStatus::Proposed),
("platformio", PurlTypeStatus::Proposed),
("pub", PurlTypeStatus::WellKnown),
("puppet", PurlTypeStatus::Proposed),
("pypi", PurlTypeStatus::WellKnown),
("qpkg", PurlTypeStatus::WellKnown),
("rpm", PurlTypeStatus::WellKnown),
("sourceforge", PurlTypeStatus::Proposed),
("sublime", PurlTypeStatus::Proposed),
("swid", PurlTypeStatus::WellKnown),
("swift", PurlTypeStatus::WellKnown),
("terraform", PurlTypeStatus::Proposed),
("vagrant", PurlTypeStatus::Proposed),
("vim", PurlTypeStatus::Proposed),
("wordpress", PurlTypeStatus::Proposed),
("yocto", PurlTypeStatus::Proposed),
];

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PurlTypeStatus {
WellKnown,
Proposed,
Other,
}

pub fn get_purl_type_status(typestr: &str) -> PurlTypeStatus {
if let Some(found) = PURL_TYPES.iter().find(|(t, _)| *t == typestr) {
found.1
} else {
PurlTypeStatus::Other
}
}

0 comments on commit 979349c

Please sign in to comment.