diff options
Diffstat (limited to '')
-rw-r--r-- | askama/Cargo.toml | 6 | ||||
-rw-r--r-- | askama/src/lib.rs | 28 | ||||
-rw-r--r-- | askama_shared/Cargo.toml | 2 | ||||
-rw-r--r-- | askama_shared/src/input.rs | 27 | ||||
-rw-r--r-- | askama_shared/src/lib.rs | 1 |
5 files changed, 37 insertions, 27 deletions
diff --git a/askama/Cargo.toml b/askama/Cargo.toml index b3876e2..076f7e9 100644 --- a/askama/Cargo.toml +++ b/askama/Cargo.toml @@ -31,12 +31,14 @@ with-rocket = ["askama_derive/rocket"] with-tide = ["askama_derive/tide"] with-warp = ["askama_derive/warp"] +# deprecated +mime = [] +mime_guess = [] + [dependencies] askama_derive = { version = "0.11.0", path = "../askama_derive" } askama_escape = { version = "0.10", path = "../askama_escape" } askama_shared = { version = "0.12.0", path = "../askama_shared", default-features = false } -mime = { version = "0.3", optional = true } -mime_guess = { version = "2", optional = true } [package.metadata.docs.rs] features = ["config", "humansize", "num-traits", "serde-json", "serde-yaml"] diff --git a/askama/src/lib.rs b/askama/src/lib.rs index 3c7f072..f1aa91c 100644 --- a/askama/src/lib.rs +++ b/askama/src/lib.rs @@ -128,33 +128,11 @@ pub use crate::shared::helpers; pub use crate::shared::{read_config_file, Error, MarkupDisplay, Result}; pub use askama_derive::*; +#[deprecated(since = "0.11.1", note = "The only function in this mod is deprecated")] pub mod mime { #[cfg(all(feature = "mime_guess", feature = "mime"))] - pub fn extension_to_mime_type(ext: &str) -> mime_guess::Mime { - let basic_type = mime_guess::from_ext(ext).first_or_octet_stream(); - for (simple, utf_8) in &TEXT_TYPES { - if &basic_type == simple { - return utf_8.clone(); - } - } - basic_type - } - - #[cfg(all(feature = "mime_guess", feature = "mime"))] - const TEXT_TYPES: [(mime_guess::Mime, mime_guess::Mime); 6] = [ - (mime::TEXT_PLAIN, mime::TEXT_PLAIN_UTF_8), - (mime::TEXT_HTML, mime::TEXT_HTML_UTF_8), - (mime::TEXT_CSS, mime::TEXT_CSS_UTF_8), - (mime::TEXT_CSV, mime::TEXT_CSV_UTF_8), - ( - mime::TEXT_TAB_SEPARATED_VALUES, - mime::TEXT_TAB_SEPARATED_VALUES_UTF_8, - ), - ( - mime::APPLICATION_JAVASCRIPT, - mime::APPLICATION_JAVASCRIPT_UTF_8, - ), - ]; + #[deprecated(since = "0.11.1", note = "Use Template::MIME_TYPE instead")] + pub use crate::shared::extension_to_mime_type; } /// Old build script helper to rebuild crates if contained templates have changed diff --git a/askama_shared/Cargo.toml b/askama_shared/Cargo.toml index 7f476b1..be00ae4 100644 --- a/askama_shared/Cargo.toml +++ b/askama_shared/Cargo.toml @@ -18,6 +18,8 @@ yaml = ["serde", "serde_yaml"] [dependencies] askama_escape = { version = "0.10.2", path = "../askama_escape" } humansize = { version = "1.1.0", optional = true } +mime = "0.3" +mime_guess = "2" nom = "7" num-traits = { version = "0.2.6", optional = true } proc-macro2 = "1" diff --git a/askama_shared/src/input.rs b/askama_shared/src/input.rs index 03c62d0..7d28a7e 100644 --- a/askama_shared/src/input.rs +++ b/askama_shared/src/input.rs @@ -3,6 +3,7 @@ use crate::{CompileError, Config, Syntax}; use std::path::{Path, PathBuf}; use std::str::FromStr; +use mime::Mime; use quote::ToTokens; pub struct TemplateInput<'a> { @@ -239,6 +240,32 @@ impl FromStr for Print { } } +#[doc(hidden)] +pub fn extension_to_mime_type(ext: &str) -> Mime { + let basic_type = mime_guess::from_ext(ext).first_or_octet_stream(); + for (simple, utf_8) in &TEXT_TYPES { + if &basic_type == simple { + return utf_8.clone(); + } + } + basic_type +} + +const TEXT_TYPES: [(Mime, Mime); 6] = [ + (mime::TEXT_PLAIN, mime::TEXT_PLAIN_UTF_8), + (mime::TEXT_HTML, mime::TEXT_HTML_UTF_8), + (mime::TEXT_CSS, mime::TEXT_CSS_UTF_8), + (mime::TEXT_CSV, mime::TEXT_CSV_UTF_8), + ( + mime::TEXT_TAB_SEPARATED_VALUES, + mime::TEXT_TAB_SEPARATED_VALUES_UTF_8, + ), + ( + mime::APPLICATION_JAVASCRIPT, + mime::APPLICATION_JAVASCRIPT_UTF_8, + ), +]; + #[cfg(test)] mod tests { use super::*; diff --git a/askama_shared/src/lib.rs b/askama_shared/src/lib.rs index f6b94dd..911367a 100644 --- a/askama_shared/src/lib.rs +++ b/askama_shared/src/lib.rs @@ -11,6 +11,7 @@ use std::{env, fmt, fs}; #[cfg(feature = "serde")] use serde::Deserialize; +pub use crate::input::extension_to_mime_type; pub use askama_escape::MarkupDisplay; mod error; |