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

Prepare for rsass 0.26. #116

Merged
merged 2 commits into from Sep 18, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/ci.yml
Expand Up @@ -12,9 +12,8 @@ jobs:
matrix:
rust:
- stable
- 1.52.1
- 1.48.0
- 1.46.0
- 1.60.0
- 1.56.1
- beta
- nightly
steps:
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -29,7 +29,7 @@ itertools = "0.10.0"
md5 = "0.7"
nom = "7.1.0"

rsass = { version = "0.25.0", optional = true }
rsass = { version = "0.26.0", optional = true }
mime = { version = "0.3", optional = true }

[badges]
Expand Down
12 changes: 6 additions & 6 deletions src/lib.rs
Expand Up @@ -455,20 +455,20 @@ impl Error for RucteError {
}

impl Display for RucteError {
fn fmt(&self, out: &mut fmt::Formatter) -> fmt::Result {
write!(out, "Error: {:?}", self)
}
}
impl Debug for RucteError {
fn fmt(&self, out: &mut fmt::Formatter) -> fmt::Result {
match self {
RucteError::Io(err) => Display::fmt(err, out),
RucteError::Env(var, err) => write!(out, "{:?}: {}", var, err),
#[cfg(feature = "sass")]
RucteError::Sass(err) => Display::fmt(err, out),
RucteError::Sass(err) => Debug::fmt(err, out),
}
}
}
impl Debug for RucteError {
fn fmt(&self, out: &mut fmt::Formatter) -> fmt::Result {
Display::fmt(self, out)
}
}

impl From<io::Error> for RucteError {
fn from(e: io::Error) -> RucteError {
Expand Down
58 changes: 23 additions & 35 deletions src/staticfiles.rs
Expand Up @@ -467,60 +467,48 @@ impl StaticFile {
where
P: AsRef<Path>,
{
let src = self.path_for(src);
use rsass::css::CssString;
use rsass::input::CargoContext;
use rsass::output::{Format, Style};
use rsass::sass::FormalArgs;
use rsass::sass::{CallError, FormalArgs};
use rsass::value::Quotes;
use rsass::*;
use std::sync::Arc;
let format = Format {
style: Style::Compressed,
precision: 4,
};
let scope = ScopeRef::new_global(format);

// TODO Find any referenced files!
println!("cargo:rerun-if-changed={}", src.display());

let existing_statics = Arc::new(self.get_names().clone());
scope.define_function(
let src = self.path_for(src);
let (context, scss) =
CargoContext::for_path(&src).map_err(rsass::Error::from)?;
let mut context = context.with_format(format);
let existing_statics = self.get_names().clone();
context.get_scope().define_function(
"static_name".into(),
sass::Function::builtin(
"",
&"static_name".into(),
FormalArgs::new(vec![("name".into(), None)]),
Arc::new(move |s| match s.get(&"name".into())? {
css::Value::Literal(name) => {
let name =
name.value().replace('-', "_").replace('.', "_");
for (n, v) in existing_statics.as_ref() {
if name == *n {
return Ok(CssString::new(
v.into(),
Quotes::Double,
)
.into());
}
}
Err(Error::S(format!(
"Static file {} not found",
name,
)))
}
name => Err(Error::BadArgument(
"name".into(),
format!(
"{} is not a string",
name.format(Format::introspect())
),
)),
Arc::new(move |s| {
let name: String = s.get("name".into())?;
let rname = name.replace('-', "_").replace('.', "_");
existing_statics
.iter()
.find(|(n, _v)| *n == &rname)
.map(|(_n, v)| {
CssString::new(v.into(), Quotes::Double).into()
})
.ok_or_else(|| {
CallError::msg(format!(
"Static file {name:?} not found",
))
})
}),
),
);

let (file_context, scss) = FsFileContext::for_path(&src)?;
let css = format.write_root(scss.parse()?, scope, &file_context)?;
let css = context.transform(scss)?;
self.add_file_data(&src.with_extension("css"), &css)
}

Expand Down