Skip to content

Commit 6964fbf

Browse files
committed
Vendor FontAwesome and Pure-CSS
1 parent 508a9d0 commit 6964fbf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+7679
-19
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
target
55
*.css
66
*.css.map
7+
!vendor/*.css
78
.sass-cache
89
.vagrant
910
.rustwide

build.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ fn main() {
2222
println!("cargo:rerun-if-changed=templates/style/_navbar.scss");
2323
println!("cargo:rerun-if-changed=templates/menu.js");
2424
println!("cargo:rerun-if-changed=templates/index.js");
25+
println!("cargo:rerun-if-changed=vendor/");
2526
// TODO: are these right?
2627
println!("cargo:rerun-if-changed=.git/HEAD");
2728
println!("cargo:rerun-if-changed=.git/index");
@@ -63,7 +64,11 @@ fn compile_sass() -> Result<(), Box<dyn Error>> {
6364
let mut context = Context::new_file(format!("{}/base.scss", STYLE_DIR))?;
6465
context.set_options(Options {
6566
output_style: OutputStyle::Compressed,
66-
include_paths: vec![STYLE_DIR.to_owned()],
67+
include_paths: vec![
68+
STYLE_DIR.to_owned(),
69+
concat!(env!("CARGO_MANIFEST_DIR"), "/vendor/fontawesome/scss").to_owned(),
70+
concat!(env!("CARGO_MANIFEST_DIR"), "/vendor/pure-css").to_owned(),
71+
],
6772
..Default::default()
6873
});
6974

src/storage/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ impl Storage {
190190

191191
#[cfg(test)]
192192
pub(crate) fn store_blobs(&self, blobs: Vec<Blob>) -> Result<(), Error> {
193-
self.store_inner(blobs.into_iter().map(|blob| Ok(blob)))
193+
self.store_inner(blobs.into_iter().map(Ok))
194194
}
195195

196196
fn store_inner(
@@ -276,7 +276,7 @@ mod test {
276276
crate::test::init_logger();
277277
let files = get_file_list(env::current_dir().unwrap());
278278
assert!(files.is_ok());
279-
assert!(files.unwrap().len() > 0);
279+
assert!(!files.unwrap().is_empty());
280280

281281
let files = get_file_list(env::current_dir().unwrap().join("Cargo.toml")).unwrap();
282282
assert_eq!(files[0], std::path::Path::new("Cargo.toml"));
@@ -375,7 +375,7 @@ mod backend_tests {
375375
compression: None,
376376
};
377377

378-
storage.store_blobs(vec![small_blob.clone(), big_blob.clone()])?;
378+
storage.store_blobs(vec![small_blob.clone(), big_blob])?;
379379

380380
let blob = storage.get("small-blob.bin", MAX_SIZE)?;
381381
assert_eq!(blob.content.len(), small_blob.content.len());
@@ -480,7 +480,7 @@ mod backend_tests {
480480
mime: "text/rust".into(),
481481
content,
482482
path: format!("{}.rs", i),
483-
date_updated: now.clone(),
483+
date_updated: now,
484484
compression: None,
485485
}
486486
})

src/web/crate_details.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ mod tests {
663663
.create()?;
664664

665665
let details = CrateDetails::new(&mut db.conn(), "foo", "0.0.1").unwrap();
666-
let mut owners = details.owners.clone();
666+
let mut owners = details.owners;
667667
owners.sort();
668668
assert_eq!(
669669
owners,

src/web/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ mod routes;
8787
mod rustdoc;
8888
mod sitemap;
8989
mod source;
90+
mod statics;
9091

9192
use crate::{impl_webpage, Context};
9293
use chrono::{DateTime, Utc};

src/web/routes.rs

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub(super) fn build_routes() -> Routes {
1818
routes.static_resource("/robots.txt", super::sitemap::robots_txt_handler);
1919
routes.static_resource("/sitemap.xml", super::sitemap::sitemap_handler);
2020
routes.static_resource("/opensearch.xml", super::opensearch_xml_handler);
21+
routes.static_resource("/-/static/:file", super::statics::static_handler);
2122

2223
routes.internal_page("/", super::releases::home_page);
2324

src/web/statics.rs

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
use super::error::Nope;
2+
use iron::{
3+
headers::CacheDirective,
4+
headers::{CacheControl, ContentType},
5+
status::Status,
6+
IronError, IronResult, Request, Response,
7+
};
8+
use router::Router;
9+
10+
const EOT: &str = "application/vnd.ms-fontobject";
11+
const TTF: &str = "application/x-font-ttf";
12+
const WOFF2: &str = "application/font-woff2";
13+
const SVG: &str = "image/svg+xml";
14+
const WOFF: &str = "application/font-woff";
15+
16+
macro_rules! serve_static_files {
17+
($($file_name:literal => $content_type:expr),* $(,)?) => {
18+
// Generate the static file handler
19+
pub fn static_handler(req: &mut Request) -> IronResult<Response> {
20+
let router = extension!(req, Router);
21+
let file = cexpect!(req, router.find("file"));
22+
23+
// Select which file the user requested or return an error if it doesn't exist
24+
let (contents, content_type): (&'static [u8], ContentType) = match file {
25+
$(
26+
$file_name => (
27+
include_bytes!(concat!("../../vendor/fontawesome/webfonts/", $file_name)),
28+
ContentType($content_type.parse().unwrap()),
29+
),
30+
)*
31+
32+
_ => return Err(IronError::new(Nope::ResourceNotFound, Status::NotFound)),
33+
};
34+
35+
// Set the cache times
36+
let mut response = Response::with((Status::Ok, contents));
37+
let cache = vec![
38+
CacheDirective::Public,
39+
CacheDirective::MaxAge(super::STATIC_FILE_CACHE_DURATION as u32),
40+
];
41+
response.headers.set(content_type);
42+
response.headers.set(CacheControl(cache));
43+
44+
Ok(response)
45+
}
46+
47+
// Test each static route we serve
48+
#[test]
49+
fn serve_static_files() {
50+
$crate::test::wrapper(|env| {
51+
let web = env.frontend();
52+
53+
$(
54+
assert!(
55+
web.get(concat!("/-/static/", $file_name)).send()?.status().is_success(),
56+
concat!("failed while requesting a static file: '/-/static/", $file_name, "'"),
57+
);
58+
)*
59+
60+
Ok(())
61+
});
62+
}
63+
};
64+
}
65+
66+
// Serve all of our vendor font & svg files
67+
serve_static_files! {
68+
"fa-brands-400.eot" => EOT,
69+
"fa-brands-400.ttf" => TTF,
70+
"fa-brands-400.woff2" => WOFF2,
71+
"fa-regular-400.svg" => SVG,
72+
"fa-regular-400.woff" => WOFF,
73+
"fa-solid-900.eot" => EOT,
74+
"fa-solid-900.ttf" => TTF,
75+
"fa-solid-900.woff2" => WOFF2,
76+
"fa-brands-400.svg" => SVG,
77+
"fa-brands-400.woff" => WOFF,
78+
"fa-regular-400.eot" => EOT,
79+
"fa-regular-400.ttf" => TTF,
80+
"fa-regular-400.woff2" => WOFF2,
81+
"fa-solid-900.svg" => SVG,
82+
"fa-solid-900.woff" => WOFF,
83+
}
84+
85+
#[test]
86+
fn static_file_that_doesnt_exist() {
87+
crate::test::wrapper(|env| {
88+
let web = env.frontend();
89+
assert!(web
90+
.get("/-/static/whoop-de-do.png")
91+
.send()?
92+
.status()
93+
.is_client_error());
94+
95+
Ok(())
96+
});
97+
}

templates/base.html

-7
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,6 @@
99
<meta name="generator" content="docs.rs {{ docsrs_version() }}">
1010
{%- block meta -%}{%- endblock meta -%}
1111

12-
{# External styles #}
13-
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pure/0.6.0/pure-min.css" type="text/css"
14-
media="all" />
15-
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pure/0.6.0/grids-responsive-min.css"
16-
type="text/css" media="all" />
17-
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.14.0/css/all.css" />
18-
1912
{# Docs.rs styles #}
2013
<link rel="stylesheet" href="/normalize-{{ rustc_resource_suffix() }}.css" type="text/css" media="all" />
2114
<link rel="stylesheet" href="/rustdoc-{{ rustc_resource_suffix() }}.css" type="text/css" media="all" />

templates/rustdoc/head.html

-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
{%- import "macros.html" as macros -%}
2-
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pure/0.6.0/menus-min.css" type="text/css"
3-
media="all" />
4-
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pure/0.6.0/grids-min.css" type="text/css"
5-
media="all" />
6-
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.14.0/css/all.css" />
72
<link rel="stylesheet" href="/style.css?{{ docsrs_version() | slugify }}" type="text/css" media="all" />
83

94
<link rel="search" href="/opensearch.xml" type="application/opensearchdescription+xml" title="Docs.rs">

templates/style/base.scss

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// FIXME: Use modules
2-
@import "vars", "rustdoc", "utils", "navbar";
2+
@import "vars", "rustdoc", "utils", "navbar", "fontawesome", "regular", "solid", "brands", "pure-min",
3+
"grids-responsive-min";
34

45
html,
56
input,

vendor/fontawesome/LICENSE.txt

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Font Awesome Free License
2+
-------------------------
3+
4+
Font Awesome Free is free, open source, and GPL friendly. You can use it for
5+
commercial projects, open source projects, or really almost whatever you want.
6+
Full Font Awesome Free license: https://fontawesome.com/license/free.
7+
8+
# Icons: CC BY 4.0 License (https://creativecommons.org/licenses/by/4.0/)
9+
In the Font Awesome Free download, the CC BY 4.0 license applies to all icons
10+
packaged as SVG and JS file types.
11+
12+
# Fonts: SIL OFL 1.1 License (https://scripts.sil.org/OFL)
13+
In the Font Awesome Free download, the SIL OFL license applies to all icons
14+
packaged as web and desktop font files.
15+
16+
# Code: MIT License (https://opensource.org/licenses/MIT)
17+
In the Font Awesome Free download, the MIT license applies to all non-font and
18+
non-icon files.
19+
20+
# Attribution
21+
Attribution is required by MIT, SIL OFL, and CC BY licenses. Downloaded Font
22+
Awesome Free files already contain embedded comments with sufficient
23+
attribution, so you shouldn't need to do anything additional when using these
24+
files normally.
25+
26+
We've kept attribution comments terse, so we ask that you do not actively work
27+
to remove them from files, especially code. They're a great way for folks to
28+
learn about Font Awesome.
29+
30+
# Brand Icons
31+
All brand icons are trademarks of their respective owners. The use of these
32+
trademarks does not indicate endorsement of the trademark holder by Font
33+
Awesome, nor vice versa. **Please do not use brand logos for any purpose except
34+
to represent the company, product, or service to which they refer.**
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Animated Icons
2+
// --------------------------
3+
4+
.#{$fa-css-prefix}-spin {
5+
animation: fa-spin 2s infinite linear;
6+
}
7+
8+
.#{$fa-css-prefix}-pulse {
9+
animation: fa-spin 1s infinite steps(8);
10+
}
11+
12+
@keyframes fa-spin {
13+
0% {
14+
transform: rotate(0deg);
15+
}
16+
17+
100% {
18+
transform: rotate(360deg);
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Bordered & Pulled
2+
// -------------------------
3+
4+
.#{$fa-css-prefix}-border {
5+
border: solid .08em $fa-border-color;
6+
border-radius: .1em;
7+
padding: .2em .25em .15em;
8+
}
9+
10+
.#{$fa-css-prefix}-pull-left { float: left; }
11+
.#{$fa-css-prefix}-pull-right { float: right; }
12+
13+
.#{$fa-css-prefix},
14+
.fas,
15+
.far,
16+
.fal,
17+
.fab {
18+
&.#{$fa-css-prefix}-pull-left { margin-right: .3em; }
19+
&.#{$fa-css-prefix}-pull-right { margin-left: .3em; }
20+
}

vendor/fontawesome/scss/_core.scss

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Base Class Definition
2+
// -------------------------
3+
4+
.#{$fa-css-prefix},
5+
.fas,
6+
.far,
7+
.fal,
8+
.fad,
9+
.fab {
10+
-moz-osx-font-smoothing: grayscale;
11+
-webkit-font-smoothing: antialiased;
12+
display: inline-block;
13+
font-style: normal;
14+
font-variant: normal;
15+
text-rendering: auto;
16+
line-height: 1;
17+
}
18+
19+
%fa-icon {
20+
@include fa-icon;
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Fixed Width Icons
2+
// -------------------------
3+
.#{$fa-css-prefix}-fw {
4+
text-align: center;
5+
width: $fa-fw-width;
6+
}

0 commit comments

Comments
 (0)