1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
#[cfg(feature = "warp")]
use warp::{
    Filter, Reply, Rejection, reply::Response, hyper::Body, http::header::{CONTENT_TYPE, CACHE_CONTROL, HeaderValue},
};

#[cfg(feature = "warp")]
pub fn route() -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
    assets().or(min_assets())
}

pub static CSS: &str = include_str!("../css/stylus.css");
pub static MAP: &str = include_str!("../css/stylus.css.map");

#[cfg(feature = "warp")]
pub fn assets() -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
    let css_path = warp::path("stylus.css").map(css);

    let map_path = warp::path("stylus.css.map").map(map);

    warp::path("assets").and(css_path.or(map_path))
}

#[cfg(feature = "warp")]
pub fn css() -> impl warp::Reply {
    Css { body: CSS }
}

#[cfg(feature = "warp")]
pub fn map() -> impl warp::Reply {
    Map { body: MAP }
}

pub static MIN_CSS: &str = include_str!("../css/stylus.min.css");
pub static MIN_MAP: &str = include_str!("../css/stylus.min.css.map");

#[cfg(feature = "warp")]
pub fn min_assets() -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
    let css_path = warp::path("stylus.min.css").map(min_css);

    let map_path = warp::path("stylus.min.css.map").map(min_map);

    warp::path("assets").and(css_path.or(map_path))
}

#[cfg(feature = "warp")]
pub fn min_css() -> impl warp::Reply {
    Css { body: MIN_CSS }
}

#[cfg(feature = "warp")]
pub fn min_map() -> impl warp::Reply {
    Map { body: MIN_MAP }
}

#[cfg(feature = "warp")]
struct Css<T> {
    body: T,
}

#[cfg(feature = "warp")]
impl<T> Reply for Css<T>
where
    Body: From<T>,
    T: Send,
{
    #[inline]
    fn into_response(self) -> Response {
        let mut res = Response::new(Body::from(self.body));

        res.headers_mut().insert(
            CACHE_CONTROL,
            HeaderValue::from_static("public, max-age=37260"),
        );

        res.headers_mut().insert(
            CONTENT_TYPE,
            HeaderValue::from_static("text/css; charset=utf-8"),
        );

        res
    }
}

#[cfg(feature = "warp")]
struct Map<T> {
    body: T,
}

#[cfg(feature = "warp")]
impl<T> Reply for Map<T>
where
    Body: From<T>,
    T: Send,
{
    #[inline]
    fn into_response(self) -> Response {
        let mut res = Response::new(Body::from(self.body));

        res.headers_mut().insert(
            CACHE_CONTROL,
            HeaderValue::from_static("public, max-age=37260"),
        );

        res.headers_mut().insert(
            CONTENT_TYPE,
            HeaderValue::from_static("application/json; charset=utf-8"),
        );

        res
    }
}