Skip to content

Commit e7756a0

Browse files
committed
Merge branch 'tables'
2 parents 2a236b3 + e8fe646 commit e7756a0

File tree

5 files changed

+95
-5
lines changed

5 files changed

+95
-5
lines changed

Cargo.lock

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ tempdir = "0.3"
4141

4242
[build-dependencies]
4343
time = "0.1"
44+
sass-rs = "0.0.18"
4445

4546
[[bin]]
4647
name = "cratesfyi"

build.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,38 @@
11

22
extern crate time;
3+
extern crate sass_rs;
34

45
use std::env;
56
use std::path::Path;
67
use std::fs::File;
78
use std::io::Write;
89
use std::process::Command;
910

10-
1111
fn main() {
1212
let git_hash = match Command::new("git")
13-
.args(&["log", "--pretty=format:%h", "-n", "1"])
14-
.output() {
13+
.args(&["log", "--pretty=format:%h", "-n", "1"])
14+
.output() {
1515
Ok(output) => String::from_utf8_lossy(&output.stdout).into_owned(),
16-
Err(_) => "???????".to_string()
16+
Err(_) => "???????".to_string(),
1717
};
1818
let build_date = time::strftime("%Y-%m-%d", &time::now_utc()).unwrap();
1919
let dest_path = Path::new(&env::var("OUT_DIR").unwrap()).join("git_version");
2020
let mut file = File::create(&dest_path).unwrap();
2121
write!(file, "({} {})", git_hash, build_date).unwrap();
22+
23+
// compile style.scss
24+
compile_sass();
25+
}
26+
27+
28+
29+
fn compile_sass() {
30+
use sass_rs::sass_context::SassFileContext;
31+
32+
let mut file_context = SassFileContext::new(concat!(env!("CARGO_MANIFEST_DIR"),
33+
"/templates/style.scss"));
34+
let css = file_context.compile().unwrap();
35+
let dest_path = Path::new(&env::var("OUT_DIR").unwrap()).join("style.css");
36+
let mut file = File::create(&dest_path).unwrap();
37+
file.write_all(css.as_bytes()).unwrap();
2238
}

src/web/mod.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::error::Error;
1616
use std::time::Duration;
1717
use std::path::PathBuf;
1818
use iron::prelude::*;
19-
use iron::Handler;
19+
use iron::{Handler, status};
2020
use router::{Router, NoRoute};
2121
use staticfile::Static;
2222
use handlebars_iron::{HandlebarsEngine, DirectorySource};
@@ -30,6 +30,7 @@ use std::collections::BTreeMap;
3030

3131
/// Duration of static files for staticfile and DatabaseFileHandler (in seconds)
3232
const STATIC_FILE_CACHE_DURATION: u64 = 60 * 60 * 24 * 30 * 12; // 12 months
33+
const STYLE_CSS: &'static str = include_str!(concat!(env!("OUT_DIR"), "/style.css"));
3334

3435

3536
struct CratesfyiHandler {
@@ -59,6 +60,7 @@ impl CratesfyiHandler {
5960
pub fn new() -> CratesfyiHandler {
6061
let mut router = Router::new();
6162
router.get("/", releases::home_page);
63+
router.get("/style.css", style_css_handler);
6264
router.get("/about", |_: &mut Request| {
6365
page::Page::new(false).title("About Docs.rs").to_resp("about")
6466
});
@@ -268,6 +270,17 @@ fn duration_to_str(ts: time::Timespec) -> String {
268270

269271

270272

273+
fn style_css_handler(_: &mut Request) -> IronResult<Response> {
274+
use iron::headers::{CacheControl, CacheDirective, ContentType};
275+
let mut response = Response::with((status::Ok, STYLE_CSS));
276+
let cache = vec![CacheDirective::Public,
277+
CacheDirective::MaxAge(STATIC_FILE_CACHE_DURATION as u32)];
278+
response.headers.set(ContentType("text/css".parse().unwrap()));
279+
response.headers.set(CacheControl(cache));
280+
Ok(response)
281+
}
282+
283+
271284
/// MetaData used in header
272285
#[derive(Debug)]
273286
pub struct MetaData {

templates/style.scss

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,45 @@ div.package-page-container {
383383
h6:first-child {
384384
margin-top: 0;
385385
}
386+
387+
table {
388+
// most of this stuff is taken from pure tables.css
389+
border-collapse: collapse;
390+
border-spacing: 0;
391+
empty-cells: show;
392+
border: 1px solid #cbcbcb;
393+
margin-bottom: 15px;
394+
395+
td, th {
396+
border-left: 1px solid #cbcbcb;
397+
border-width: 0 0 0 1px;
398+
font-size: inherit;
399+
margin: 0;
400+
overflow: visible;
401+
padding: 0.5em 1em;
402+
}
403+
404+
th {
405+
font-family: $font-family-sans;
406+
font-weight: 500;
407+
}
408+
409+
td {
410+
border-bottom: 1px solid #cbcbcb;
411+
}
412+
413+
tbody > tr:last-child > td {
414+
border-bottom-width: 0;
415+
}
416+
417+
thead {
418+
background-color: #e0e0e0;
419+
color: #000;
420+
text-align: left;
421+
vertical-align: bottom;
422+
}
423+
424+
}
386425
}
387426

388427
pre {

0 commit comments

Comments
 (0)