Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
bwinf
medal
Commits
0e3980e8
Commit
0e3980e8
authored
Jun 12, 2019
by
Robert Czechowski
Browse files
Allow for different templates in subfolders
parent
026953f9
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main.rs
View file @
0e3980e8
...
...
@@ -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
());
...
...
src/webfw_iron.rs
View file @
0e3980e8
...
...
@@ -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 "./e
xa
mples/template
s
/**/*.hbs"
pub
fn
get_handlebars_engine
(
template_name
:
&
str
)
->
impl
AfterMiddleware
{
// HandlebarsEngine will look up all files with "./
t
empl
at
es/
<
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
());
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment