-
Notifications
You must be signed in to change notification settings - Fork 22
feat(css-syntax): migrate to @webref/css 7 #317
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
Conversation
|
Waiting for a decision from content for the copy, style and placement for a formal syntax disclaimer. |
|
Content decision is done, a PR adding the necessary translated text fragments is under review. |
crates/css-syntax-types/src/lib.rs
Outdated
|
|
||
| #[derive(Clone, Debug, Deserialize, Serialize)] | ||
| #[serde(deny_unknown_fields)] | ||
| pub struct AtRule { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that all these types share some fields, could these be extracted to a common base type, to ensure consistency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since there is no classic inheritance in rust, and we are bound to the JSON-structure of the webref data, we cannot use a straight composition pattern (tying together shared attributes in a common sub-struct). Other ways to do inheritance (traits, enums) are also not helping with clarity here. I think the current structs are not overwhelmingly large and changes are comparatively few.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you considered struct flattening?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but I decided against it. For consistency we would have to change a lot of structs that are outside the scope of this change. I would recommend to do that in a separate PR if really needed.
caugner
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Second pass.
crates/css-syntax-types/src/lib.rs
Outdated
|
|
||
| #[derive(Clone, Debug, Deserialize, Serialize)] | ||
| #[serde(deny_unknown_fields)] | ||
| pub struct AtRule { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you considered struct flattening?
crates/css-syntax-types/src/css.rs
Outdated
| } | ||
| } | ||
| #[derive(Clone, Debug, Deserialize, Serialize)] | ||
| pub struct AtruleDescriptor { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Rename to AtRuleDescriptor for consistency.
| pub struct AtruleDescriptor { | |
| pub struct AtRuleDescriptor { |
| } | ||
| } | ||
| #[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] | ||
| pub enum Interfacetype { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| pub enum Interfacetype { | |
| pub enum InterfaceType { |
crates/rari-deps/src/webref_css.rs
Outdated
| Ok(url_to_title) | ||
| } | ||
|
|
||
| fn url_to_title_map(base_path: &Path) -> Result<BTreeMap<String, String>, DepsError> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Add a short comment with an example of what the resulting map contains. Also possibly rename to spec_url_to_title_map.
| fn url_to_title_map(base_path: &Path) -> Result<BTreeMap<String, String>, DepsError> { | |
| fn spec_url_to_title_map(base_path: &Path) -> Result<BTreeMap<String, String>, DepsError> { |
crates/rari-deps/src/webref_css.rs
Outdated
| let url_to_title = url_to_title_map(base_path)?; | ||
|
|
||
| // Process the CSS data with the URL-to-title map passed in. | ||
| if let Some(package_path) = get_package("@webref/css", &deps().webref_css, base_path)? { | ||
| let webref_css = transform(&package_path, &url_to_title)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Move url_to_title inside block.
| let url_to_title = url_to_title_map(base_path)?; | |
| // Process the CSS data with the URL-to-title map passed in. | |
| if let Some(package_path) = get_package("@webref/css", &deps().webref_css, base_path)? { | |
| let webref_css = transform(&package_path, &url_to_title)?; | |
| // Process the CSS data with the URL-to-title map passed in. | |
| if let Some(package_path) = get_package("@webref/css", &deps().webref_css, base_path)? { | |
| let url_to_title = url_to_title_map(base_path)?; | |
| let webref_css = transform(&package_path, &url_to_title)?; |
crates/css-syntax-types/src/utils.rs
Outdated
| // // In order to use it with in a BtreeSet<SpecLink>, implement `PartialOrd` and `Ord` | ||
| // impl PartialOrd for SpecLink { | ||
| // fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { | ||
| // Some(self.cmp(other)) | ||
| // } | ||
| // } | ||
|
|
||
| impl Ord for SpecLink { | ||
| fn cmp(&self, other: &Self) -> std::cmp::Ordering { | ||
| // First compare by title, then by URL if titles are equal | ||
| self.title | ||
| .cmp(&other.title) | ||
| .then_with(|| self.url.cmp(&other.url)) | ||
| } | ||
| } | ||
| // impl Ord for SpecLink { | ||
| // fn cmp(&self, other: &Self) -> std::cmp::Ordering { | ||
| // // First compare by title, then by URL if titles are equal | ||
| // self.title | ||
| // .cmp(&other.title) | ||
| // .then_with(|| self.url.cmp(&other.url)) | ||
| // } | ||
| // } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Can't we just remove?
| // // In order to use it with in a BtreeSet<SpecLink>, implement `PartialOrd` and `Ord` | |
| // impl PartialOrd for SpecLink { | |
| // fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { | |
| // Some(self.cmp(other)) | |
| // } | |
| // } | |
| impl Ord for SpecLink { | |
| fn cmp(&self, other: &Self) -> std::cmp::Ordering { | |
| // First compare by title, then by URL if titles are equal | |
| self.title | |
| .cmp(&other.title) | |
| .then_with(|| self.url.cmp(&other.url)) | |
| } | |
| } | |
| // impl Ord for SpecLink { | |
| // fn cmp(&self, other: &Self) -> std::cmp::Ordering { | |
| // // First compare by title, then by URL if titles are equal | |
| // self.title | |
| // .cmp(&other.title) | |
| // .then_with(|| self.url.cmp(&other.url)) | |
| // } | |
| // } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah sorry, missed a file save there.
Description
This implements the usage of data from webref-css version 7.x. That version only provides a consolidated version of the data, so we can get rid of the brittle logic around selecting a CSS level we show. The editorial responsibility therefore lies with the maintainers of webref-css.
This is the basis of our CSS formal syntax rendering.
Motivation
Upstream major version change.
Additional details
Webref-css changelog
Diff of the document changes induced by this PR: 255 changes
<color>example formal syntaxBefore

After

There are numerous additions to this in the v7 data, namely the correct introduction of
light-dark()(which we document on the page) anddevice-cmyk()(which is not implemented by any browser by time of writing).Since the specification titles are no more included with the webref data, titles are pulled in from the browser-specs data package.
Related issues and pull requests
Fixes #304