1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
// Copyright (C) 2015 Steven Allen // // This file is part of gazetta. // // This program is free software: you can redistribute it and/or modify it under the terms of the // GNU General Public License as published by the Free Software Foundation version 3 of the // License. // // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See // the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with this program. If // not, see <http://www.gnu.org/licenses/>. // use std::ops::Deref; use std::fmt; use ::render::Gazetta; /// A "website" /// /// You should include this view at the top of your websites "head". It renders /// into script, stylesheet, icon tags, metadata tags, and *importantly* the /// base tag. /// /// ```norun /// html! { /// html { /// head { /// : site; /// // ... /// } /// } /// } /// ``` pub struct Site<'a, G> where G: Gazetta + 'a, G::SiteMeta: 'a { /// The website's title pub title: &'a str, /// The "canonical" origin for the website. (i.e. the /// `<protocol>://<domain>:<port>` part of the url) pub origin: &'a str, /// The path prefix at wich we're serving this website. pub prefix: &'a str, /// The concatinated stylesheets. pub stylesheets: Option<&'a str>, /// The concatinated javascript. pub javascript: Option<&'a str>, /// The icon. pub icon: Option<&'a str>, /// Extra metadata specified in the Source. pub meta: &'a G::SiteMeta, } impl<'a, G> Deref for Site<'a, G> where G: Gazetta + 'a, G::SiteMeta: 'a { type Target = G::SiteMeta; fn deref(&self) -> &Self::Target { self.meta } } impl<'a, G> Copy for Site<'a, G> where G: Gazetta + 'a, G::PageMeta: 'a, G::SiteMeta: 'a { } impl<'a, G> Clone for Site<'a, G> where G: Gazetta + 'a, G::PageMeta: 'a, G::SiteMeta: 'a { fn clone(&self) -> Self { *self } } // Manually implement because rust isn't correctly adding the Debug constraint // when deriving. impl<'a, G> fmt::Debug for Site<'a, G> where G: Gazetta + 'a, G::PageMeta: 'a, G::SiteMeta: fmt::Debug + 'a { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("Page") .field("title", &self.title) .field("stylesheets", &self.stylesheets) .field("javascript", &self.javascript) .field("icon", &self.icon) .field("meta", &self.meta) .finish() } }