Explicitly set theme for layout.

Refactoring in anticipation of letting the user choose theme
This commit is contained in:
Magnus Hovland Hoff 2018-09-18 23:11:25 +02:00
parent c1dcb1de64
commit 6118f14bb0
5 changed files with 10 additions and 3 deletions

View file

@ -11,6 +11,7 @@ use mimes::*;
use rendering::render_markdown; use rendering::render_markdown;
use site::Layout; use site::Layout;
use state::{State, UpdateResult, RebaseConflict}; use state::{State, UpdateResult, RebaseConflict};
use theme;
use web::{Resource, ResponseFuture}; use web::{Resource, ResponseFuture};
use super::changes_resource::QueryParameters; use super::changes_resource::QueryParameters;
@ -102,6 +103,7 @@ impl Resource for ArticleResource {
.with_body(Layout { .with_body(Layout {
base: None, // Hmm, should perhaps accept `base` as argument base: None, // Hmm, should perhaps accept `base` as argument
title: &data.title, title: &data.title,
theme: theme::theme_from_str(&data.title),
body: &Template { body: &Template {
revision: data.revision, revision: data.revision,
last_updated: Some(&last_updated( last_updated: Some(&last_updated(
@ -238,6 +240,7 @@ impl Resource for ArticleResource {
.with_body(Layout { .with_body(Layout {
base: None, base: None,
title: &title, title: &title,
theme: theme::theme_from_str(&title),
body: &Template { body: &Template {
revision: base_article.revision, revision: base_article.revision,
last_updated: Some(&last_updated( last_updated: Some(&last_updated(

View file

@ -12,6 +12,7 @@ use mimes::*;
use models::ArticleRevision; use models::ArticleRevision;
use site::Layout; use site::Layout;
use state::State; use state::State;
use theme;
use web::{Resource, ResponseFuture}; use web::{Resource, ResponseFuture};
use super::changes_resource; use super::changes_resource;
@ -122,6 +123,7 @@ impl Resource for DiffResource {
.with_body(Layout { .with_body(Layout {
base: Some("../"), // Hmm, should perhaps accept `base` as argument base: Some("../"), // Hmm, should perhaps accept `base` as argument
title: "Difference", title: "Difference",
theme: theme::theme_from_str("Difference"),
body: &Template { body: &Template {
consecutive: self.to.revision - self.from.revision == 1, consecutive: self.to.revision - self.from.revision == 1,
article_id: self.from.article_id as u32, article_id: self.from.article_id as u32,

View file

@ -10,6 +10,7 @@ use mimes::*;
use rendering::render_markdown; use rendering::render_markdown;
use site::Layout; use site::Layout;
use state::State; use state::State;
use theme;
use web::{Resource, ResponseFuture}; use web::{Resource, ResponseFuture};
const NEW: &str = "NEW"; const NEW: &str = "NEW";
@ -83,6 +84,7 @@ impl Resource for NewArticleResource {
.with_body(Layout { .with_body(Layout {
base: None, // Hmm, should perhaps accept `base` as argument base: None, // Hmm, should perhaps accept `base` as argument
title: &title, title: &title,
theme: theme::theme_from_str(&title),
body: &Template { body: &Template {
revision: NEW, revision: NEW,
last_updated: None, last_updated: None,

View file

@ -28,12 +28,11 @@ header! { (XIdentity, "X-Identity") => [String] }
pub struct Layout<'a, T: 'a + fmt::Display> { pub struct Layout<'a, T: 'a + fmt::Display> {
pub base: Option<&'a str>, pub base: Option<&'a str>,
pub title: &'a str, pub title: &'a str,
pub theme: theme::Theme,
pub body: T, pub body: T,
} }
impl<'a, T: 'a + fmt::Display> Layout<'a, T> { impl<'a, T: 'a + fmt::Display> Layout<'a, T> {
pub fn theme(&self) -> theme::Theme { theme::theme_from_str(self.title) }
pub fn themes_css(&self) -> &str { ThemesCss::resource_name() } pub fn themes_css(&self) -> &str { ThemesCss::resource_name() }
pub fn style_css(&self) -> &str { StyleCss::resource_name() } pub fn style_css(&self) -> &str { StyleCss::resource_name() }
pub fn search_js(&self) -> &str { SearchJs::resource_name() } pub fn search_js(&self) -> &str { SearchJs::resource_name() }
@ -57,6 +56,7 @@ where
Layout { Layout {
base, base,
title, title,
theme: theme::theme_from_str(title),
body: SystemPageLayout { body: SystemPageLayout {
title, title,
html_body: body, html_body: body,

View file

@ -9,7 +9,7 @@
<link href="_assets/{{style_css()}}" rel="stylesheet"> <link href="_assets/{{style_css()}}" rel="stylesheet">
<meta name="generator" content="{{project_name()}} {{version()}}" /> <meta name="generator" content="{{project_name()}} {{version()}}" />
</head> </head>
<body class="{{#theme().}}{{.css_class()}}{{/theme()}}"> <body class="{{theme.css_class()}}">
{{>search_input.html}} {{>search_input.html}}
{{{body}}} {{{body}}}
</body> </body>