Skip to content
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

Only new selectors #195

Merged
merged 10 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ project adheres to

## Unreleased

(Nothing yet)
### Breaking changes:

* Replaced the css `Selector` implementation.
The new "logical" selector types that was used in selector
function in rsass 0.28 is now the only css selector implementation.
Most of the api to those types are private.
Some will probably be made public after some stabilization period.

## Release 0.28.10

Expand Down
10 changes: 6 additions & 4 deletions rsass/src/css/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ pub use self::comment::Comment;
pub use self::item::{Import, Item};
pub use self::mediarule::{MediaArgs, MediaRule};
pub use self::rule::{BodyItem, CustomProperty, Property, Rule};
pub use self::selectors::{BadSelector, Selector, SelectorPart, Selectors};
pub use self::selectors::{BadSelector, Selector, SelectorSet};
pub use self::string::CssString;
pub use self::value::{InvalidCss, Value, ValueMap, ValueToMapError};

pub(crate) use self::selectors::{
CssSelectorSet, LogicalSelector, SelectorCtx,
};
pub(crate) use self::selectors::{CssSelectorSet, SelectorCtx};
pub(crate) use self::util::{is_calc_name, is_function_name, is_not, IsNot};

pub(crate) mod parser {
pub(crate) use super::selectors::parser::selector_set;
}
40 changes: 23 additions & 17 deletions rsass/src/css/rule.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
use super::{AtRule, Comment, CssString, Import, Selectors, Value};
use super::{
selectors::Opt, AtRule, Comment, CssString, Import, SelectorSet, Value,
};
use crate::output::CssBuf;
use std::io::{self, Write};
use std::io;

/// A css rule.
///
/// A rule binds [`Selectors`] to a body of [`BodyItem`]s (mainly
/// A rule binds a [`SelectorSet`] to a body of [`BodyItem`]s (mainly
/// properties with [`Value`]s).
#[derive(Clone, Debug)]
pub struct Rule {
pub(crate) selectors: Selectors,
pub(crate) selectors: SelectorSet,
pub(crate) body: Vec<BodyItem>,
}

impl Rule {
/// Create a new Rule.
pub fn new(selectors: Selectors) -> Self {
pub fn new(selectors: SelectorSet) -> Self {
Self {
selectors,
body: Vec::new(),
Expand All @@ -28,19 +30,23 @@ impl Rule {
/// Write this rule to a css output buffer.
pub(crate) fn write(&self, buf: &mut CssBuf) -> io::Result<()> {
if !self.body.is_empty() {
if let Some(selectors) = self.selectors.no_placeholder() {
buf.do_indent_no_nl();
if buf.format().is_compressed() {
write!(buf, "{selectors:#}")?;
} else {
write!(buf, "{selectors}")?;
}
buf.start_block();
for item in &self.body {
item.write(buf)?;
}
buf.end_block();
let s = self.selectors.no_placeholder();
if matches!(s, Opt::None) {
return Ok(());
}
buf.do_indent_no_nl();
let p = buf.len();
if let Opt::Some(s) = s {
s.write_to(buf);
}
if buf.len() == p {
buf.add_str("*");
}
buf.start_block();
for item in &self.body {
item.write(buf)?;
}
buf.end_block();
}
Ok(())
}
Expand Down
Loading
Loading