Skip to content

Commit

Permalink
fill in some missing metadata for the 0.1.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
ealmloff committed Feb 21, 2024
1 parent a427947 commit 839f3e1
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 33 deletions.
6 changes: 6 additions & 0 deletions cli-support/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
name = "manganis-cli-support"
version = "0.1.0"
edition = "2021"
authors = ["Evan Almloff"]
description = "Ergonomic, Automatic, cross crate asset collection"
license = "MIT OR Apache-2.0"
repository = "https://github.com/DioxusLabs/collect-assets/"
homepage = "https://dioxuslabs.com"
keywords = ["assets"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
6 changes: 6 additions & 0 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
name = "manganis-common"
version = "0.1.0"
edition = "2021"
authors = ["Evan Almloff"]
description = "Ergonomic, Automatic, cross crate asset collection"
license = "MIT OR Apache-2.0"
repository = "https://github.com/DioxusLabs/collect-assets/"
homepage = "https://dioxuslabs.com"
keywords = ["assets"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
2 changes: 1 addition & 1 deletion common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![doc = include_str!("../../../README.md")]
#![deny(missing_docs)]
//! Common types and methods for the manganis asset system
mod asset;
pub mod cache;
Expand Down
11 changes: 7 additions & 4 deletions macro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "manganis-macro"
version = "0.1.0"
authors = ["Evan Almloff"]
edition = "2021"
authors = ["Evan Almloff"]
description = "Ergonomic, Automatic, cross crate asset collection"
license = "MIT OR Apache-2.0"
repository = "https://github.com/DioxusLabs/dioxus/"
repository = "https://github.com/DioxusLabs/collect-assets/"
homepage = "https://dioxuslabs.com"
keywords = ["assets"]

Expand All @@ -17,5 +17,8 @@ proc-macro2 = { version = "1.0" }
quote = "1.0"
syn = { version = "2.0", features = ["full", "extra-traits"] }
manganis-common = { path = "../common", version = "0.1.0" }
manganis-cli-support = { path = "../cli-support", version = "0.1.0" }
base64 = "0.21.5"
manganis-cli-support = { path = "../cli-support", version = "0.1.0", optional = true }
base64 = { version = "0.21.5", optional = true }

[features]
url-encoding = ["manganis-cli-support", "base64"]
3 changes: 3 additions & 0 deletions macro/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Manganis Macro

This crate contains the macro used to interact with the Manganis asset system.
71 changes: 44 additions & 27 deletions macro/src/image.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use base64::Engine;
use manganis_cli_support::process_file;
use manganis_common::{get_mime_from_ext, FileAsset, FileOptions, FileSource, ImageOptions};
use manganis_common::{ FileAsset, FileOptions, FileSource, ImageOptions};
use quote::{quote, ToTokens};
use syn::{parenthesized, parse::Parse, Token};

Expand Down Expand Up @@ -210,6 +208,12 @@ impl Parse for ImageAssetParser {
_ => unreachable!(),
};
let file_name = if this_file.url_encoded() {
#[cfg(not(feature = "url-encoding"))]
return Err(syn::Error::new(
proc_macro2::Span::call_site(),
"URL encoding is not enabled. Enable the url-encoding feature to use this feature",
));
#[cfg(feature = "url-encoding")]
url_encoded_asset(&this_file).map_err(|e| {
syn::Error::new(
proc_macro2::Span::call_site(),
Expand All @@ -221,29 +225,39 @@ impl Parse for ImageAssetParser {
};

let low_quality_preview = if low_quality_preview {
let current_image_size = match this_file.options() {
manganis_common::FileOptions::Image(options) => options.size(),
_ => None,
};
let low_quality_preview_size = current_image_size
.map(|(width, height)| {
let width = width / 10;
let height = height / 10;
(width, height)
})
.unwrap_or((32, 32));
let lqip = FileAsset::new(path).with_options(manganis_common::FileOptions::Image(
ImageOptions::new(
manganis_common::ImageType::Avif,
Some(low_quality_preview_size),
),
#[cfg(not(feature = "url-encoding"))]
return Err(syn::Error::new(
proc_macro2::Span::call_site(),
"Low quality previews require URL encoding. Enable the url-encoding feature to use this feature",
));
Some(url_encoded_asset(&lqip).map_err(|e| {
syn::Error::new(
proc_macro2::Span::call_site(),
format!("Failed to encode file: {}", e),
)
})?)

#[cfg(feature = "url-encoding")]
{
let current_image_size = match this_file.options() {
manganis_common::FileOptions::Image(options) => options.size(),
_ => None,
};
let low_quality_preview_size = current_image_size
.map(|(width, height)| {
let width = width / 10;
let height = height / 10;
(width, height)
})
.unwrap_or((32, 32));
let lqip = FileAsset::new(path).with_options(manganis_common::FileOptions::Image(
ImageOptions::new(
manganis_common::ImageType::Avif,
Some(low_quality_preview_size),
),
));

Some(url_encoded_asset(&lqip).map_err(|e| {
syn::Error::new(
proc_macro2::Span::call_site(),
format!("Failed to encode file: {}", e),
)
})?)
}
} else {
None
};
Expand All @@ -255,7 +269,10 @@ impl Parse for ImageAssetParser {
}
}

#[cfg(feature = "url-encoding")]
fn url_encoded_asset(file_asset: &FileAsset) -> Result<String, syn::Error> {
use base64::Engine;

let target_directory =
std::env::var("CARGO_TARGET_DIR").unwrap_or_else(|_| "target".to_string());
let output_folder = std::path::Path::new(&target_directory)
Expand All @@ -267,7 +284,7 @@ fn url_encoded_asset(file_asset: &FileAsset) -> Result<String, syn::Error> {
format!("Failed to create output folder: {}", e),
)
})?;
process_file(file_asset, &output_folder).map_err(|e| {
manganis_cli_support::process_file(file_asset, &output_folder).map_err(|e| {
syn::Error::new(
proc_macro2::Span::call_site(),
format!("Failed to process file: {}", e),
Expand All @@ -281,7 +298,7 @@ fn url_encoded_asset(file_asset: &FileAsset) -> Result<String, syn::Error> {
)
})?;
let data = base64::engine::general_purpose::STANDARD_NO_PAD.encode(data);
let mime = get_mime_from_ext(file_asset.options().extension());
let mime = manganis_common::get_mime_from_ext(file_asset.options().extension());
Ok(format!("data:{mime};base64,{data}"))
}

Expand Down
2 changes: 1 addition & 1 deletion macro/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![doc = include_str!("../../README.md")]
#![doc = include_str!("../README.md")]
#![deny(missing_docs)]

use file::FileAssetParser;
Expand Down

0 comments on commit 839f3e1

Please sign in to comment.