@prospective.co/procss 0.1.9 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prospective.co/procss",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "description": "A simple CSS parsing and transformation framework.",
5
5
  "repository": {
6
6
  "type": "git",
package/src/lib.rs CHANGED
@@ -86,7 +86,11 @@ mod parser;
86
86
  mod render;
87
87
  mod transform;
88
88
  pub mod transformers;
89
- mod utils;
89
+ #[cfg(feature = "iotest")]
90
+ pub mod utils;
91
+
92
+ #[cfg(not(feature = "iotest"))]
93
+ pub mod utils;
90
94
 
91
95
  use self::ast::Tree;
92
96
  pub use self::builder::BuildCss;
@@ -28,9 +28,14 @@ fn parse_url(input: &str) -> nom::IResult<&str, &str> {
28
28
  }
29
29
 
30
30
  fn into_data_uri<'a>(path: &Path) -> Cow<'a, str> {
31
- let contents = fs::read_to_string(path).expect("Error reading file");
31
+ let contents = fs::read(path).expect("Error reading file");
32
32
  let encoded = base64::encode(contents);
33
- format!("url(data:image/svg+xml;base64,{})", encoded).into()
33
+ let fff = path.extension().unwrap_or_default().to_string_lossy();
34
+ let fmt = match fff.as_ref() {
35
+ "png" => "png",
36
+ _ => "svg+xml",
37
+ };
38
+ format!("url(\"data:image/{};base64,{}\")", fmt, encoded).into()
34
39
  }
35
40
 
36
41
  fn inline_url_impl<'a>(newpath: &str, flat: &mut Css<'a>) {
@@ -40,7 +45,9 @@ fn inline_url_impl<'a>(newpath: &str, flat: &mut Css<'a>) {
40
45
  .and_then(|x| x.0.is_empty().then_some(Path::new(newpath).join(x.1)));
41
46
 
42
47
  if let Some(path) = &path {
43
- rule.value = into_data_uri(path);
48
+ if path.starts_with(".") || path.starts_with("/") {
49
+ rule.value = into_data_uri(path);
50
+ }
44
51
  }
45
52
  })
46
53
  }
package/src/utils.rs CHANGED
@@ -72,6 +72,8 @@ mod mock {
72
72
  // where
73
73
  // P: AsRef<std::path::Path> + 'static;
74
74
 
75
+ fn read(path: &std::path::Path) -> std::io::Result<Vec<u8>>;
76
+
75
77
  fn create_dir_all<P>(path: P) -> std::io::Result<()>
76
78
  where
77
79
  P: AsRef<std::path::Path> + 'static;
Binary file
Binary file