1/* Part of ClioPatria SeRQL and SPARQL server 2 3 Author: Jan Wielemaker 4 E-mail: J.Wielemaker@cs.vu.nl 5 WWW: http://www.swi-prolog.org 6 Copyright (C): 2010, University of Amsterdam, 7 VU University Amsterdam 8 9 This program is free software; you can redistribute it and/or 10 modify it under the terms of the GNU General Public License 11 as published by the Free Software Foundation; either version 2 12 of the License, or (at your option) any later version. 13 14 This program is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public 20 License along with this library; if not, write to the Free Software 21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 23 As a special exception, if you link this library with other files, 24 compiled with a Free Software compiler, to produce an executable, this 25 library does not by itself cause the resulting executable to be covered 26 by the GNU General Public License. This exception does not however 27 invalidate any other reasons why the executable file might be covered by 28 the GNU General Public License. 29*/ 30 31:- module(cp_skin, 32 [ server_address//1, % +Component 33 current_page_doc_link//0 34 ]). 35:- use_module(library(http/html_write)). 36:- use_module(library(http/html_head)). 37:- use_module(library(http/http_wrapper)). 38:- use_module(library(http/http_dispatch)). 39:- use_module(library(http/http_path)). 40:- use_module(library(version)). 41:- use_module(components(menu)). 42:- use_module(components(simple_search)). 43:- use_module(applications(help/version)). 44 45/** <module> ClioPatria skin 46 47This page defines the overall layout of ClioPatria pages. All pages are 48returned using reply_html_page/3, using the page class cliopatria(Id), 49where Id is currently always =default=. Pages can be redefined by 50providing a rule for user:body//2, where the first argument must unify 51with the page class. 52 53The default skin provides the overall menu, a simple search form, the 54content and the `server-address'. Because the search-form uses the YUI 55autocomplete widgets, the body must include class =|yui-skin-sam|=. The 56default body has the classes =|yui-skin-sam|= and =cliopatria=. 57 58The default skin provided by this can be overruled using two hooks: 59 60 $ cliopatria:page_body//1 : 61 Emit a page from the given content. This hook can be used to modify 62 the overall page layout beyond what can be achieved with CSS. 63 $ cliopatria:server_address//0 : 64 Write the address of the server. 65 66This library also provides building blocks, notably for 67server_address//0: 68 69 $ server_address//1 : 70 Presents the version info and a link to a GIT module. 71 $ current_page_doc_link//0 : 72 Presents a link to the documentation of a page if the 73 self-documentation facilities are loaded. See run.pl.in. 74 75The CSS file css('cliopatria.css') contains the ClioPatria style that is 76makes ClioPatria look pretty to our eyes, but is not essential. The 77plugin config-available/fix_menu.pl contains example code to extend the 78ClioPatria skin. 79*/ 80 81:- http_handler('/favicon.ico', 82 http_reply_file(icons('favicon.ico'), []), 83 []). 84 85:- html_resource(js('cliopatria.js'), 86 [ requires([jquery]) 87 ]). 88:- html_resource(plain, 89 [ virtual(true), 90 requires([ css('plain.css') 91 ]) 92 ]). 93:- html_resource(cliopatria, 94 [ virtual(true), 95 requires([ css('cliopatria.css'), 96 js('cliopatria.js') 97 ]) 98 ]). 99 100%% user:body(+Style, :Body)// is det. 101% 102% The multi-file implementation defines the overall layout of HTML 103% pages with the Style cliopatria(_). 104 105:- multifile 106 user:body//2. 107 108userbody(cliopatria(Style), Body) --> 109 cliopatria:page_body(cliopatria(Style), Body), !. 110userbody(cliopatria(_), Body) --> 111 cliopatria:page_body(Body), !. 112userbody(cliopatria(plain), Body) --> 113 html_requires(plain), 114 html(body(class(['yui-skin-sam', cliopatria]), 115 [ div([id('cp-menu'), class(menu)], \cp_logo_and_menu), 116 \simple_search_form([value(p(q))]), 117 br(clear(all)), 118 div([id('cp-content'), class(content)], Body), 119 br(clear(all)), 120 div([id('cp-footer'), class(footer)], \address) 121 ])). 122userbody(cliopatria(_), Body) --> 123 html_requires(cliopatria), 124 html(body(class(['yui-skin-sam', cliopatria]), 125 [ div([id('cp-menu'), class(menu)], \cp_logo_and_menu), 126 \simple_search_form([value(p(q))]), 127 br(clear(all)), 128 div([id('cp-content'), class(content)], Body), 129 br(clear(all)), 130 div([id('cp-footer'), class(footer)], \address) 131 ])). 132 --> 134 cp_logo, 135 cp_menu. 136 137cp_logo --> 138 cliopatria:logo, !. 139cp_logo --> 140 { File = 'cliopatria-logo.png', 141 absolute_file_name(icons(File), _Logo, 142 [access(read), file_errors(fail)]), 143 http_absolute_location(icons(File), Src, []), 144 http_link_to_id(home, [], Home) 145 }, 146 html(a([class(logo), href(Home), style('float:left') 147 ], 148 img([src(Src)]))). 149 150%% address// 151% 152% Emit an element =address= with class =cliopatria=. This first 153% class the hook cliopatria:server_address//0. If this hooks 154% fails, it calls server_address('ClioPatria'). 155% 156% @see version.pl 157 158address --> 159 cliopatria:server_address, !. 160address --> 161 server_address('ClioPatria'). 162 163 164%% server_address(+Component)// 165% 166% HTML component that emits the default ClioPatria address link. 167% This provides a link to the ClioPatria home page and the (GIT) 168% version information. ClioPatria is registered with the GIT 169% module =|ClioPatria|= and the default server address is provided 170% by calling: 171% 172% == 173% ..., 174% server_address('ClioPatria'), 175% ... 176% == 177% 178% @see register_git_module/2 for registering a GIT module. 179 180server_address(Component) --> 181 html([ address(class(footer), 182 [ \component_address(Component), 183 \current_page_doc_link 184 ]) 185 ]). 186 187%% component_address(+Name)// 188% 189% The label ClioPatria as a link to its home-page on the web. 190 191component_address(Component) --> 192 ( { git_module_property(Component, home_url(Home)) } 193 -> html(a([ class(home), href(Home), 194 title(Component+' home') 195 ], Component)) 196 ; html(span(class(home), Component)) 197 ), 198 html(' (version '), 199 component_version(Component), 200 html(')'). 201 202 203%% component_version(+Name)// 204% 205% Give verion information and link to detailed version info 206 207component_version(Component) --> 208 { ( git_module_property(Component, version(Version)) 209 -> true 210 ; Version = 'no GIT?' 211 ), 212 http_link_to_id(version_info, [], VREF) 213 }, 214 html(a([title('About versions'), 215 class(version), 216 href(VREF)], 217 Version)). 218 219 220 221%% current_page_doc_link// 222% 223% Create a link to the documentation (and from there to the 224% implementation) of this page. This link is created only if the 225% library applications(help/http_help) is loaded. 226 227:- if(current_predicate(http_help:page_documentation_link//1)). 228current_page_doc_link --> 229 { http_current_request(Request) }, 230 http_help:page_documentation_link(Request). 231:- else. 232current_page_doc_link --> []. 233:- endif.