Update ructe.

It now supports adding static sass files, so remove direct dependency
on rsass.
This commit is contained in:
Rasmus Kaj 2017-05-08 07:09:18 +02:00
parent fee9a801db
commit 5ea5a9bd90
3 changed files with 9 additions and 28 deletions

View File

@ -7,8 +7,7 @@ build = "src/build.rs"
[build-dependencies]
diesel_codegen_syntex = { version = "^0.9", features = ["postgres", "syntex"] }
ructe = "^0.2.4"
rsass = "*"
ructe = { version = "^0.3.0", features = ["sass"] }
[[bin]]
name = "rphotoserver"

View File

@ -1,22 +1,18 @@
extern crate diesel_codegen_syntex as diesel_codegen;
extern crate rsass;
extern crate ructe;
use rsass::{OutputStyle, compile_scss_file};
use ructe::{compile_static_files, compile_templates};
use ructe::{StaticFiles, compile_templates};
use std::env;
use std::fs::{File, create_dir_all};
use std::io::Write;
use std::path::{Path, PathBuf};
fn main() {
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
prepare_diesel(&out_dir);
let css_dir = out_dir.join("tmpcss");
do_sassify(&css_dir);
let template_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap())
.join("templates");
compile_static_files(&css_dir, &out_dir).expect("statics");
let base_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
let template_dir = base_dir.join("templates");
let mut statics = StaticFiles::new(&out_dir).unwrap();
statics.add_sass_file(&base_dir.join("photos.scss")).unwrap();
compile_templates(&template_dir, &out_dir).expect("templates");
}
@ -29,17 +25,3 @@ pub fn prepare_diesel(out_dir: &Path) {
println!("cargo:rerun-if-changed=src/models.rs");
println!("cargo:rerun-if-changed=src/lib.in.rs");
}
pub fn do_sassify(static_dir: &Path) {
create_dir_all(&static_dir).unwrap();
let css = compile_scss_file("photos.scss".as_ref(),
OutputStyle::Compressed).unwrap();
File::create(static_dir.join("style.css"))
.and_then(|mut f| f.write(&css))
.expect("Writing css");
// TODO Find any referenced files!
println!("cargo:rerun-if-changed=photos.scss");
}

View File

@ -1,6 +1,6 @@
@use ::Link;
@use templates::head;
@use templates::statics::style_css;
@use templates::statics::photos_css;
@(title: &str, lpath: &[Link], user: &Option<String>, content: Content)
@ -10,7 +10,7 @@
<title>@title</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="stylesheet" href="/static/@style_css.name" type="text/css"/>
<link rel="stylesheet" href="/static/@photos_css.name" type="text/css"/>
</head>
<body>
@:head(lpath, user)