Commit 0e3980e8 authored by Robert Czechowski's avatar Robert Czechowski
Browse files

Allow for different templates in subfolders

parent 026953f9
......@@ -56,6 +56,7 @@ pub struct Config {
self_url: Option<String>,
oauth_providers: Option<Vec<oauth_provider::OauthProvider>>,
database_file: Option<PathBuf>,
template: Option<String>,
}
fn read_config_from_file(file: &Path) -> Config {
......@@ -88,6 +89,9 @@ fn read_config_from_file(file: &Path) -> Config {
if config.self_url.is_none() {
config.self_url = Some("http://localhost:8080".to_string())
}
if config.template.is_none() {
config.template = Some("default".to_string())
}
println!("OAuth providers will be told to redirect to {}", config.self_url.as_ref().unwrap());
......
......@@ -764,10 +764,10 @@ impl Key for SharedConfiguration {
}
#[cfg(feature = "watch")]
pub fn get_handlebars_engine() -> impl AfterMiddleware {
pub fn get_handlebars_engine(template_name: &str) -> impl AfterMiddleware {
// HandlebarsEngine will look up all files with "./examples/templates/**/*.hbs"
let mut hbse = HandlebarsEngine::new();
hbse.add(Box::new(DirectorySource::new("./templates/", ".hbs")));
hbse.add(Box::new(DirectorySource::new(&format!("./templates/{}/", template_name) as &str, ".hbs")));
// load templates from all registered sources
if let Err(r) = hbse.reload() {
......@@ -783,10 +783,10 @@ pub fn get_handlebars_engine() -> impl AfterMiddleware {
}
#[cfg(not(feature = "watch"))]
pub fn get_handlebars_engine() -> impl AfterMiddleware {
// HandlebarsEngine will look up all files with "./examples/templates/**/*.hbs"
pub fn get_handlebars_engine(template_name: &str) -> impl AfterMiddleware {
// HandlebarsEngine will look up all files with "./templates/<template>/**/*.hbs"
let mut hbse = HandlebarsEngine::new();
hbse.add(Box::new(DirectorySource::new("./templates/", ".hbs")));
hbse.add(Box::new(DirectorySource::new(&format!("./templates/{}/", template_name) as &str, ".hbs")));
// load templates from all registered sources
if let Err(r) = hbse.reload() {
......@@ -860,7 +860,7 @@ pub fn start_server(conn: Connection, config: ::Config) -> iron::error::HttpResu
ch.link_around(CookieDistributor::new());
ch.link_around(SessionStorage::new(SignedCookieBackend::new(my_secret)));
ch.link_after(get_handlebars_engine());
ch.link_after(get_handlebars_engine(&config.template.unwrap_or("default".to_string())));
ch.link_after(ErrorReporter);
let socket_addr = format!("{}:{}", config.host.unwrap(), config.port.unwrap());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment