Skip to content

Commit 7220e9e

Browse files
authored
chore: fix build warnings (#322)
1 parent 01c238e commit 7220e9e

File tree

9 files changed

+34
-22
lines changed

9 files changed

+34
-22
lines changed

cot/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

cot/build.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ fn build_css() {
2525

2626
let css = grass::from_path(scss_path, &options).expect("failed to compile SCSS");
2727

28-
let css_path = PathBuf::from(css_file);
28+
let out_dir = std::env::var("OUT_DIR").expect("OUT_DIR should be set");
29+
let css_path = PathBuf::from(out_dir).join(css_file);
2930
let css_dir = css_path
3031
.parent()
3132
.expect("failed to get CSS parent directory");

cot/src/admin.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::marker::PhantomData;
88

99
use askama::Template;
1010
use async_trait::async_trait;
11+
use bytes::Bytes;
1112
use cot::request::extractors::StaticFiles;
1213
/// Implements the [`AdminModel`] trait for a struct.
1314
///
@@ -32,7 +33,7 @@ use crate::request::{Request, RequestExt};
3233
use crate::response::{IntoResponse, Response};
3334
use crate::router::{Router, Urls};
3435
use crate::static_files::StaticFile;
35-
use crate::{App, Error, Method, RequestHandler, reverse_redirect, static_files};
36+
use crate::{App, Error, Method, RequestHandler, reverse_redirect};
3637

3738
struct AdminAuthenticated<T, H: Send + Sync>(H, PhantomData<fn() -> T>);
3839

@@ -715,6 +716,12 @@ impl App for AdminApp {
715716
}
716717

717718
fn static_files(&self) -> Vec<StaticFile> {
718-
static_files!("admin/admin.css")
719+
vec![StaticFile::new(
720+
"admin/admin.css",
721+
Bytes::from_static(include_bytes!(concat!(
722+
env!("OUT_DIR"),
723+
"/static/admin/admin.css"
724+
))),
725+
)]
719726
}
720727
}

cot/src/auth.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,8 @@ pub struct Auth {
706706
}
707707

708708
impl Auth {
709-
#[cfg(feature = "db")] // only currently used in TestRequestBuilder if database is enabled
709+
// only currently used in TestRequestBuilder if database is enabled
710+
#[cfg(all(feature = "db", feature = "test"))]
710711
pub(crate) async fn new(
711712
session: Session,
712713
backend: Arc<dyn AuthBackend>,

cot/src/error_page.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ struct ErrorPageTemplate {
5656
project_config: String,
5757
}
5858

59+
fn error_css() -> &'static str {
60+
include_str!(concat!(env!("OUT_DIR"), "/templates/css/error.css"))
61+
}
62+
5963
#[derive(Debug, Default, Clone)]
6064
struct ErrorPageTemplateBuilder {
6165
kind: Kind,

cot/src/project.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,6 +1574,7 @@ impl ProjectContext<WithDatabase> {
15741574
}
15751575

15761576
impl ProjectContext<Initialized> {
1577+
#[cfg(feature = "test")]
15771578
pub(crate) fn initialized(
15781579
config: <Initialized as BootstrapPhase>::Config,
15791580
apps: <Initialized as BootstrapPhase>::Apps,

cot/src/static_files.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,16 @@ use crate::response::{Response, ResponseExt};
4646
/// // .
4747
/// // ├── Cargo.toml
4848
/// // └── static
49-
/// // └── admin
50-
/// // └── admin.css
49+
/// // └── test
50+
/// // └── test.txt
5151
///
5252
/// impl App for ExampleApp {
5353
/// fn name(&self) -> &str {
5454
/// "test_app"
5555
/// }
5656
///
5757
/// fn static_files(&self) -> Vec<StaticFile> {
58-
/// static_files!("admin/admin.css")
58+
/// static_files!("test/test.txt")
5959
/// }
6060
/// }
6161
/// ```
@@ -191,16 +191,16 @@ impl From<&MiddlewareContext> for StaticFiles {
191191
/// // .
192192
/// // ├── Cargo.toml
193193
/// // └── static
194-
/// // └── admin
195-
/// // └── admin.css
194+
/// // └── test
195+
/// // └── test.txt
196196
///
197197
/// impl App for ExampleApp {
198198
/// fn name(&self) -> &str {
199199
/// "test_app"
200200
/// }
201201
///
202202
/// fn static_files(&self) -> Vec<StaticFile> {
203-
/// static_files!("admin/admin.css")
203+
/// static_files!("test/test.txt")
204204
/// }
205205
/// }
206206
/// ```
@@ -531,7 +531,7 @@ mod tests {
531531
}
532532

533533
fn static_files(&self) -> Vec<StaticFile> {
534-
static_files!("admin/admin.css")
534+
static_files!("test/test.txt")
535535
}
536536
}
537537

@@ -563,11 +563,11 @@ mod tests {
563563
let middleware = StaticFilesMiddleware::from_context(bootstrapper.context());
564564
let static_files = middleware.static_files;
565565

566-
let file = static_files.get_file("admin/admin.css").unwrap();
567-
assert_eq!(file.mime_type, mime_guess::mime::TEXT_CSS);
566+
let file = static_files.get_file("test/test.txt").unwrap();
567+
assert_eq!(file.mime_type, mime_guess::mime::TEXT_PLAIN);
568568
assert_eq!(
569569
file.content,
570-
Bytes::from_static(include_bytes!("../static/admin/admin.css"))
570+
Bytes::from_static(include_bytes!("../static/test/test.txt"))
571571
);
572572

573573
let file = static_files.get_file("app2/test.js").unwrap();
@@ -617,19 +617,19 @@ mod tests {
617617

618618
#[test]
619619
fn static_files_macro() {
620-
let static_files = static_files!("admin/admin.css");
620+
let static_files = static_files!("test/test.txt");
621621

622622
assert_eq!(static_files.len(), 1);
623-
assert_eq!(static_files[0].path, "admin/admin.css");
623+
assert_eq!(static_files[0].path, "test/test.txt");
624624
assert_eq!(
625625
static_files[0].content,
626-
Bytes::from_static(include_bytes!("../static/admin/admin.css"))
626+
Bytes::from_static(include_bytes!("../static/test/test.txt"))
627627
);
628628
}
629629

630630
#[test]
631631
fn static_files_macro_trailing_comma() {
632-
let static_files = static_files!("admin/admin.css",);
632+
let static_files = static_files!("test/test.txt",);
633633

634634
assert_eq!(static_files.len(), 1);
635635
}

cot/static/test/test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This file is only used in tests.

cot/templates/error.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<title>Cot failure</title>
88

99
<style>
10-
{% include "css/error.css" %}
10+
{{ self::error_css()|safe }}
1111
</style>
1212
</head>
1313
<body>

0 commit comments

Comments
 (0)