View source with raw comments or as raw
    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)).

ClioPatria skin

This page defines the overall layout of ClioPatria pages. All pages are returned using reply_html_page/3, using the page class cliopatria(Id), where Id is currently always default. Pages can be redefined by providing a rule for user:body//2, where the first argument must unify with the page class.

The default skin provides the overall menu, a simple search form, the content and the `server-address'. Because the search-form uses the YUI autocomplete widgets, the body must include class yui-skin-sam. The default body has the classes yui-skin-sam and cliopatria.

The default skin provided by this can be overruled using two hooks:

cliopatria:page_body//1
Emit a page from the given content. This hook can be used to modify the overall page layout beyond what can be achieved with CSS.
cliopatria:server_address//0
Write the address of the server.

This library also provides building blocks, notably for server_address//0:

server_address//1
Presents the version info and a link to a GIT module.
current_page_doc_link//0
Presents a link to the documentation of a page if the self-documentation facilities are loaded. See run.pl.in.

The CSS file css('cliopatria.css') contains the ClioPatria style that is makes ClioPatria look pretty to our eyes, but is not essential. The plugin config-available/fix_menu.pl contains example code to extend the ClioPatria skin. */

   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		 ]).
 user:body(+Style, :Body)// is det
The multi-file implementation defines the overall layout of HTML pages with the Style cliopatria(_).
  105:- multifile
  106	user:body//2.  107
  108user:body(cliopatria(Style), Body) -->
  109	cliopatria:page_body(cliopatria(Style), Body), !.
  110user:body(cliopatria(_), Body) -->
  111	cliopatria:page_body(Body), !.
  112user:body(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		  ])).
  122user:body(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
  133cp_logo_and_menu -->
  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)]))).
 address//
Emit an element address with class cliopatria. This first class the hook cliopatria:server_address//0. If this hooks fails, it calls server_address('ClioPatria').
See also
- version.pl
  158address -->
  159	cliopatria:server_address, !.
  160address -->
  161	server_address('ClioPatria').
 server_address(+Component)//
HTML component that emits the default ClioPatria address link. This provides a link to the ClioPatria home page and the (GIT) version information. ClioPatria is registered with the GIT module ClioPatria and the default server address is provided by calling:
    ...,
    server_address('ClioPatria'),
    ...
See also
- register_git_module/2 for registering a GIT module.
  180server_address(Component) -->
  181	html([ address(class(footer),
  182		       [ \component_address(Component),
  183			 \current_page_doc_link
  184		       ])
  185	     ]).
 component_address(+Name)//
The label ClioPatria as a link to its home-page on the web.
  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(')').
 component_version(+Name)//
Give verion information and link to detailed version info
  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)).
 current_page_doc_link//
Create a link to the documentation (and from there to the implementation) of this page. This link is created only if the library applications(help/http_help) is loaded.
  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.